Add Boost.Test karmic valgrind suppressions
[senf.git] / boost / multi_index / detail / index_base.hpp
1 /* Copyright 2003-2007 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,Allocator>    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   bool modify_rollback_(node_type*){return true;}
121
122 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
123   /* serialization */
124
125   template<typename Archive>
126   void save_(Archive&,const unsigned int,const index_saver_type&)const{}
127
128   template<typename Archive>
129   void load_(Archive&,const unsigned int,const index_loader_type&){}
130 #endif
131
132 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
133   /* invariant stuff */
134
135   bool invariant_()const{return true;}
136 #endif
137
138   /* access to backbone memfuns of Final class */
139
140   final_type&       final(){return *static_cast<final_type*>(this);}
141   const final_type& final()const{return *static_cast<const final_type*>(this);}
142
143   final_node_type* final_header()const{return final().header();}
144
145   bool        final_empty_()const{return final().empty_();}
146   std::size_t final_size_()const{return final().size_();}
147   std::size_t final_max_size_()const{return final().max_size_();}
148
149   std::pair<final_node_type*,bool> final_insert_(value_param_type x)
150     {return final().insert_(x);}
151   std::pair<final_node_type*,bool> final_insert_(
152     value_param_type x,final_node_type* position)
153     {return final().insert_(x,position);}
154
155   void final_erase_(final_node_type* x){final().erase_(x);}
156
157   void final_delete_node_(final_node_type* x){final().delete_node_(x);}
158   void final_delete_all_nodes_(){final().delete_all_nodes_();}
159   void final_clear_(){final().clear_();}
160
161   void final_swap_(final_type& x){final().swap_(x);}
162   bool final_replace_(
163     value_param_type k,final_node_type* x)
164     {return final().replace_(k,x);}
165
166   template<typename Modifier>
167   bool final_modify_(Modifier& mod,final_node_type* x)
168     {return final().modify_(mod,x);}
169
170   template<typename Modifier,typename Rollback>
171   bool final_modify_(Modifier& mod,Rollback& back,final_node_type* x)
172     {return final().modify_(mod,back,x);}
173
174 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
175   void final_check_invariant_()const{final().check_invariant_();}
176 #endif
177 };
178
179 } /* namespace multi_index::detail */
180
181 } /* namespace multi_index */
182
183 } /* namespace boost */
184
185 #endif