1 | /* Copyright 2003-2005 Joaquín M López Muñoz.
|
---|
2 | * Distributed under the Boost Software License, Version 1.0.
|
---|
3 | * (See accompanying file LICENSE_1_0.txt or copy at
|
---|
4 | * http://www.boost.org/LICENSE_1_0.txt)
|
---|
5 | *
|
---|
6 | * See http://www.boost.org/libs/multi_index for library home page.
|
---|
7 | */
|
---|
8 |
|
---|
9 | #ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_BASE_HPP
|
---|
10 | #define BOOST_MULTI_INDEX_DETAIL_INDEX_BASE_HPP
|
---|
11 |
|
---|
12 | #if defined(_MSC_VER)&&(_MSC_VER>=1200)
|
---|
13 | #pragma once
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
|
---|
17 | #include <boost/call_traits.hpp>
|
---|
18 | #include <boost/detail/workaround.hpp>
|
---|
19 | #include <boost/mpl/vector.hpp>
|
---|
20 | #include <boost/multi_index/detail/copy_map.hpp>
|
---|
21 | #include <boost/multi_index/detail/node_type.hpp>
|
---|
22 | #include <boost/multi_index_container_fwd.hpp>
|
---|
23 | #include <boost/tuple/tuple.hpp>
|
---|
24 | #include <utility>
|
---|
25 |
|
---|
26 | #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
|
---|
27 | #include <boost/multi_index/detail/index_loader.hpp>
|
---|
28 | #include <boost/multi_index/detail/index_saver.hpp>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | namespace boost{
|
---|
32 |
|
---|
33 | namespace multi_index{
|
---|
34 |
|
---|
35 | namespace detail{
|
---|
36 |
|
---|
37 | /* The role of this class is threefold:
|
---|
38 | * - tops the linear hierarchy of indices.
|
---|
39 | * - terminates some cascading backbone function calls (insert_, etc.),
|
---|
40 | * - grants access to the backbone functions of the final
|
---|
41 | * multi_index_container class (for access restriction reasons, these
|
---|
42 | * cannot be called directly from the index classes.)
|
---|
43 | */
|
---|
44 |
|
---|
45 | template<typename Value,typename IndexSpecifierList,typename Allocator>
|
---|
46 | class index_base
|
---|
47 | {
|
---|
48 | protected:
|
---|
49 | typedef index_node_base<Value> node_type;
|
---|
50 | typedef typename multi_index_node_type<
|
---|
51 | Value,IndexSpecifierList,Allocator>::type final_node_type;
|
---|
52 | typedef multi_index_container<
|
---|
53 | Value,IndexSpecifierList,Allocator> final_type;
|
---|
54 | typedef tuples::null_type ctor_args_list;
|
---|
55 | typedef typename
|
---|
56 | boost::detail::allocator::rebind_to<
|
---|
57 | Allocator,
|
---|
58 | typename Allocator::value_type>::type final_allocator_type;
|
---|
59 | typedef mpl::vector0<> index_type_list;
|
---|
60 | typedef mpl::vector0<> iterator_type_list;
|
---|
61 | typedef mpl::vector0<> const_iterator_type_list;
|
---|
62 | typedef copy_map<
|
---|
63 | final_node_type,
|
---|
64 | final_allocator_type> copy_map_type;
|
---|
65 |
|
---|
66 | #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
|
---|
67 | typedef index_saver<
|
---|
68 | node_type,
|
---|
69 | final_allocator_type> index_saver_type;
|
---|
70 | typedef index_loader<
|
---|
71 | node_type,
|
---|
72 | final_node_type,
|
---|
73 | final_allocator_type> index_loader_type;
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | private:
|
---|
77 | typedef typename call_traits<Value>::param_type value_param_type;
|
---|
78 |
|
---|
79 | protected:
|
---|
80 | explicit index_base(const ctor_args_list&,const Allocator&){}
|
---|
81 |
|
---|
82 | void copy_(
|
---|
83 | const index_base<Value,IndexSpecifierList,Allocator>&,const copy_map_type&)
|
---|
84 | {}
|
---|
85 |
|
---|
86 | node_type* insert_(value_param_type v,node_type* x)
|
---|
87 | {
|
---|
88 | boost::detail::allocator::construct(&x->value,v);
|
---|
89 | return x;
|
---|
90 | }
|
---|
91 |
|
---|
92 | node_type* insert_(value_param_type v,node_type*,node_type* x)
|
---|
93 | {
|
---|
94 | boost::detail::allocator::construct(&x->value,v);
|
---|
95 | return x;
|
---|
96 | }
|
---|
97 |
|
---|
98 | void erase_(node_type* x)
|
---|
99 | {
|
---|
100 | boost::detail::allocator::destroy(&x->value);
|
---|
101 | }
|
---|
102 |
|
---|
103 | void delete_node_(node_type* x)
|
---|
104 | {
|
---|
105 | boost::detail::allocator::destroy(&x->value);
|
---|
106 | }
|
---|
107 |
|
---|
108 | void clear_(){}
|
---|
109 |
|
---|
110 | void swap_(index_base<Value,IndexSpecifierList,Allocator>&){}
|
---|
111 |
|
---|
112 | bool replace_(value_param_type v,node_type* x)
|
---|
113 | {
|
---|
114 | x->value=v;
|
---|
115 | return true;
|
---|
116 | }
|
---|
117 |
|
---|
118 | bool modify_(node_type*){return true;}
|
---|
119 |
|
---|
120 | #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
|
---|
121 | /* serialization */
|
---|
122 |
|
---|
123 | template<typename Archive>
|
---|
124 | void save_(Archive&,const unsigned int,const index_saver_type&)const{}
|
---|
125 |
|
---|
126 | template<typename Archive>
|
---|
127 | void load_(Archive&,const unsigned int,const index_loader_type&){}
|
---|
128 | #endif
|
---|
129 |
|
---|
130 | #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
|
---|
131 | /* invariant stuff */
|
---|
132 |
|
---|
133 | bool invariant_()const{return true;}
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | /* access to backbone memfuns of Final class */
|
---|
137 |
|
---|
138 | final_type& final(){return *static_cast<final_type*>(this);}
|
---|
139 | const final_type& final()const{return *static_cast<const final_type*>(this);}
|
---|
140 |
|
---|
141 | final_node_type* final_header()const{return final().header();}
|
---|
142 |
|
---|
143 | bool final_empty_()const{return final().empty_();}
|
---|
144 | std::size_t final_size_()const{return final().size_();}
|
---|
145 | std::size_t final_max_size_()const{return final().max_size_();}
|
---|
146 |
|
---|
147 | std::pair<final_node_type*,bool> final_insert_(value_param_type x)
|
---|
148 | {return final().insert_(x);}
|
---|
149 | std::pair<final_node_type*,bool> final_insert_(
|
---|
150 | value_param_type x,final_node_type* position)
|
---|
151 | {return final().insert_(x,position);}
|
---|
152 |
|
---|
153 | void final_erase_(final_node_type* x){final().erase_(x);}
|
---|
154 |
|
---|
155 | void final_delete_node_(final_node_type* x){final().delete_node_(x);}
|
---|
156 | void final_delete_all_nodes_(){final().delete_all_nodes_();}
|
---|
157 | void final_clear_(){final().clear_();}
|
---|
158 |
|
---|
159 | void final_swap_(final_type& x){final().swap_(x);}
|
---|
160 | bool final_replace_(
|
---|
161 | value_param_type k,final_node_type* x)
|
---|
162 | {return final().replace_(k,x);}
|
---|
163 |
|
---|
164 | template<typename Modifier>
|
---|
165 | bool final_modify_(Modifier mod,final_node_type* x)
|
---|
166 | {return final().modify_(mod,x);}
|
---|
167 |
|
---|
168 | #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
|
---|
169 | void final_check_invariant_()const{final().check_invariant_();}
|
---|
170 | #endif
|
---|
171 | };
|
---|
172 |
|
---|
173 | } /* namespace multi_index::detail */
|
---|
174 |
|
---|
175 | } /* namespace multi_index */
|
---|
176 |
|
---|
177 | } /* namespace boost */
|
---|
178 |
|
---|
179 | #endif
|
---|