1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2008
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>
19 #include <boost/intrusive/detail/utilities.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>
29 template<class VoidPointer
, bool OptimizeSize
= false>
30 struct get_set_node_algo
32 typedef rbtree_algorithms
<rbtree_node_traits
<VoidPointer
, OptimizeSize
> > type
;
36 //! Helper metafunction to define a \c set_base_hook that yields to the same
37 //! type when the same options (either explicitly or implicitly) are used.
38 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
39 template<class ...Options
>
41 template<class O1
= none
, class O2
= none
, class O3
= none
, class O4
= none
>
43 struct make_set_base_hook
46 typedef typename pack_options
48 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
53 >::type packed_options
;
55 typedef detail::generic_hook
56 < get_set_node_algo
<typename
packed_options::void_pointer
57 ,packed_options::optimize_size
>
58 , typename
packed_options::tag
59 , packed_options::link_mode
61 > implementation_defined
;
63 typedef implementation_defined type
;
66 //! Derive a class from set_base_hook in order to store objects in
67 //! in a set/multiset. set_base_hook holds the data necessary to maintain
68 //! the set/multiset and provides an appropriate value_traits class for set/multiset.
70 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
71 //! \c link_mode<> and \c optimize_size<>.
73 //! \c tag<> defines a tag to identify the node.
74 //! The same tag value can be used in different classes, but if a class is
75 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
78 //! \c void_pointer<> is the pointer type that will be used internally in the hook
79 //! and the the container configured to use this hook.
81 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
82 //! \c auto_unlink or \c safe_link).
84 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
86 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
87 template<class ...Options
>
89 template<class O1
, class O2
, class O3
, class O4
>
92 : public make_set_base_hook
<
93 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
100 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
101 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
102 //! initializes the node to an unlinked state.
104 //! <b>Throws</b>: Nothing.
107 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
108 //! initializes the node to an unlinked state. The argument is ignored.
110 //! <b>Throws</b>: Nothing.
112 //! <b>Rationale</b>: Providing a copy-constructor
113 //! makes classes using the hook STL-compliant without forcing the
114 //! user to do some additional work. \c swap can be used to emulate
116 set_base_hook(const set_base_hook
& );
118 //! <b>Effects</b>: Empty function. The argument is ignored.
120 //! <b>Throws</b>: Nothing.
122 //! <b>Rationale</b>: Providing an assignment operator
123 //! makes classes using the hook STL-compliant without forcing the
124 //! user to do some additional work. \c swap can be used to emulate
126 set_base_hook
& operator=(const set_base_hook
& );
128 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
129 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
130 //! object is stored in a set an assertion is raised. If link_mode is
131 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
133 //! <b>Throws</b>: Nothing.
136 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
137 //! related to those nodes in one or two containers. That is, if the node
138 //! this is part of the element e1, the node x is part of the element e2
139 //! and both elements are included in the containers s1 and s2, then after
140 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
141 //! at the position of e1. If one element is not in a container, then
142 //! after the swap-operation the other element is not in a container.
143 //! Iterators to e1 and e2 related to those nodes are invalidated.
145 //! <b>Complexity</b>: Constant
147 //! <b>Throws</b>: Nothing.
148 void swap_nodes(set_base_hook
&other
);
150 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
152 //! <b>Returns</b>: true, if the node belongs to a container, false
153 //! otherwise. This function can be used to test whether \c set::iterator_to
154 //! will return a valid iterator.
156 //! <b>Complexity</b>: Constant
157 bool is_linked() const;
159 //! <b>Effects</b>: Removes the node if it's inserted in a container.
160 //! This function is only allowed if link_mode is \c auto_unlink.
162 //! <b>Throws</b>: Nothing.
167 //! Helper metafunction to define a \c set_member_hook that yields to the same
168 //! type when the same options (either explicitly or implicitly) are used.
169 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
170 template<class ...Options
>
172 template<class O1
= none
, class O2
= none
, class O3
= none
, class O4
= none
>
174 struct make_set_member_hook
177 typedef typename pack_options
179 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
184 >::type packed_options
;
186 typedef detail::generic_hook
187 < get_set_node_algo
<typename
packed_options::void_pointer
188 ,packed_options::optimize_size
>
190 , packed_options::link_mode
192 > implementation_defined
;
194 typedef implementation_defined type
;
197 //! Put a public data member set_member_hook in order to store objects of this class in
198 //! a set/multiset. set_member_hook holds the data necessary for maintaining the
199 //! set/multiset and provides an appropriate value_traits class for set/multiset.
201 //! The hook admits the following options: \c void_pointer<>,
202 //! \c link_mode<> and \c optimize_size<>.
204 //! \c void_pointer<> is the pointer type that will be used internally in the hook
205 //! and the the container configured to use this hook.
207 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
208 //! \c auto_unlink or \c safe_link).
210 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
212 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
213 template<class ...Options
>
215 template<class O1
, class O2
, class O3
, class O4
>
217 class set_member_hook
218 : public make_set_member_hook
<
219 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
226 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
227 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
228 //! initializes the node to an unlinked state.
230 //! <b>Throws</b>: Nothing.
233 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
234 //! initializes the node to an unlinked state. The argument is ignored.
236 //! <b>Throws</b>: Nothing.
238 //! <b>Rationale</b>: Providing a copy-constructor
239 //! makes classes using the hook STL-compliant without forcing the
240 //! user to do some additional work. \c swap can be used to emulate
242 set_member_hook(const set_member_hook
& );
244 //! <b>Effects</b>: Empty function. The argument is ignored.
246 //! <b>Throws</b>: Nothing.
248 //! <b>Rationale</b>: Providing an assignment operator
249 //! makes classes using the hook STL-compliant without forcing the
250 //! user to do some additional work. \c swap can be used to emulate
252 set_member_hook
& operator=(const set_member_hook
& );
254 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
255 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
256 //! object is stored in a set an assertion is raised. If link_mode is
257 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
259 //! <b>Throws</b>: Nothing.
262 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
263 //! related to those nodes in one or two containers. That is, if the node
264 //! this is part of the element e1, the node x is part of the element e2
265 //! and both elements are included in the containers s1 and s2, then after
266 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
267 //! at the position of e1. If one element is not in a container, then
268 //! after the swap-operation the other element is not in a container.
269 //! Iterators to e1 and e2 related to those nodes are invalidated.
271 //! <b>Complexity</b>: Constant
273 //! <b>Throws</b>: Nothing.
274 void swap_nodes(set_member_hook
&other
);
276 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
278 //! <b>Returns</b>: true, if the node belongs to a container, false
279 //! otherwise. This function can be used to test whether \c set::iterator_to
280 //! will return a valid iterator.
282 //! <b>Complexity</b>: Constant
283 bool is_linked() const;
285 //! <b>Effects</b>: Removes the node if it's inserted in a container.
286 //! This function is only allowed if link_mode is \c auto_unlink.
288 //! <b>Throws</b>: Nothing.
293 } //namespace intrusive
296 #include <boost/intrusive/detail/config_end.hpp>
298 #endif //BOOST_INTRUSIVE_SET_HOOK_HPP