File indexing completed on 2025-01-18 09:42:07
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_BASE_HPP
0010 #define BOOST_MULTI_INDEX_DETAIL_INDEX_BASE_HPP
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/core/addressof.hpp>
0018 #include <boost/core/no_exceptions_support.hpp>
0019 #include <boost/detail/workaround.hpp>
0020 #include <boost/move/utility_core.hpp>
0021 #include <boost/mpl/vector.hpp>
0022 #include <boost/multi_index/detail/allocator_traits.hpp>
0023 #include <boost/multi_index/detail/copy_map.hpp>
0024 #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
0025 #include <boost/multi_index/detail/index_access_sequence.hpp>
0026 #include <boost/multi_index/detail/node_handle.hpp>
0027 #include <boost/multi_index/detail/node_type.hpp>
0028 #include <boost/multi_index/detail/vartempl_support.hpp>
0029 #include <boost/multi_index_container_fwd.hpp>
0030 #include <boost/tuple/tuple.hpp>
0031 #include <utility>
0032
0033 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
0034 #include <boost/multi_index/detail/index_loader.hpp>
0035 #include <boost/multi_index/detail/index_saver.hpp>
0036 #endif
0037
0038 namespace boost{
0039
0040 namespace multi_index{
0041
0042 namespace detail{
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 struct lvalue_tag{};
0053 struct rvalue_tag{};
0054 struct emplaced_tag{};
0055
0056 template<typename Value,typename IndexSpecifierList,typename Allocator>
0057 class index_base
0058 {
0059 protected:
0060 typedef index_node_base<Value,Allocator> index_node_type;
0061 typedef typename multi_index_node_type<
0062 Value,IndexSpecifierList,Allocator>::type final_node_type;
0063 typedef multi_index_container<
0064 Value,IndexSpecifierList,Allocator> final_type;
0065 typedef tuples::null_type ctor_args_list;
0066 typedef typename rebind_alloc_for<
0067 Allocator,typename Allocator::value_type
0068 >::type final_allocator_type;
0069 typedef node_handle<
0070 final_node_type,final_allocator_type> final_node_handle_type;
0071 typedef mpl::vector0<> index_type_list;
0072 typedef mpl::vector0<> iterator_type_list;
0073 typedef mpl::vector0<> const_iterator_type_list;
0074 typedef copy_map<
0075 final_node_type,
0076 final_allocator_type> copy_map_type;
0077
0078 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
0079 typedef index_saver<
0080 index_node_type,
0081 final_allocator_type> index_saver_type;
0082 typedef index_loader<
0083 index_node_type,
0084 final_node_type,
0085 final_allocator_type> index_loader_type;
0086 #endif
0087
0088 private:
0089 typedef Value value_type;
0090 typedef allocator_traits<Allocator> alloc_traits;
0091 typedef typename alloc_traits::size_type size_type;
0092
0093 protected:
0094 explicit index_base(const ctor_args_list&,const Allocator&){}
0095
0096 index_base(
0097 const index_base<Value,IndexSpecifierList,Allocator>&,
0098 do_not_copy_elements_tag)
0099 {}
0100
0101 void copy_(
0102 const index_base<Value,IndexSpecifierList,Allocator>&,const copy_map_type&)
0103 {}
0104
0105 final_node_type* insert_(const value_type& v,final_node_type*& x,lvalue_tag)
0106 {
0107 x=final().allocate_node();
0108 BOOST_TRY{
0109 final().construct_value(x,v);
0110 }
0111 BOOST_CATCH(...){
0112 final().deallocate_node(x);
0113 BOOST_RETHROW;
0114 }
0115 BOOST_CATCH_END
0116 return x;
0117 }
0118
0119 final_node_type* insert_(const value_type& v,final_node_type*& x,rvalue_tag)
0120 {
0121 x=final().allocate_node();
0122 BOOST_TRY{
0123 final().construct_value(x,boost::move(const_cast<value_type&>(v)));
0124 }
0125 BOOST_CATCH(...){
0126 final().deallocate_node(x);
0127 BOOST_RETHROW;
0128 }
0129 BOOST_CATCH_END
0130 return x;
0131 }
0132
0133 final_node_type* insert_(const value_type&,final_node_type*& x,emplaced_tag)
0134 {
0135 return x;
0136 }
0137
0138 template<typename MultiIndexContainer>
0139 final_node_type* insert_(
0140 const value_type&,final_node_type*& x,MultiIndexContainer* p)
0141 {
0142 p->final_extract_for_transfer_(
0143 x,index_access_sequence<final_type>(&final()));
0144 return x;
0145 }
0146
0147 final_node_type* insert_(
0148 const value_type& v,index_node_type*,final_node_type*& x,lvalue_tag)
0149 {
0150 return insert_(v,x,lvalue_tag());
0151 }
0152
0153 final_node_type* insert_(
0154 const value_type& v,index_node_type*,final_node_type*& x,rvalue_tag)
0155 {
0156 return insert_(v,x,rvalue_tag());
0157 }
0158
0159 final_node_type* insert_(
0160 const value_type&,index_node_type*,final_node_type*& x,emplaced_tag)
0161 {
0162 return x;
0163 }
0164
0165 template<typename Dst>
0166 void extract_(index_node_type*,Dst){}
0167
0168 void clear_(){}
0169
0170 template<typename BoolConstant>
0171 void swap_(
0172 index_base<Value,IndexSpecifierList,Allocator>&,
0173 BoolConstant )
0174 {}
0175
0176 void swap_elements_(index_base<Value,IndexSpecifierList,Allocator>&){}
0177
0178 bool replace_(const value_type& v,index_node_type* x,lvalue_tag)
0179 {
0180 x->value()=v;
0181 return true;
0182 }
0183
0184 bool replace_(const value_type& v,index_node_type* x,rvalue_tag)
0185 {
0186 x->value()=boost::move(const_cast<value_type&>(v));
0187 return true;
0188 }
0189
0190 bool modify_(index_node_type*){return true;}
0191
0192 bool modify_rollback_(index_node_type*){return true;}
0193
0194 bool check_rollback_(index_node_type*)const{return true;}
0195
0196 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
0197
0198
0199 template<typename Archive>
0200 void save_(Archive&,const unsigned int,const index_saver_type&)const{}
0201
0202 template<typename Archive>
0203 void load_(Archive&,const unsigned int,const index_loader_type&){}
0204 #endif
0205
0206 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
0207
0208
0209 bool invariant_()const{return true;}
0210 #endif
0211
0212
0213
0214 final_type& final(){return *static_cast<final_type*>(this);}
0215 const final_type& final()const{return *static_cast<const final_type*>(this);}
0216
0217 template<typename Index>
0218 static typename Index::final_type& final(Index& x)
0219 {return static_cast<typename Index::final_type&>(x);}
0220
0221 final_node_type* final_header()const{return final().header();}
0222
0223 bool final_empty_()const{return final().empty_();}
0224 size_type final_size_()const{return final().size_();}
0225 size_type final_max_size_()const{return final().max_size_();}
0226
0227 std::pair<final_node_type*,bool> final_insert_(const value_type& x)
0228 {return final().insert_(x);}
0229 std::pair<final_node_type*,bool> final_insert_rv_(const value_type& x)
0230 {return final().insert_rv_(x);}
0231 template<typename T>
0232 std::pair<final_node_type*,bool> final_insert_ref_(const T& t)
0233 {return final().insert_ref_(t);}
0234 template<typename T>
0235 std::pair<final_node_type*,bool> final_insert_ref_(T& t)
0236 {return final().insert_ref_(t);}
0237 std::pair<final_node_type*,bool> final_insert_nh_(final_node_handle_type& nh)
0238 {return final().insert_nh_(nh);}
0239
0240 template<typename Index>
0241 std::pair<final_node_type*,bool> final_transfer_(Index& x,final_node_type* n)
0242 {return final().transfer_(x,n);}
0243
0244 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
0245 std::pair<final_node_type*,bool> final_emplace_(
0246 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
0247 {
0248 return final().emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
0249 }
0250
0251 std::pair<final_node_type*,bool> final_insert_(
0252 const value_type& x,final_node_type* position)
0253 {return final().insert_(x,position);}
0254 std::pair<final_node_type*,bool> final_insert_rv_(
0255 const value_type& x,final_node_type* position)
0256 {return final().insert_rv_(x,position);}
0257 template<typename T>
0258 std::pair<final_node_type*,bool> final_insert_ref_(
0259 const T& t,final_node_type* position)
0260 {return final().insert_ref_(t,position);}
0261 template<typename T>
0262 std::pair<final_node_type*,bool> final_insert_ref_(
0263 T& t,final_node_type* position)
0264 {return final().insert_ref_(t,position);}
0265 std::pair<final_node_type*,bool> final_insert_nh_(
0266 final_node_handle_type& nh,final_node_type* position)
0267 {return final().insert_nh_(nh,position);}
0268
0269 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
0270 std::pair<final_node_type*,bool> final_emplace_hint_(
0271 final_node_type* position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
0272 {
0273 return final().emplace_hint_(
0274 position,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
0275 }
0276
0277 final_node_handle_type final_extract_(final_node_type* x)
0278 {
0279 return final().extract_(x);
0280 }
0281
0282 template<typename Dst>
0283 void final_extract_for_transfer_(final_node_type* x,Dst dst)
0284 {
0285 final().extract_for_transfer_(x,dst);
0286 }
0287
0288 void final_erase_(final_node_type* x){final().erase_(x);}
0289
0290 void final_delete_node_(final_node_type* x){final().delete_node_(x);}
0291 void final_delete_all_nodes_(){final().delete_all_nodes_();}
0292 void final_clear_(){final().clear_();}
0293
0294 template<typename Index>
0295 void final_transfer_range_(
0296 Index& x,
0297 BOOST_DEDUCED_TYPENAME Index::iterator first,
0298 BOOST_DEDUCED_TYPENAME Index::iterator last)
0299 {final().transfer_range_(x,first,last);}
0300
0301 void final_swap_(final_type& x){final().swap_(x);}
0302
0303 bool final_replace_(
0304 const value_type& k,final_node_type* x)
0305 {return final().replace_(k,x);}
0306 bool final_replace_rv_(
0307 const value_type& k,final_node_type* x)
0308 {return final().replace_rv_(k,x);}
0309
0310 template<typename Modifier>
0311 bool final_modify_(Modifier& mod,final_node_type* x)
0312 {return final().modify_(mod,x);}
0313
0314 template<typename Modifier,typename Rollback>
0315 bool final_modify_(Modifier& mod,Rollback& back,final_node_type* x)
0316 {return final().modify_(mod,back,x);}
0317
0318 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
0319 void final_check_invariant_()const{final().check_invariant_();}
0320 #endif
0321 };
0322
0323 }
0324
0325 }
0326
0327 }
0328
0329 #endif