1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2013
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef BOOST_INTRUSIVE_SET_HOOK_HPP
15 #define BOOST_INTRUSIVE_SET_HOOK_HPP
17 #include <boost/intrusive/detail/config_begin.hpp>
18 #include <boost/intrusive/intrusive_fwd.hpp>
20 #include <boost/intrusive/detail/rbtree_node.hpp>
21 #include <boost/intrusive/rbtree_algorithms.hpp>
22 #include <boost/intrusive/options.hpp>
23 #include <boost/intrusive/detail/generic_hook.hpp>
25 #if defined(BOOST_HAS_PRAGMA_ONCE)
32 //! Helper metafunction to define a \c set_base_hook that yields to the same
33 //! type when the same options (either explicitly or implicitly) are used.
34 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
35 template<class ...Options>
37 template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
39 struct make_set_base_hook
42 typedef typename pack_options
44 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
49 >::type packed_options;
53 , rbtree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size>
54 , typename packed_options::tag
55 , packed_options::link_mode
57 > implementation_defined;
59 typedef implementation_defined type;
62 //! Derive a class from set_base_hook in order to store objects in
63 //! in a set/multiset. set_base_hook holds the data necessary to maintain
64 //! the set/multiset and provides an appropriate value_traits class for set/multiset.
66 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
67 //! \c link_mode<> and \c optimize_size<>.
69 //! \c tag<> defines a tag to identify the node.
70 //! The same tag value can be used in different classes, but if a class is
71 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
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.
77 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
78 //! \c auto_unlink or \c safe_link).
80 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
82 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
83 template<class ...Options>
85 template<class O1, class O2, class O3, class O4>
88 : public make_set_base_hook<
89 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
96 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
98 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
99 //! initializes the node to an unlinked state.
101 //! <b>Throws</b>: Nothing.
102 set_base_hook() BOOST_NOEXCEPT;
104 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
105 //! initializes the node to an unlinked state. The argument is ignored.
107 //! <b>Throws</b>: Nothing.
109 //! <b>Rationale</b>: Providing a copy-constructor
110 //! makes classes using the hook STL-compliant without forcing the
111 //! user to do some additional work. \c swap can be used to emulate
113 set_base_hook(const set_base_hook& ) BOOST_NOEXCEPT;
115 //! <b>Effects</b>: Empty function. The argument is ignored.
117 //! <b>Throws</b>: Nothing.
119 //! <b>Rationale</b>: Providing an assignment operator
120 //! makes classes using the hook STL-compliant without forcing the
121 //! user to do some additional work. \c swap can be used to emulate
123 set_base_hook& operator=(const set_base_hook& ) BOOST_NOEXCEPT;
125 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
126 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
127 //! object is stored in a set an assertion is raised. If link_mode is
128 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
130 //! <b>Throws</b>: Nothing.
133 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
134 //! related to those nodes in one or two containers. That is, if the node
135 //! this is part of the element e1, the node x is part of the element e2
136 //! and both elements are included in the containers s1 and s2, then after
137 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
138 //! at the position of e1. If one element is not in a container, then
139 //! after the swap-operation the other element is not in a container.
140 //! Iterators to e1 and e2 related to those nodes are invalidated.
142 //! <b>Complexity</b>: Constant
144 //! <b>Throws</b>: Nothing.
145 void swap_nodes(set_base_hook &other) BOOST_NOEXCEPT;
147 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
149 //! <b>Returns</b>: true, if the node belongs to a container, false
150 //! otherwise. This function can be used to test whether \c set::iterator_to
151 //! will return a valid iterator.
153 //! <b>Complexity</b>: Constant
154 bool is_linked() const BOOST_NOEXCEPT;
156 //! <b>Effects</b>: Removes the node if it's inserted in a container.
157 //! This function is only allowed if link_mode is \c auto_unlink.
159 //! <b>Throws</b>: Nothing.
160 void unlink() BOOST_NOEXCEPT;
164 //! Helper metafunction to define a \c set_member_hook that yields to the same
165 //! type when the same options (either explicitly or implicitly) are used.
166 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
167 template<class ...Options>
169 template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
171 struct make_set_member_hook
174 typedef typename pack_options
176 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
181 >::type packed_options;
185 , rbtree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size>
187 , packed_options::link_mode
189 > implementation_defined;
191 typedef implementation_defined type;
194 //! Put a public data member set_member_hook in order to store objects of this class in
195 //! a set/multiset. set_member_hook holds the data necessary for maintaining the
196 //! set/multiset and provides an appropriate value_traits class for set/multiset.
198 //! The hook admits the following options: \c void_pointer<>,
199 //! \c link_mode<> and \c optimize_size<>.
201 //! \c void_pointer<> is the pointer type that will be used internally in the hook
202 //! and the container configured to use this hook.
204 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
205 //! \c auto_unlink or \c safe_link).
207 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
209 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
210 template<class ...Options>
212 template<class O1, class O2, class O3, class O4>
214 class set_member_hook
215 : public make_set_member_hook<
216 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
223 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
225 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
226 //! initializes the node to an unlinked state.
228 //! <b>Throws</b>: Nothing.
229 set_member_hook() BOOST_NOEXCEPT;
231 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
232 //! initializes the node to an unlinked state. The argument is ignored.
234 //! <b>Throws</b>: Nothing.
236 //! <b>Rationale</b>: Providing a copy-constructor
237 //! makes classes using the hook STL-compliant without forcing the
238 //! user to do some additional work. \c swap can be used to emulate
240 set_member_hook(const set_member_hook& ) BOOST_NOEXCEPT;
242 //! <b>Effects</b>: Empty function. The argument is ignored.
244 //! <b>Throws</b>: Nothing.
246 //! <b>Rationale</b>: Providing an assignment operator
247 //! makes classes using the hook STL-compliant without forcing the
248 //! user to do some additional work. \c swap can be used to emulate
250 set_member_hook& operator=(const set_member_hook& ) BOOST_NOEXCEPT;
252 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
253 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
254 //! object is stored in a set an assertion is raised. If link_mode is
255 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
257 //! <b>Throws</b>: Nothing.
260 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
261 //! related to those nodes in one or two containers. That is, if the node
262 //! this is part of the element e1, the node x is part of the element e2
263 //! and both elements are included in the containers s1 and s2, then after
264 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
265 //! at the position of e1. If one element is not in a container, then
266 //! after the swap-operation the other element is not in a container.
267 //! Iterators to e1 and e2 related to those nodes are invalidated.
269 //! <b>Complexity</b>: Constant
271 //! <b>Throws</b>: Nothing.
272 void swap_nodes(set_member_hook &other) BOOST_NOEXCEPT;
274 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
276 //! <b>Returns</b>: true, if the node belongs to a container, false
277 //! otherwise. This function can be used to test whether \c set::iterator_to
278 //! will return a valid iterator.
280 //! <b>Complexity</b>: Constant
281 bool is_linked() const BOOST_NOEXCEPT;
283 //! <b>Effects</b>: Removes the node if it's inserted in a container.
284 //! This function is only allowed if link_mode is \c auto_unlink.
286 //! <b>Throws</b>: Nothing.
287 void unlink() BOOST_NOEXCEPT;
291 } //namespace intrusive
294 #include <boost/intrusive/detail/config_end.hpp>
296 #endif //BOOST_INTRUSIVE_SET_HOOK_HPP