1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2013
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/any_node_and_algorithms.hpp>
19 #include <boost/intrusive/options.hpp>
20 #include <boost/intrusive/detail/generic_hook.hpp>
21 #include <boost/intrusive/detail/mpl.hpp>
22 #include <boost/intrusive/pointer_rebind.hpp>
24 #if defined(BOOST_HAS_PRAGMA_ONCE)
31 //! Helper metafunction to define a \c \c any_base_hook that yields to the same
32 //! type when the same options (either explicitly or implicitly) are used.
33 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
34 template<class ...Options>
36 template<class O1 = void, class O2 = void, class O3 = void>
38 struct make_any_base_hook
41 typedef typename pack_options
43 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
48 >::type packed_options;
52 , any_node_traits<typename packed_options::void_pointer>
53 , typename packed_options::tag
54 , packed_options::link_mode
56 > implementation_defined;
58 typedef implementation_defined type;
61 //! Derive a class from this hook in order to store objects of that class
62 //! in an intrusive container.
64 //! The hook admits the following options: \c tag<>, \c void_pointer<> and
67 //! \c tag<> defines a tag to identify the node.
68 //! The same tag value can be used in different classes, but if a class is
69 //! derived from more than one \c any_base_hook, then each \c any_base_hook needs its
72 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, \c safe_link).
74 //! \c void_pointer<> is the pointer type that will be used internally in the hook
75 //! and the container configured to use this hook.
76 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
77 template<class ...Options>
79 template<class O1, class O2, class O3>
82 : public make_any_base_hook
83 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
90 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
92 //! <b>Effects</b>: If link_mode is or \c safe_link
93 //! initializes the node to an unlinked state.
95 //! <b>Throws</b>: Nothing.
98 //! <b>Effects</b>: If link_mode is or \c safe_link
99 //! initializes the node to an unlinked state. The argument is ignored.
101 //! <b>Throws</b>: Nothing.
103 //! <b>Rationale</b>: Providing a copy-constructor
104 //! makes classes using the hook STL-compliant without forcing the
105 //! user to do some additional work. \c swap can be used to emulate
107 any_base_hook(const any_base_hook& );
109 //! <b>Effects</b>: Empty function. The argument is ignored.
111 //! <b>Throws</b>: Nothing.
113 //! <b>Rationale</b>: Providing an assignment operator
114 //! makes classes using the hook STL-compliant without forcing the
115 //! user to do some additional work. \c swap can be used to emulate
117 any_base_hook& operator=(const any_base_hook& );
119 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
120 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
121 //! object is stored in a container an assertion is raised.
123 //! <b>Throws</b>: Nothing.
126 //! <b>Precondition</b>: link_mode must be \c safe_link.
128 //! <b>Returns</b>: true, if the node belongs to a container, false
129 //! otherwise. This function can be used to test whether \c container::iterator_to
130 //! will return a valid iterator.
132 //! <b>Complexity</b>: Constant
133 bool is_linked() const;
137 //! Helper metafunction to define a \c \c any_member_hook that yields to the same
138 //! type when the same options (either explicitly or implicitly) are used.
139 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
140 template<class ...Options>
142 template<class O1 = void, class O2 = void, class O3 = void>
144 struct make_any_member_hook
147 typedef typename pack_options
149 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
154 >::type packed_options;
158 , any_node_traits<typename packed_options::void_pointer>
160 , packed_options::link_mode
162 > implementation_defined;
164 typedef implementation_defined type;
167 //! Store this hook in a class to be inserted
168 //! in an intrusive container.
170 //! The hook admits the following options: \c void_pointer<> and
173 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link or \c safe_link).
175 //! \c void_pointer<> is the pointer type that will be used internally in the hook
176 //! and the container configured to use this hook.
177 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
178 template<class ...Options>
180 template<class O1, class O2, class O3>
182 class any_member_hook
183 : public make_any_member_hook
184 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
191 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
193 //! <b>Effects</b>: If link_mode is or \c safe_link
194 //! initializes the node to an unlinked state.
196 //! <b>Throws</b>: Nothing.
199 //! <b>Effects</b>: If link_mode is or \c safe_link
200 //! initializes the node to an unlinked state. The argument is ignored.
202 //! <b>Throws</b>: Nothing.
204 //! <b>Rationale</b>: Providing a copy-constructor
205 //! makes classes using the hook STL-compliant without forcing the
206 //! user to do some additional work. \c swap can be used to emulate
208 any_member_hook(const any_member_hook& );
210 //! <b>Effects</b>: Empty function. The argument is ignored.
212 //! <b>Throws</b>: Nothing.
214 //! <b>Rationale</b>: Providing an assignment operator
215 //! makes classes using the hook STL-compliant without forcing the
216 //! user to do some additional work. \c swap can be used to emulate
218 any_member_hook& operator=(const any_member_hook& );
220 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
221 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
222 //! object is stored in a container an assertion is raised.
224 //! <b>Throws</b>: Nothing.
227 //! <b>Precondition</b>: link_mode must be \c safe_link.
229 //! <b>Returns</b>: true, if the node belongs to a container, false
230 //! otherwise. This function can be used to test whether \c container::iterator_to
231 //! will return a valid iterator.
233 //! <b>Complexity</b>: Constant
234 bool is_linked() const;
242 BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(old_proto_value_traits_base_hook, hooktags::is_base_hook)
244 //!This option setter specifies that the container
245 //!must use the specified base hook
246 template<class BasicHook, template <class> class NodeTraits>
247 struct any_to_some_hook
249 typedef typename BasicHook::template pack<empty>::proto_value_traits old_proto_value_traits;
252 struct pack : public Base
254 struct proto_value_traits
256 //proto_value_traits::hooktags::is_base_hook is used by get_value_traits
257 //to detect base hooks, so mark it in case BasicHook has it.
260 static const bool is_base_hook = old_proto_value_traits_base_hook_bool_is_true
261 <old_proto_value_traits>::value;
264 typedef old_proto_value_traits basic_hook_t;
265 static const bool is_any_hook = true;
267 template<class VoidPtr>
268 struct node_traits_from_voidptr
269 { typedef NodeTraits<VoidPtr> type; };
274 } //namespace detail{
278 //!This option setter specifies that
279 //!any hook should behave as an slist hook
280 template<class BasicHook>
281 struct any_to_slist_hook
283 : public detail::any_to_some_hook<BasicHook, any_slist_node_traits>
287 //!This option setter specifies that
288 //!any hook should behave as an list hook
289 template<class BasicHook>
290 struct any_to_list_hook
292 : public detail::any_to_some_hook<BasicHook, any_list_node_traits>
296 //!This option setter specifies that
297 //!any hook should behave as a set hook
298 template<class BasicHook>
299 struct any_to_set_hook
301 : public detail::any_to_some_hook<BasicHook, any_rbtree_node_traits>
305 //!This option setter specifies that
306 //!any hook should behave as an avl_set hook
307 template<class BasicHook>
308 struct any_to_avl_set_hook
310 : public detail::any_to_some_hook<BasicHook, any_avltree_node_traits>
314 //!This option setter specifies that any
315 //!hook should behave as a bs_set hook
316 template<class BasicHook>
317 struct any_to_bs_set_hook
319 : public detail::any_to_some_hook<BasicHook, any_tree_node_traits>
323 //!This option setter specifies that any hook
324 //!should behave as an unordered set hook
325 template<class BasicHook>
326 struct any_to_unordered_set_hook
328 : public detail::any_to_some_hook<BasicHook, any_unordered_node_traits>
333 } //namespace intrusive
336 #include <boost/intrusive/detail/config_end.hpp>
338 #endif //BOOST_INTRUSIVE_ANY_HOOK_HPP