ptr_list_inserter.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #ifndef BOOST_ASSIGN_PTR_LIST_INSERTER_HPP
  11. #define BOOST_ASSIGN_PTR_LIST_INSERTER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  13. # pragma once
  14. #endif
  15. #include <boost/assign/list_inserter.hpp>
  16. #include <boost/type_traits/remove_reference.hpp>
  17. #include <boost/type_traits/remove_pointer.hpp>
  18. namespace boost
  19. {
  20. namespace assign
  21. {
  22. template< class Function, class Obj >
  23. class ptr_list_inserter
  24. {
  25. typedef BOOST_DEDUCED_TYPENAME
  26. remove_pointer< BOOST_DEDUCED_TYPENAME
  27. remove_reference<Obj>::type >::type
  28. obj_type;
  29. public:
  30. ptr_list_inserter( Function fun ) : insert_( fun )
  31. {}
  32. template< class Function2, class Obj2 >
  33. ptr_list_inserter( const ptr_list_inserter<Function2,Obj2>& r )
  34. : insert_( r.fun_private() )
  35. {}
  36. ptr_list_inserter( const ptr_list_inserter& r ) : insert_( r.insert_ )
  37. {}
  38. ptr_list_inserter& operator()()
  39. {
  40. insert_( new obj_type() );
  41. return *this;
  42. }
  43. template< class T >
  44. ptr_list_inserter& operator()( const T& t )
  45. {
  46. insert_( new obj_type(t) );
  47. return *this;
  48. }
  49. #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
  50. #define BOOST_ASSIGN_MAX_PARAMS 5
  51. #endif
  52. #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
  53. #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
  54. #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
  55. #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
  56. #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
  57. #define BOOST_PP_LOCAL_MACRO(n) \
  58. template< class T, BOOST_ASSIGN_PARAMS1(n) > \
  59. ptr_list_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \
  60. { \
  61. insert_( new obj_type(t, BOOST_ASSIGN_PARAMS3(n) )); \
  62. return *this; \
  63. } \
  64. /**/
  65. #include BOOST_PP_LOCAL_ITERATE()
  66. private:
  67. ptr_list_inserter& operator=( const ptr_list_inserter& );
  68. Function insert_;
  69. };
  70. template< class Obj, class Function >
  71. inline ptr_list_inserter< Function, Obj >
  72. make_ptr_list_inserter( Function fun )
  73. {
  74. return ptr_list_inserter< Function, Obj >( fun );
  75. }
  76. template< class C >
  77. inline ptr_list_inserter< assign_detail::call_push_back<C>,
  78. BOOST_DEDUCED_TYPENAME C::reference >
  79. ptr_push_back( C& c )
  80. {
  81. return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
  82. ( assign_detail::call_push_back<C>( c ) );
  83. }
  84. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  85. template< class T, class C >
  86. inline ptr_list_inserter< assign_detail::call_push_back<C>, T >
  87. ptr_push_back( C& c )
  88. {
  89. return make_ptr_list_inserter<T>(
  90. assign_detail::call_push_back<C>( c ) );
  91. }
  92. #endif
  93. template< class C >
  94. inline ptr_list_inserter< assign_detail::call_push_front<C>,
  95. BOOST_DEDUCED_TYPENAME C::reference >
  96. ptr_push_front( C& c )
  97. {
  98. return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
  99. ( assign_detail::call_push_front<C>( c ) );
  100. }
  101. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  102. template< class T, class C >
  103. inline ptr_list_inserter< assign_detail::call_push_front<C>, T >
  104. ptr_push_front( C& c )
  105. {
  106. return make_ptr_list_inserter<T>(
  107. assign_detail::call_push_front<C>( c ) );
  108. }
  109. #endif
  110. template< class C >
  111. inline ptr_list_inserter< assign_detail::call_insert<C>,
  112. BOOST_DEDUCED_TYPENAME C::reference>
  113. ptr_insert( C& c )
  114. {
  115. return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
  116. ( assign_detail::call_insert<C>( c ) );
  117. }
  118. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  119. template< class T, class C >
  120. inline ptr_list_inserter< assign_detail::call_insert<C>, T >
  121. ptr_insert( C& c )
  122. {
  123. return make_ptr_list_inserter<T>( assign_detail::call_insert<C>( c ) );
  124. }
  125. #endif
  126. } // namespace 'assign'
  127. } // namespace 'boost'
  128. #undef BOOST_ASSIGN_PARAMS1
  129. #undef BOOST_ASSIGN_PARAMS2
  130. #undef BOOST_ASSIGN_PARAMS3
  131. #undef BOOST_ASSIGN_MAX_PARAMETERS
  132. #endif