fix doc example typo
[boost.git] / boost / intrusive / any_hook.hpp
blob29a5b089d65f93553354a40d772b460f32cbf18b
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-2008
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.
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_ANY_HOOK_HPP
14 #define BOOST_INTRUSIVE_ANY_HOOK_HPP
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/detail/pointer_to_other.hpp>
24 namespace boost {
25 namespace intrusive {
27 /// @cond
28 template<class VoidPointer>
29 struct get_any_node_algo
31 typedef any_algorithms<VoidPointer> type;
33 /// @endcond
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 = none, class O2 = none, class O3 = none>
41 #endif
42 struct make_any_base_hook
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;
54 typedef detail::generic_hook
55 < get_any_node_algo<typename packed_options::void_pointer>
56 , typename packed_options::tag
57 , packed_options::link_mode
58 , detail::AnyBaseHook
59 > implementation_defined;
60 /// @endcond
61 typedef implementation_defined type;
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
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();
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& );
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& );
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();
129 //! <b>Precondition</b>: link_mode must be \c safe_link.
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.
135 //! <b>Complexity</b>: Constant
136 bool is_linked() const;
137 #endif
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 = none, class O2 = none, class O3 = none>
146 #endif
147 struct make_any_member_hook
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;
159 typedef detail::generic_hook
160 < get_any_node_algo<typename packed_options::void_pointer>
161 , member_tag
162 , packed_options::link_mode
163 , detail::NoBaseHook
164 > implementation_defined;
165 /// @endcond
166 typedef implementation_defined type;
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).
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
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();
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& );
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& );
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();
229 //! <b>Precondition</b>: link_mode must be \c safe_link.
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.
235 //! <b>Complexity</b>: Constant
236 bool is_linked() const;
237 #endif
240 /// @cond
242 namespace detail{
244 template<class ValueTraits>
245 struct any_to_get_base_pointer_type
247 typedef typename pointer_to_other
248 <typename ValueTraits::boost_intrusive_tags::node_traits::node_ptr, void>::type type;
251 template<class ValueTraits>
252 struct any_to_get_member_pointer_type
254 typedef typename pointer_to_other
255 <typename ValueTraits::node_ptr, void>::type type;
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
263 typedef typename BaseHook::template pack<none>::value_traits old_value_traits;
264 template<class Base>
265 struct pack : public Base
267 struct value_traits : public old_value_traits
269 static const bool is_any_hook = true;
270 typedef typename detail::eval_if_c
271 < detail::internal_base_hook_bool_is_true<old_value_traits>::value
272 , any_to_get_base_pointer_type<old_value_traits>
273 , any_to_get_member_pointer_type<old_value_traits>
274 >::type void_pointer;
275 typedef NodeTraits<void_pointer> node_traits;
280 } //namespace detail{
282 /// @endcond
284 //!This option setter specifies that
285 //!any hook should behave as an slist hook
286 template<class BaseHook>
287 struct any_to_slist_hook
288 /// @cond
289 : public detail::any_to_some_hook<BaseHook, any_slist_node_traits>
290 /// @endcond
293 //!This option setter specifies that
294 //!any hook should behave as an list hook
295 template<class BaseHook>
296 struct any_to_list_hook
297 /// @cond
298 : public detail::any_to_some_hook<BaseHook, any_list_node_traits>
299 /// @endcond
302 //!This option setter specifies that
303 //!any hook should behave as a set hook
304 template<class BaseHook>
305 struct any_to_set_hook
306 /// @cond
307 : public detail::any_to_some_hook<BaseHook, any_rbtree_node_traits>
308 /// @endcond
311 //!This option setter specifies that
312 //!any hook should behave as an avl_set hook
313 template<class BaseHook>
314 struct any_to_avl_set_hook
315 /// @cond
316 : public detail::any_to_some_hook<BaseHook, any_avltree_node_traits>
317 /// @endcond
320 //!This option setter specifies that any
321 //!hook should behave as a bs_set hook
322 template<class BaseHook>
323 struct any_to_bs_set_hook
324 /// @cond
325 : public detail::any_to_some_hook<BaseHook, any_tree_node_traits>
326 /// @endcond
329 //!This option setter specifies that any hook
330 //!should behave as an unordered set hook
331 template<class BaseHook>
332 struct any_to_unordered_set_hook
333 /// @cond
334 : public detail::any_to_some_hook<BaseHook, any_unordered_node_traits>
335 /// @endcond
339 } //namespace intrusive
340 } //namespace boost
342 #include <boost/intrusive/detail/config_end.hpp>
344 #endif //BOOST_INTRUSIVE_ANY_HOOK_HPP