//! @copyright *this file is freware. //! @warning Use it at your own risk. //! @file assign.hpp //! @author Dejan D. M. Milosavljevic //! @version 1.0 //! @date 2003 //! @please "Do not remove or change this comments" //! @description assign classes. //! @bug if( NULL == P_left ) Ir_item = new N_left( P_right ) //! @warning Use it at your own risk. //! @copyright *this file is freware. #ifndef DDMRM_assign_classes_HPP_ #define DDMRM_assign_classes_HPP_ #include namespace stl_ext { template< typename N_left, typename N_right = N_left > class assign_to_ref : public std::binary_function< N_left &, N_right const&, N_left & > { public: assign_to_ref(){} typedef N_left & first_argument_type; typedef N_right const& second_argument_type; typedef N_left & result_type; result_type operator()( first_argument_type P_left, second_argument_type P_right ) { return P_left = P_right; } }; template< typename N_left, typename N_right = N_left , typename N_assign = assign_to_ref > class assign_to_ptr : public std::binary_function< N_left *, N_right const&, N_left * > { public: assign_to_ptr(){} typedef N_left * first_argument_type; typedef N_right const& second_argument_type; typedef N_left * result_type; result_type operator()( first_argument_type P_left, second_argument_type P_right ) { N_left *Ir_item = NULL; if( NULL == P_left ) { Ir_item = new N_left( ); // or { Ir_item = new N_left( P_right ); return Ir_item; } } else { Ir_item = P_left; } N_assign()( *Ir_item, P_right ); // red point return Ir_item; } }; template< typename N_left, typename N_right = N_left , typename N_assign = assign_to_ref > class assign_ptr_to_ptr: public std::binary_function< N_left *, N_right const*, N_left * > { public: assign_ptr_to_ptr(){} typedef N_left * first_argument_type; typedef N_right const* second_argument_type; typedef N_left * result_type; result_type operator()( first_argument_type P_left, second_argument_type P_right ) { N_left *Ir_item = NULL; if( NULL == P_left ) { Ir_item = new N_left( ); // or { Ir_item = new N_left( P_right ); return Ir_item; } } else { Ir_item = P_left; } N_assign()( *Ir_item , *P_right ); // red point return Ir_item; } }; } #endif