1 /* Copyright 2003-2021 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/core/no_exceptions_support.hpp>
19 #include <boost/detail/workaround.hpp>
20 #include <boost/move/utility_core.hpp>
21 #include <boost/mpl/vector.hpp>
22 #include <boost/multi_index/detail/allocator_traits.hpp>
23 #include <boost/multi_index/detail/copy_map.hpp>
24 #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
25 #include <boost/multi_index/detail/index_access_sequence.hpp>
26 #include <boost/multi_index/detail/node_handle.hpp>
27 #include <boost/multi_index/detail/node_type.hpp>
28 #include <boost/multi_index/detail/vartempl_support.hpp>
29 #include <boost/multi_index_container_fwd.hpp>
30 #include <boost/tuple/tuple.hpp>
33 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
34 #include <boost/multi_index/detail/index_loader.hpp>
35 #include <boost/multi_index/detail/index_saver.hpp>
40 namespace multi_index{
44 /* The role of this class is threefold:
45 * - tops the linear hierarchy of indices.
46 * - terminates some cascading backbone function calls (insert_, etc.),
47 * - grants access to the backbone functions of the final
48 * multi_index_container class (for access restriction reasons, these
49 * cannot be called directly from the index classes.)
54 struct emplaced_tag{};
56 template<typename Value,typename IndexSpecifierList,typename Allocator>
60 typedef index_node_base<Value,Allocator> index_node_type;
61 typedef typename multi_index_node_type<
62 Value,IndexSpecifierList,Allocator>::type final_node_type;
63 typedef multi_index_container<
64 Value,IndexSpecifierList,Allocator> final_type;
65 typedef tuples::null_type ctor_args_list;
66 typedef typename rebind_alloc_for<
67 Allocator,typename Allocator::value_type
68 >::type final_allocator_type;
70 final_node_type,final_allocator_type> final_node_handle_type;
71 typedef mpl::vector0<> index_type_list;
72 typedef mpl::vector0<> iterator_type_list;
73 typedef mpl::vector0<> const_iterator_type_list;
76 final_allocator_type> copy_map_type;
78 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
81 final_allocator_type> index_saver_type;
85 final_allocator_type> index_loader_type;
89 typedef Value value_type;
90 typedef allocator_traits<Allocator> alloc_traits;
91 typedef typename alloc_traits::size_type size_type;
94 explicit index_base(const ctor_args_list&,const Allocator&){}
97 const index_base<Value,IndexSpecifierList,Allocator>&,
98 do_not_copy_elements_tag)
102 const index_base<Value,IndexSpecifierList,Allocator>&,const copy_map_type&)
105 final_node_type* insert_(const value_type& v,final_node_type*& x,lvalue_tag)
107 x=final().allocate_node();
109 final().construct_value(x,v);
112 final().deallocate_node(x);
119 final_node_type* insert_(const value_type& v,final_node_type*& x,rvalue_tag)
121 x=final().allocate_node();
123 final().construct_value(x,boost::move(const_cast<value_type&>(v)));
126 final().deallocate_node(x);
133 final_node_type* insert_(const value_type&,final_node_type*& x,emplaced_tag)
138 template<typename MultiIndexContainer>
139 final_node_type* insert_(
140 const value_type&,final_node_type*& x,MultiIndexContainer* p)
142 p->final_extract_for_transfer_(
143 x,index_access_sequence<final_type>(&final()));
147 final_node_type* insert_(
148 const value_type& v,index_node_type*,final_node_type*& x,lvalue_tag)
150 return insert_(v,x,lvalue_tag());
153 final_node_type* insert_(
154 const value_type& v,index_node_type*,final_node_type*& x,rvalue_tag)
156 return insert_(v,x,rvalue_tag());
159 final_node_type* insert_(
160 const value_type&,index_node_type*,final_node_type*& x,emplaced_tag)
165 template<typename Dst>
166 void extract_(index_node_type*,Dst){}
170 template<typename BoolConstant>
172 index_base<Value,IndexSpecifierList,Allocator>&,
173 BoolConstant /* swap_allocators */)
176 void swap_elements_(index_base<Value,IndexSpecifierList,Allocator>&){}
178 bool replace_(const value_type& v,index_node_type* x,lvalue_tag)
184 bool replace_(const value_type& v,index_node_type* x,rvalue_tag)
186 x->value()=boost::move(const_cast<value_type&>(v));
190 bool modify_(index_node_type*){return true;}
192 bool modify_rollback_(index_node_type*){return true;}
194 bool check_rollback_(index_node_type*)const{return true;}
196 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
199 template<typename Archive>
200 void save_(Archive&,const unsigned int,const index_saver_type&)const{}
202 template<typename Archive>
203 void load_(Archive&,const unsigned int,const index_loader_type&){}
206 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
207 /* invariant stuff */
209 bool invariant_()const{return true;}
212 /* access to backbone memfuns of Final class */
214 final_type& final(){return *static_cast<final_type*>(this);}
215 const final_type& final()const{return *static_cast<const final_type*>(this);}
217 template<typename Index>
218 static typename Index::final_type& final(Index& x) /* cross-index access */
219 {return static_cast<typename Index::final_type&>(x);}
221 final_node_type* final_header()const{return final().header();}
223 bool final_empty_()const{return final().empty_();}
224 size_type final_size_()const{return final().size_();}
225 size_type final_max_size_()const{return final().max_size_();}
227 std::pair<final_node_type*,bool> final_insert_(const value_type& x)
228 {return final().insert_(x);}
229 std::pair<final_node_type*,bool> final_insert_rv_(const value_type& x)
230 {return final().insert_rv_(x);}
232 std::pair<final_node_type*,bool> final_insert_ref_(const T& t)
233 {return final().insert_ref_(t);}
235 std::pair<final_node_type*,bool> final_insert_ref_(T& t)
236 {return final().insert_ref_(t);}
237 std::pair<final_node_type*,bool> final_insert_nh_(final_node_handle_type& nh)
238 {return final().insert_nh_(nh);}
240 template<typename Index>
241 std::pair<final_node_type*,bool> final_transfer_(Index& x,final_node_type* n)
242 {return final().transfer_(x,n);}
244 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
245 std::pair<final_node_type*,bool> final_emplace_(
246 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
248 return final().emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
251 std::pair<final_node_type*,bool> final_insert_(
252 const value_type& x,final_node_type* position)
253 {return final().insert_(x,position);}
254 std::pair<final_node_type*,bool> final_insert_rv_(
255 const value_type& x,final_node_type* position)
256 {return final().insert_rv_(x,position);}
258 std::pair<final_node_type*,bool> final_insert_ref_(
259 const T& t,final_node_type* position)
260 {return final().insert_ref_(t,position);}
262 std::pair<final_node_type*,bool> final_insert_ref_(
263 T& t,final_node_type* position)
264 {return final().insert_ref_(t,position);}
265 std::pair<final_node_type*,bool> final_insert_nh_(
266 final_node_handle_type& nh,final_node_type* position)
267 {return final().insert_nh_(nh,position);}
269 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
270 std::pair<final_node_type*,bool> final_emplace_hint_(
271 final_node_type* position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
273 return final().emplace_hint_(
274 position,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
277 final_node_handle_type final_extract_(final_node_type* x)
279 return final().extract_(x);
282 template<typename Dst>
283 void final_extract_for_transfer_(final_node_type* x,Dst dst)
285 final().extract_for_transfer_(x,dst);
288 void final_erase_(final_node_type* x){final().erase_(x);}
290 void final_delete_node_(final_node_type* x){final().delete_node_(x);}
291 void final_delete_all_nodes_(){final().delete_all_nodes_();}
292 void final_clear_(){final().clear_();}
294 template<typename Index>
295 void final_transfer_range_(
297 BOOST_DEDUCED_TYPENAME Index::iterator first,
298 BOOST_DEDUCED_TYPENAME Index::iterator last)
299 {final().transfer_range_(x,first,last);}
301 void final_swap_(final_type& x){final().swap_(x);}
304 const value_type& k,final_node_type* x)
305 {return final().replace_(k,x);}
306 bool final_replace_rv_(
307 const value_type& k,final_node_type* x)
308 {return final().replace_rv_(k,x);}
310 template<typename Modifier>
311 bool final_modify_(Modifier& mod,final_node_type* x)
312 {return final().modify_(mod,x);}
314 template<typename Modifier,typename Rollback>
315 bool final_modify_(Modifier& mod,Rollback& back,final_node_type* x)
316 {return final().modify_(mod,back,x);}
318 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
319 void final_check_invariant_()const{final().check_invariant_();}
323 } /* namespace multi_index::detail */
325 } /* namespace multi_index */
327 } /* namespace boost */