1 /* Copyright 2003-2020 Joaquin M Lopez Munoz.
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)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_BASE_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_INDEX_BASE_HPP
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/core/addressof.hpp>
18 #include <boost/detail/no_exceptions_support.hpp>
19 #include <boost/detail/workaround.hpp>
20 #include <boost/move/core.hpp>
21 #include <boost/move/utility_core.hpp>
22 #include <boost/mpl/vector.hpp>
23 #include <boost/multi_index/detail/allocator_traits.hpp>
24 #include <boost/multi_index/detail/copy_map.hpp>
25 #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
26 #include <boost/multi_index/detail/node_type.hpp>
27 #include <boost/multi_index/detail/vartempl_support.hpp>
28 #include <boost/multi_index_container_fwd.hpp>
29 #include <boost/tuple/tuple.hpp>
32 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
33 #include <boost/multi_index/detail/index_loader.hpp>
34 #include <boost/multi_index/detail/index_saver.hpp>
39 namespace multi_index{
43 /* The role of this class is threefold:
44 * - tops the linear hierarchy of indices.
45 * - terminates some cascading backbone function calls (insert_, etc.),
46 * - grants access to the backbone functions of the final
47 * multi_index_container class (for access restriction reasons, these
48 * cannot be called directly from the index classes.)
53 struct emplaced_tag{};
55 template<typename Value,typename IndexSpecifierList,typename Allocator>
59 typedef index_node_base<Value,Allocator> node_type;
60 typedef typename multi_index_node_type<
61 Value,IndexSpecifierList,Allocator>::type final_node_type;
62 typedef multi_index_container<
63 Value,IndexSpecifierList,Allocator> final_type;
64 typedef tuples::null_type ctor_args_list;
65 typedef typename rebind_alloc_for<
66 Allocator,typename Allocator::value_type
67 >::type final_allocator_type;
68 typedef mpl::vector0<> index_type_list;
69 typedef mpl::vector0<> iterator_type_list;
70 typedef mpl::vector0<> const_iterator_type_list;
73 final_allocator_type> copy_map_type;
75 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
78 final_allocator_type> index_saver_type;
82 final_allocator_type> index_loader_type;
86 typedef Value value_type;
87 typedef allocator_traits<Allocator> alloc_traits;
88 typedef typename alloc_traits::size_type size_type;
91 explicit index_base(const ctor_args_list&,const Allocator&){}
94 const index_base<Value,IndexSpecifierList,Allocator>&,
95 do_not_copy_elements_tag)
99 const index_base<Value,IndexSpecifierList,Allocator>&,const copy_map_type&)
102 final_node_type* insert_(const value_type& v,final_node_type*& x,lvalue_tag)
104 x=final().allocate_node();
106 final().construct_value(x,v);
109 final().deallocate_node(x);
116 final_node_type* insert_(const value_type& v,final_node_type*& x,rvalue_tag)
118 x=final().allocate_node();
120 final().construct_value(x,boost::move(const_cast<value_type&>(v)));
123 final().deallocate_node(x);
130 final_node_type* insert_(const value_type&,final_node_type*& x,emplaced_tag)
135 final_node_type* insert_(
136 const value_type& v,node_type*,final_node_type*& x,lvalue_tag)
138 return insert_(v,x,lvalue_tag());
141 final_node_type* insert_(
142 const value_type& v,node_type*,final_node_type*& x,rvalue_tag)
144 return insert_(v,x,rvalue_tag());
147 final_node_type* insert_(
148 const value_type&,node_type*,final_node_type*& x,emplaced_tag)
153 void erase_(node_type* x)
155 final().destroy_value(static_cast<final_node_type*>(x));
158 void delete_node_(node_type* x)
160 final().destroy_value(static_cast<final_node_type*>(x));
165 template<typename BoolConstant>
167 index_base<Value,IndexSpecifierList,Allocator>&,
168 BoolConstant /* swap_allocators */)
171 void swap_elements_(index_base<Value,IndexSpecifierList,Allocator>&){}
173 bool replace_(const value_type& v,node_type* x,lvalue_tag)
179 bool replace_(const value_type& v,node_type* x,rvalue_tag)
181 x->value()=boost::move(const_cast<value_type&>(v));
185 bool modify_(node_type*){return true;}
187 bool modify_rollback_(node_type*){return true;}
189 bool check_rollback_(node_type*)const{return true;}
191 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
194 template<typename Archive>
195 void save_(Archive&,const unsigned int,const index_saver_type&)const{}
197 template<typename Archive>
198 void load_(Archive&,const unsigned int,const index_loader_type&){}
201 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
202 /* invariant stuff */
204 bool invariant_()const{return true;}
207 /* access to backbone memfuns of Final class */
209 final_type& final(){return *static_cast<final_type*>(this);}
210 const final_type& final()const{return *static_cast<const final_type*>(this);}
212 final_node_type* final_header()const{return final().header();}
214 bool final_empty_()const{return final().empty_();}
215 size_type final_size_()const{return final().size_();}
216 size_type final_max_size_()const{return final().max_size_();}
218 std::pair<final_node_type*,bool> final_insert_(const value_type& x)
219 {return final().insert_(x);}
220 std::pair<final_node_type*,bool> final_insert_rv_(const value_type& x)
221 {return final().insert_rv_(x);}
223 std::pair<final_node_type*,bool> final_insert_ref_(const T& t)
224 {return final().insert_ref_(t);}
226 std::pair<final_node_type*,bool> final_insert_ref_(T& t)
227 {return final().insert_ref_(t);}
229 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
230 std::pair<final_node_type*,bool> final_emplace_(
231 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
233 return final().emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
236 std::pair<final_node_type*,bool> final_insert_(
237 const value_type& x,final_node_type* position)
238 {return final().insert_(x,position);}
239 std::pair<final_node_type*,bool> final_insert_rv_(
240 const value_type& x,final_node_type* position)
241 {return final().insert_rv_(x,position);}
243 std::pair<final_node_type*,bool> final_insert_ref_(
244 const T& t,final_node_type* position)
245 {return final().insert_ref_(t,position);}
247 std::pair<final_node_type*,bool> final_insert_ref_(
248 T& t,final_node_type* position)
249 {return final().insert_ref_(t,position);}
251 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
252 std::pair<final_node_type*,bool> final_emplace_hint_(
253 final_node_type* position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
255 return final().emplace_hint_(
256 position,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
259 void final_erase_(final_node_type* x){final().erase_(x);}
261 void final_delete_node_(final_node_type* x){final().delete_node_(x);}
262 void final_delete_all_nodes_(){final().delete_all_nodes_();}
263 void final_clear_(){final().clear_();}
265 void final_swap_(final_type& x){final().swap_(x);}
268 const value_type& k,final_node_type* x)
269 {return final().replace_(k,x);}
270 bool final_replace_rv_(
271 const value_type& k,final_node_type* x)
272 {return final().replace_rv_(k,x);}
274 template<typename Modifier>
275 bool final_modify_(Modifier& mod,final_node_type* x)
276 {return final().modify_(mod,x);}
278 template<typename Modifier,typename Rollback>
279 bool final_modify_(Modifier& mod,Rollback& back,final_node_type* x)
280 {return final().modify_(mod,back,x);}
282 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
283 void final_check_invariant_()const{final().check_invariant_();}
287 } /* namespace multi_index::detail */
289 } /* namespace multi_index */
291 } /* namespace boost */