source: NonGTP/Boost/boost/assign/ptr_list_inserter.hpp @ 857

Revision 857, 3.9 KB checked in by igarcia, 18 years ago (diff)
Line 
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) && (_MSC_VER >= 1020)
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
22namespace boost
23{
24
25namespace 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       
36        ptr_list_inserter( Function fun ) : insert_( fun )
37        {}
38       
39        template< class Function2, class Obj2 >
40        ptr_list_inserter( const ptr_list_inserter<Function2,Obj2>& r )
41        : insert_( r.fun_private() )
42        {}
43
44        ptr_list_inserter( const ptr_list_inserter& r ) : insert_( r.insert_ )
45        {}
46
47        ptr_list_inserter& operator()()
48        {
49            insert_( new obj_type() );
50            return *this;
51        }
52       
53        template< class 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 >
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 >
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    template< class C >
103    inline ptr_list_inserter< assign_detail::call_push_front<C>,
104                              BOOST_DEDUCED_TYPENAME C::reference >
105    ptr_push_front( C& c )
106    {
107        return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
108                 ( assign_detail::call_push_front<C>( c ) );
109    }
110
111    template< class C >
112    inline ptr_list_inserter< assign_detail::call_insert<C>,
113                          BOOST_DEDUCED_TYPENAME C::reference>
114    ptr_insert( C& c )
115    {
116        return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
117                    ( assign_detail::call_insert<C>( c ) );
118    }
119   
120} // namespace 'assign'
121} // namespace 'boost'
122
123#undef BOOST_ASSIGN_PARAMS1
124#undef BOOST_ASSIGN_PARAMS2
125#undef BOOST_ASSIGN_PARAMS3
126#undef BOOST_ASSIGN_MAX_PARAMETERS
127
128#endif
Note: See TracBrowser for help on using the repository browser.