1 // Boost.Assign library 2 // 3 // Copyright Thorsten Ottosen 2003-2005. Use, modification and 4 // distribution is subject to the Boost Software License, Version 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // For more information, see http://www.boost.org/libs/assign/ 9 // 10 11 #ifndef BOOST_ASSIGN_PTR_LIST_INSERTER_HPP 12 #define BOOST_ASSIGN_PTR_LIST_INSERTER_HPP 13 14 #if defined(_MSC_VER) 15 # pragma once 16 #endif 17 18 #include <boost/assign/list_inserter.hpp> 19 #include <boost/type_traits/remove_reference.hpp> 20 #include <boost/type_traits/remove_pointer.hpp> 21 22 namespace boost 23 { 24 25 namespace assign 26 { 27 template< class Function, class Obj > 28 class ptr_list_inserter 29 { 30 typedef BOOST_DEDUCED_TYPENAME 31 remove_pointer< BOOST_DEDUCED_TYPENAME 32 remove_reference<Obj>::type >::type 33 obj_type; 34 public: 35 ptr_list_inserter(Function fun)36 ptr_list_inserter( Function fun ) : insert_( fun ) 37 {} 38 39 template< class Function2, class Obj2 > ptr_list_inserter(const ptr_list_inserter<Function2,Obj2> & r)40 ptr_list_inserter( const ptr_list_inserter<Function2,Obj2>& r ) 41 : insert_( r.fun_private() ) 42 {} 43 ptr_list_inserter(const ptr_list_inserter & r)44 ptr_list_inserter( const ptr_list_inserter& r ) : insert_( r.insert_ ) 45 {} 46 operator ()()47 ptr_list_inserter& operator()() 48 { 49 insert_( new obj_type() ); 50 return *this; 51 } 52 53 template< class T > operator ()(const T & t)54 ptr_list_inserter& operator()( const T& t ) 55 { 56 insert_( new obj_type(t) ); 57 return *this; 58 } 59 60 #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value 61 #define BOOST_ASSIGN_MAX_PARAMS 5 62 #endif 63 #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) 64 #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T) 65 #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t) 66 #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t) 67 68 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 69 #define BOOST_PP_LOCAL_MACRO(n) \ 70 template< class T, BOOST_ASSIGN_PARAMS1(n) > \ 71 ptr_list_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \ 72 { \ 73 insert_( new obj_type(t, BOOST_ASSIGN_PARAMS3(n) )); \ 74 return *this; \ 75 } \ 76 /**/ 77 78 #include BOOST_PP_LOCAL_ITERATE() 79 80 private: 81 82 ptr_list_inserter& operator=( const ptr_list_inserter& ); 83 Function insert_; 84 }; 85 86 template< class Obj, class Function > 87 inline ptr_list_inserter< Function, Obj > make_ptr_list_inserter(Function fun)88 make_ptr_list_inserter( Function fun ) 89 { 90 return ptr_list_inserter< Function, Obj >( fun ); 91 } 92 93 template< class C > 94 inline ptr_list_inserter< assign_detail::call_push_back<C>, 95 BOOST_DEDUCED_TYPENAME C::reference > ptr_push_back(C & c)96 ptr_push_back( C& c ) 97 { 98 return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference> 99 ( assign_detail::call_push_back<C>( c ) ); 100 } 101 102 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 103 104 template< class T, class C > 105 inline ptr_list_inserter< assign_detail::call_push_back<C>, T > ptr_push_back(C & c)106 ptr_push_back( C& c ) 107 { 108 return make_ptr_list_inserter<T>( 109 assign_detail::call_push_back<C>( c ) ); 110 } 111 112 #endif 113 114 template< class C > 115 inline ptr_list_inserter< assign_detail::call_push_front<C>, 116 BOOST_DEDUCED_TYPENAME C::reference > ptr_push_front(C & c)117 ptr_push_front( C& c ) 118 { 119 return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference> 120 ( assign_detail::call_push_front<C>( c ) ); 121 } 122 123 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 124 125 template< class T, class C > 126 inline ptr_list_inserter< assign_detail::call_push_front<C>, T > ptr_push_front(C & c)127 ptr_push_front( C& c ) 128 { 129 return make_ptr_list_inserter<T>( 130 assign_detail::call_push_front<C>( c ) ); 131 } 132 133 #endif 134 135 template< class C > 136 inline ptr_list_inserter< assign_detail::call_insert<C>, 137 BOOST_DEDUCED_TYPENAME C::reference> ptr_insert(C & c)138 ptr_insert( C& c ) 139 { 140 return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference> 141 ( assign_detail::call_insert<C>( c ) ); 142 } 143 144 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 145 146 template< class T, class C > 147 inline ptr_list_inserter< assign_detail::call_insert<C>, T > ptr_insert(C & c)148 ptr_insert( C& c ) 149 { 150 return make_ptr_list_inserter<T>( assign_detail::call_insert<C>( c ) ); 151 } 152 153 #endif 154 155 156 } // namespace 'assign' 157 } // namespace 'boost' 158 159 #undef BOOST_ASSIGN_PARAMS1 160 #undef BOOST_ASSIGN_PARAMS2 161 #undef BOOST_ASSIGN_PARAMS3 162 #undef BOOST_ASSIGN_MAX_PARAMETERS 163 164 #endif 165