1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2007-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_BS_SET_HOOK_HPP
14 #define BOOST_INTRUSIVE_BS_SET_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/tree_node.hpp>
20 #include <boost/intrusive/detail/tree_algorithms.hpp>
21 #include <boost/intrusive/options.hpp>
22 #include <boost/intrusive/detail/generic_hook.hpp>
28 template<class VoidPointer
>
29 struct get_bs_set_node_algo
31 typedef detail::tree_algorithms
<tree_node_traits
<VoidPointer
> > type
;
35 //! Helper metafunction to define a \c bs_set_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_bs_set_base_hook
45 typedef typename pack_options
46 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
47 < hook_defaults
, O1
, O2
, O3
>
49 < hook_defaults
, Options
...>
51 ::type packed_options
;
53 //Scapegoat trees can't be auto unlink trees
54 BOOST_STATIC_ASSERT(((int)packed_options::link_mode
!= (int)auto_unlink
));
56 typedef detail::generic_hook
57 < get_bs_set_node_algo
<typename
packed_options::void_pointer
>
58 , typename
packed_options::tag
59 , packed_options::link_mode
60 , detail::BsSetBaseHook
61 > implementation_defined
;
63 typedef implementation_defined type
;
66 //! Derive a class from bs_set_base_hook in order to store objects in
67 //! in a bs_set/bs_multiset. bs_set_base_hook holds the data necessary to maintain
68 //! the bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
70 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
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).
83 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
84 template<class ...Options
>
86 template<class O1
, class O2
, class O3
>
88 class bs_set_base_hook
89 : public make_bs_set_base_hook
90 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
98 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
99 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
100 //! initializes the node to an unlinked state.
102 //! <b>Throws</b>: Nothing.
105 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
106 //! initializes the node to an unlinked state. The argument is ignored.
108 //! <b>Throws</b>: Nothing.
110 //! <b>Rationale</b>: Providing a copy-constructor
111 //! makes classes using the hook STL-compliant without forcing the
112 //! user to do some additional work. \c swap can be used to emulate
114 bs_set_base_hook(const bs_set_base_hook
& );
116 //! <b>Effects</b>: Empty function. The argument is ignored.
118 //! <b>Throws</b>: Nothing.
120 //! <b>Rationale</b>: Providing an assignment operator
121 //! makes classes using the hook STL-compliant without forcing the
122 //! user to do some additional work. \c swap can be used to emulate
124 bs_set_base_hook
& operator=(const bs_set_base_hook
& );
126 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
127 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
128 //! object is stored in a set an assertion is raised. If link_mode is
129 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
131 //! <b>Throws</b>: Nothing.
134 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
135 //! related to those nodes in one or two containers. That is, if the node
136 //! this is part of the element e1, the node x is part of the element e2
137 //! and both elements are included in the containers s1 and s2, then after
138 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
139 //! at the position of e1. If one element is not in a container, then
140 //! after the swap-operation the other element is not in a container.
141 //! Iterators to e1 and e2 related to those nodes are invalidated.
143 //! <b>Complexity</b>: Constant
145 //! <b>Throws</b>: Nothing.
146 void swap_nodes(bs_set_base_hook
&other
);
148 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
150 //! <b>Returns</b>: true, if the node belongs to a container, false
151 //! otherwise. This function can be used to test whether \c set::iterator_to
152 //! will return a valid iterator.
154 //! <b>Complexity</b>: Constant
155 bool is_linked() const;
157 //! <b>Effects</b>: Removes the node if it's inserted in a container.
158 //! This function is only allowed if link_mode is \c auto_unlink.
160 //! <b>Throws</b>: Nothing.
165 //! Helper metafunction to define a \c bs_set_member_hook that yields to the same
166 //! type when the same options (either explicitly or implicitly) are used.
167 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
168 template<class ...Options
>
170 template<class O1
= none
, class O2
= none
, class O3
= none
>
172 struct make_bs_set_member_hook
175 typedef typename pack_options
176 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
177 < hook_defaults
, O1
, O2
, O3
>
179 < hook_defaults
, Options
...>
182 ::type packed_options
;
184 //Scapegoat trees can't be auto unlink trees
185 BOOST_STATIC_ASSERT(((int)packed_options::link_mode
!= (int)auto_unlink
));
187 typedef detail::generic_hook
188 < get_bs_set_node_algo
<typename
packed_options::void_pointer
>
190 , packed_options::link_mode
192 > implementation_defined
;
194 typedef implementation_defined type
;
197 //! Put a public data member bs_set_member_hook in order to store objects of this class in
198 //! a bs_set/bs_multiset. bs_set_member_hook holds the data necessary for maintaining the
199 //! bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
201 //! The hook admits the following options: \c void_pointer<>, \c link_mode<>.
203 //! \c void_pointer<> is the pointer type that will be used internally in the hook
204 //! and the the container configured to use this hook.
206 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
207 //! \c auto_unlink or \c safe_link).
208 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
209 template<class ...Options
>
211 template<class O1
, class O2
, class O3
>
213 class bs_set_member_hook
214 : public make_bs_set_member_hook
215 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
222 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
223 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
224 //! initializes the node to an unlinked state.
226 //! <b>Throws</b>: Nothing.
227 bs_set_member_hook();
229 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
230 //! initializes the node to an unlinked state. The argument is ignored.
232 //! <b>Throws</b>: Nothing.
234 //! <b>Rationale</b>: Providing a copy-constructor
235 //! makes classes using the hook STL-compliant without forcing the
236 //! user to do some additional work. \c swap can be used to emulate
238 bs_set_member_hook(const bs_set_member_hook
& );
240 //! <b>Effects</b>: Empty function. The argument is ignored.
242 //! <b>Throws</b>: Nothing.
244 //! <b>Rationale</b>: Providing an assignment operator
245 //! makes classes using the hook STL-compliant without forcing the
246 //! user to do some additional work. \c swap can be used to emulate
248 bs_set_member_hook
& operator=(const bs_set_member_hook
& );
250 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
251 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
252 //! object is stored in a set an assertion is raised. If link_mode is
253 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
255 //! <b>Throws</b>: Nothing.
256 ~bs_set_member_hook();
258 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
259 //! related to those nodes in one or two containers. That is, if the node
260 //! this is part of the element e1, the node x is part of the element e2
261 //! and both elements are included in the containers s1 and s2, then after
262 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
263 //! at the position of e1. If one element is not in a container, then
264 //! after the swap-operation the other element is not in a container.
265 //! Iterators to e1 and e2 related to those nodes are invalidated.
267 //! <b>Complexity</b>: Constant
269 //! <b>Throws</b>: Nothing.
270 void swap_nodes(bs_set_member_hook
&other
);
272 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
274 //! <b>Returns</b>: true, if the node belongs to a container, false
275 //! otherwise. This function can be used to test whether \c set::iterator_to
276 //! will return a valid iterator.
278 //! <b>Complexity</b>: Constant
279 bool is_linked() const;
281 //! <b>Effects</b>: Removes the node if it's inserted in a container.
282 //! This function is only allowed if link_mode is \c auto_unlink.
284 //! <b>Throws</b>: Nothing.
289 } //namespace intrusive
292 #include <boost/intrusive/detail/config_end.hpp>
294 #endif //BOOST_INTRUSIVE_BS_SET_HOOK_HPP