1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2008
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)
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>
28 template<class VoidPointer
>
29 struct get_any_node_algo
31 typedef any_algorithms
<VoidPointer
> type
;
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
>
40 template<class O1
= none
, class O2
= none
, class O3
= none
>
42 struct make_any_base_hook
45 typedef typename pack_options
47 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
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
59 > implementation_defined
;
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.
67 //! The hook admits the following options: \c tag<>, \c void_pointer<> and
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
75 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, \c safe_link).
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
>
82 template<class O1
, class O2
, class O3
>
85 : public make_any_base_hook
86 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
93 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
95 //! <b>Effects</b>: If link_mode is or \c safe_link
96 //! initializes the node to an unlinked state.
98 //! <b>Throws</b>: Nothing.
101 //! <b>Effects</b>: If link_mode is or \c safe_link
102 //! initializes the node to an unlinked state. The argument is ignored.
104 //! <b>Throws</b>: Nothing.
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
110 any_base_hook(const any_base_hook
& );
112 //! <b>Effects</b>: Empty function. The argument is ignored.
114 //! <b>Throws</b>: Nothing.
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
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.
126 //! <b>Throws</b>: Nothing.
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;
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
>
145 template<class O1
= none
, class O2
= none
, class O3
= none
>
147 struct make_any_member_hook
150 typedef typename pack_options
152 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
157 >::type packed_options
;
159 typedef detail::generic_hook
160 < get_any_node_algo
<typename
packed_options::void_pointer
>
162 , packed_options::link_mode
164 > implementation_defined
;
166 typedef implementation_defined type
;
169 //! Store this hook in a class to be inserted
170 //! in an intrusive container.
172 //! The hook admits the following options: \c void_pointer<> and
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
>
182 template<class O1
, class O2
, class O3
>
184 class any_member_hook
185 : public make_any_member_hook
186 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
193 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
195 //! <b>Effects</b>: If link_mode is or \c safe_link
196 //! initializes the node to an unlinked state.
198 //! <b>Throws</b>: Nothing.
201 //! <b>Effects</b>: If link_mode is or \c safe_link
202 //! initializes the node to an unlinked state. The argument is ignored.
204 //! <b>Throws</b>: Nothing.
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
210 any_member_hook(const any_member_hook
& );
212 //! <b>Effects</b>: Empty function. The argument is ignored.
214 //! <b>Throws</b>: Nothing.
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
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.
226 //! <b>Throws</b>: Nothing.
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;
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
;
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{
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
289 : public detail::any_to_some_hook
<BaseHook
, any_slist_node_traits
>
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
298 : public detail::any_to_some_hook
<BaseHook
, any_list_node_traits
>
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
307 : public detail::any_to_some_hook
<BaseHook
, any_rbtree_node_traits
>
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
316 : public detail::any_to_some_hook
<BaseHook
, any_avltree_node_traits
>
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
325 : public detail::any_to_some_hook
<BaseHook
, any_tree_node_traits
>
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
334 : public detail::any_to_some_hook
<BaseHook
, any_unordered_node_traits
>
339 } //namespace intrusive
342 #include <boost/intrusive/detail/config_end.hpp>
344 #endif //BOOST_INTRUSIVE_ANY_HOOK_HPP