Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/intrusive/any_hook.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 ///////////////////////////////////////////////////////////////////////////// | |
2 // | |
3 // (C) Copyright Ion Gaztanaga 2006-2013 | |
4 // | |
5 // Distributed under the Boost Software License, Version 1.0. | |
6 // (See accompanying file LICENSE_1_0.txt or copy at | |
7 // http://www.boost.org/LICENSE_1_0.txt) | |
8 // | |
9 // See http://www.boost.org/libs/intrusive for documentation. | |
10 // | |
11 ///////////////////////////////////////////////////////////////////////////// | |
12 | |
13 #ifndef BOOST_INTRUSIVE_ANY_HOOK_HPP | |
14 #define BOOST_INTRUSIVE_ANY_HOOK_HPP | |
15 | |
16 #include <boost/intrusive/detail/config_begin.hpp> | |
17 #include <boost/intrusive/intrusive_fwd.hpp> | |
18 #include <boost/intrusive/detail/utilities.hpp> | |
19 #include <boost/intrusive/detail/any_node_and_algorithms.hpp> | |
20 #include <boost/intrusive/options.hpp> | |
21 #include <boost/intrusive/detail/generic_hook.hpp> | |
22 #include <boost/intrusive/pointer_traits.hpp> | |
23 | |
24 namespace boost { | |
25 namespace intrusive { | |
26 | |
27 /// @cond | |
28 template<class VoidPointer> | |
29 struct get_any_node_algo | |
30 { | |
31 typedef any_algorithms<VoidPointer> type; | |
32 }; | |
33 /// @endcond | |
34 | |
35 //! Helper metafunction to define a \c \c any_base_hook that yields to the same | |
36 //! type when the same options (either explicitly or implicitly) are used. | |
37 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
38 template<class ...Options> | |
39 #else | |
40 template<class O1 = void, class O2 = void, class O3 = void> | |
41 #endif | |
42 struct make_any_base_hook | |
43 { | |
44 /// @cond | |
45 typedef typename pack_options | |
46 < hook_defaults, | |
47 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
48 O1, O2, O3 | |
49 #else | |
50 Options... | |
51 #endif | |
52 >::type packed_options; | |
53 | |
54 typedef generic_hook | |
55 < get_any_node_algo<typename packed_options::void_pointer> | |
56 , typename packed_options::tag | |
57 , packed_options::link_mode | |
58 , AnyBaseHookId | |
59 > implementation_defined; | |
60 /// @endcond | |
61 typedef implementation_defined type; | |
62 }; | |
63 | |
64 //! Derive a class from this hook in order to store objects of that class | |
65 //! in an intrusive container. | |
66 //! | |
67 //! The hook admits the following options: \c tag<>, \c void_pointer<> and | |
68 //! \c link_mode<>. | |
69 //! | |
70 //! \c tag<> defines a tag to identify the node. | |
71 //! The same tag value can be used in different classes, but if a class is | |
72 //! derived from more than one \c any_base_hook, then each \c any_base_hook needs its | |
73 //! unique tag. | |
74 //! | |
75 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, \c safe_link). | |
76 //! | |
77 //! \c void_pointer<> is the pointer type that will be used internally in the hook | |
78 //! and the the container configured to use this hook. | |
79 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
80 template<class ...Options> | |
81 #else | |
82 template<class O1, class O2, class O3> | |
83 #endif | |
84 class any_base_hook | |
85 : public make_any_base_hook | |
86 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
87 <O1, O2, O3> | |
88 #else | |
89 <Options...> | |
90 #endif | |
91 ::type | |
92 { | |
93 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) | |
94 public: | |
95 //! <b>Effects</b>: If link_mode is or \c safe_link | |
96 //! initializes the node to an unlinked state. | |
97 //! | |
98 //! <b>Throws</b>: Nothing. | |
99 any_base_hook(); | |
100 | |
101 //! <b>Effects</b>: If link_mode is or \c safe_link | |
102 //! initializes the node to an unlinked state. The argument is ignored. | |
103 //! | |
104 //! <b>Throws</b>: Nothing. | |
105 //! | |
106 //! <b>Rationale</b>: Providing a copy-constructor | |
107 //! makes classes using the hook STL-compliant without forcing the | |
108 //! user to do some additional work. \c swap can be used to emulate | |
109 //! move-semantics. | |
110 any_base_hook(const any_base_hook& ); | |
111 | |
112 //! <b>Effects</b>: Empty function. The argument is ignored. | |
113 //! | |
114 //! <b>Throws</b>: Nothing. | |
115 //! | |
116 //! <b>Rationale</b>: Providing an assignment operator | |
117 //! makes classes using the hook STL-compliant without forcing the | |
118 //! user to do some additional work. \c swap can be used to emulate | |
119 //! move-semantics. | |
120 any_base_hook& operator=(const any_base_hook& ); | |
121 | |
122 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does | |
123 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the | |
124 //! object is stored in a container an assertion is raised. | |
125 //! | |
126 //! <b>Throws</b>: Nothing. | |
127 ~any_base_hook(); | |
128 | |
129 //! <b>Precondition</b>: link_mode must be \c safe_link. | |
130 //! | |
131 //! <b>Returns</b>: true, if the node belongs to a container, false | |
132 //! otherwise. This function can be used to test whether \c container::iterator_to | |
133 //! will return a valid iterator. | |
134 //! | |
135 //! <b>Complexity</b>: Constant | |
136 bool is_linked() const; | |
137 #endif | |
138 }; | |
139 | |
140 //! Helper metafunction to define a \c \c any_member_hook that yields to the same | |
141 //! type when the same options (either explicitly or implicitly) are used. | |
142 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
143 template<class ...Options> | |
144 #else | |
145 template<class O1 = void, class O2 = void, class O3 = void> | |
146 #endif | |
147 struct make_any_member_hook | |
148 { | |
149 /// @cond | |
150 typedef typename pack_options | |
151 < hook_defaults, | |
152 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
153 O1, O2, O3 | |
154 #else | |
155 Options... | |
156 #endif | |
157 >::type packed_options; | |
158 | |
159 typedef generic_hook | |
160 < get_any_node_algo<typename packed_options::void_pointer> | |
161 , member_tag | |
162 , packed_options::link_mode | |
163 , NoBaseHookId | |
164 > implementation_defined; | |
165 /// @endcond | |
166 typedef implementation_defined type; | |
167 }; | |
168 | |
169 //! Store this hook in a class to be inserted | |
170 //! in an intrusive container. | |
171 //! | |
172 //! The hook admits the following options: \c void_pointer<> and | |
173 //! \c link_mode<>. | |
174 //! | |
175 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link or \c safe_link). | |
176 //! | |
177 //! \c void_pointer<> is the pointer type that will be used internally in the hook | |
178 //! and the the container configured to use this hook. | |
179 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
180 template<class ...Options> | |
181 #else | |
182 template<class O1, class O2, class O3> | |
183 #endif | |
184 class any_member_hook | |
185 : public make_any_member_hook | |
186 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) | |
187 <O1, O2, O3> | |
188 #else | |
189 <Options...> | |
190 #endif | |
191 ::type | |
192 { | |
193 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) | |
194 public: | |
195 //! <b>Effects</b>: If link_mode is or \c safe_link | |
196 //! initializes the node to an unlinked state. | |
197 //! | |
198 //! <b>Throws</b>: Nothing. | |
199 any_member_hook(); | |
200 | |
201 //! <b>Effects</b>: If link_mode is or \c safe_link | |
202 //! initializes the node to an unlinked state. The argument is ignored. | |
203 //! | |
204 //! <b>Throws</b>: Nothing. | |
205 //! | |
206 //! <b>Rationale</b>: Providing a copy-constructor | |
207 //! makes classes using the hook STL-compliant without forcing the | |
208 //! user to do some additional work. \c swap can be used to emulate | |
209 //! move-semantics. | |
210 any_member_hook(const any_member_hook& ); | |
211 | |
212 //! <b>Effects</b>: Empty function. The argument is ignored. | |
213 //! | |
214 //! <b>Throws</b>: Nothing. | |
215 //! | |
216 //! <b>Rationale</b>: Providing an assignment operator | |
217 //! makes classes using the hook STL-compliant without forcing the | |
218 //! user to do some additional work. \c swap can be used to emulate | |
219 //! move-semantics. | |
220 any_member_hook& operator=(const any_member_hook& ); | |
221 | |
222 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does | |
223 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the | |
224 //! object is stored in a container an assertion is raised. | |
225 //! | |
226 //! <b>Throws</b>: Nothing. | |
227 ~any_member_hook(); | |
228 | |
229 //! <b>Precondition</b>: link_mode must be \c safe_link. | |
230 //! | |
231 //! <b>Returns</b>: true, if the node belongs to a container, false | |
232 //! otherwise. This function can be used to test whether \c container::iterator_to | |
233 //! will return a valid iterator. | |
234 //! | |
235 //! <b>Complexity</b>: Constant | |
236 bool is_linked() const; | |
237 #endif | |
238 }; | |
239 | |
240 /// @cond | |
241 | |
242 namespace detail{ | |
243 | |
244 template<class ValueTraits> | |
245 struct any_to_get_base_pointer_type | |
246 { | |
247 typedef typename pointer_traits<typename ValueTraits::hooktags::node_traits::node_ptr>::template | |
248 rebind_pointer<void>::type type; | |
249 }; | |
250 | |
251 template<class ValueTraits> | |
252 struct any_to_get_member_pointer_type | |
253 { | |
254 typedef typename pointer_traits | |
255 <typename ValueTraits::node_ptr>::template rebind_pointer<void>::type type; | |
256 }; | |
257 | |
258 //!This option setter specifies that the container | |
259 //!must use the specified base hook | |
260 template<class BaseHook, template <class> class NodeTraits> | |
261 struct any_to_some_hook | |
262 { | |
263 typedef typename BaseHook::template pack<empty>::proto_value_traits old_proto_value_traits; | |
264 | |
265 template<class Base> | |
266 struct pack : public Base | |
267 { | |
268 struct proto_value_traits : public old_proto_value_traits | |
269 { | |
270 static const bool is_any_hook = true; | |
271 typedef typename detail::eval_if_c | |
272 < detail::internal_base_hook_bool_is_true<old_proto_value_traits>::value | |
273 , any_to_get_base_pointer_type<old_proto_value_traits> | |
274 , any_to_get_member_pointer_type<old_proto_value_traits> | |
275 >::type void_pointer; | |
276 typedef NodeTraits<void_pointer> node_traits; | |
277 }; | |
278 }; | |
279 }; | |
280 | |
281 } //namespace detail{ | |
282 | |
283 /// @endcond | |
284 | |
285 //!This option setter specifies that | |
286 //!any hook should behave as an slist hook | |
287 template<class BaseHook> | |
288 struct any_to_slist_hook | |
289 /// @cond | |
290 : public detail::any_to_some_hook<BaseHook, any_slist_node_traits> | |
291 /// @endcond | |
292 {}; | |
293 | |
294 //!This option setter specifies that | |
295 //!any hook should behave as an list hook | |
296 template<class BaseHook> | |
297 struct any_to_list_hook | |
298 /// @cond | |
299 : public detail::any_to_some_hook<BaseHook, any_list_node_traits> | |
300 /// @endcond | |
301 {}; | |
302 | |
303 //!This option setter specifies that | |
304 //!any hook should behave as a set hook | |
305 template<class BaseHook> | |
306 struct any_to_set_hook | |
307 /// @cond | |
308 : public detail::any_to_some_hook<BaseHook, any_rbtree_node_traits> | |
309 /// @endcond | |
310 {}; | |
311 | |
312 //!This option setter specifies that | |
313 //!any hook should behave as an avl_set hook | |
314 template<class BaseHook> | |
315 struct any_to_avl_set_hook | |
316 /// @cond | |
317 : public detail::any_to_some_hook<BaseHook, any_avltree_node_traits> | |
318 /// @endcond | |
319 {}; | |
320 | |
321 //!This option setter specifies that any | |
322 //!hook should behave as a bs_set hook | |
323 template<class BaseHook> | |
324 struct any_to_bs_set_hook | |
325 /// @cond | |
326 : public detail::any_to_some_hook<BaseHook, any_tree_node_traits> | |
327 /// @endcond | |
328 {}; | |
329 | |
330 //!This option setter specifies that any hook | |
331 //!should behave as an unordered set hook | |
332 template<class BaseHook> | |
333 struct any_to_unordered_set_hook | |
334 /// @cond | |
335 : public detail::any_to_some_hook<BaseHook, any_unordered_node_traits> | |
336 /// @endcond | |
337 {}; | |
338 | |
339 | |
340 } //namespace intrusive | |
341 } //namespace boost | |
342 | |
343 #include <boost/intrusive/detail/config_end.hpp> | |
344 | |
345 #endif //BOOST_INTRUSIVE_ANY_HOOK_HPP |