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_AVL_SET_HOOK_HPP
14 #define BOOST_INTRUSIVE_AVL_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/avltree_node.hpp>
20 #include <boost/intrusive/avltree_algorithms.hpp>
21 #include <boost/intrusive/options.hpp>
22 #include <boost/intrusive/detail/generic_hook.hpp>
28 template<class VoidPointer
, bool OptimizeSize
= false>
29 struct get_avl_set_node_algo
31 typedef avltree_algorithms
<avltree_node_traits
<VoidPointer
, OptimizeSize
> > type
;
35 //! Helper metafunction to define a \c avl_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
, class O4
= none
>
42 struct make_avl_set_base_hook
45 typedef typename pack_options
46 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
47 <hook_defaults
, O1
, O2
, O3
, O4
>
49 <hook_defaults
, Options
...>
51 ::type packed_options
;
53 typedef detail::generic_hook
54 < get_avl_set_node_algo
<typename
packed_options::void_pointer
55 ,packed_options::optimize_size
>
56 , typename
packed_options::tag
57 , packed_options::link_mode
58 , detail::AvlSetBaseHook
59 > implementation_defined
;
61 typedef implementation_defined type
;
64 //! Derive a class from avl_set_base_hook in order to store objects in
65 //! in an avl_set/avl_multiset. avl_set_base_hook holds the data necessary to maintain
66 //! the avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_multiset.
68 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
69 //! \c link_mode<> and \c optimize_size<>.
71 //! \c tag<> defines a tag to identify the node.
72 //! The same tag value can be used in different classes, but if a class is
73 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
76 //! \c void_pointer<> is the pointer type that will be used internally in the hook
77 //! and the the container configured to use this hook.
79 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
80 //! \c auto_unlink or \c safe_link).
82 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
84 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
85 template<class ...Options
>
87 template<class O1
, class O2
, class O3
, class O4
>
89 class avl_set_base_hook
90 : public make_avl_set_base_hook
91 #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 avl_set_base_hook(const avl_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 avl_set_base_hook
& operator=(const avl_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.
132 ~avl_set_base_hook();
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(avl_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 avl_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
, class O4
= none
>
172 struct make_avl_set_member_hook
175 typedef typename pack_options
176 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
177 <hook_defaults
, O1
, O2
, O3
, O4
>
179 <hook_defaults
, Options
...>
181 ::type packed_options
;
183 typedef detail::generic_hook
184 < get_avl_set_node_algo
<typename
packed_options::void_pointer
185 ,packed_options::optimize_size
>
187 , packed_options::link_mode
189 > implementation_defined
;
191 typedef implementation_defined type
;
194 //! Put a public data member avl_set_member_hook in order to store objects of this class in
195 //! an avl_set/avl_multiset. avl_set_member_hook holds the data necessary for maintaining the
196 //! avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_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 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 avl_set_member_hook
215 : public make_avl_set_member_hook
216 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
223 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
224 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
225 //! initializes the node to an unlinked state.
227 //! <b>Throws</b>: Nothing.
228 avl_set_member_hook();
230 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
231 //! initializes the node to an unlinked state. The argument is ignored.
233 //! <b>Throws</b>: Nothing.
235 //! <b>Rationale</b>: Providing a copy-constructor
236 //! makes classes using the hook STL-compliant without forcing the
237 //! user to do some additional work. \c swap can be used to emulate
239 avl_set_member_hook(const avl_set_member_hook
& );
241 //! <b>Effects</b>: Empty function. The argument is ignored.
243 //! <b>Throws</b>: Nothing.
245 //! <b>Rationale</b>: Providing an assignment operator
246 //! makes classes using the hook STL-compliant without forcing the
247 //! user to do some additional work. \c swap can be used to emulate
249 avl_set_member_hook
& operator=(const avl_set_member_hook
& );
251 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
252 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
253 //! object is stored in a set an assertion is raised. If link_mode is
254 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
256 //! <b>Throws</b>: Nothing.
257 ~avl_set_member_hook();
259 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
260 //! related to those nodes in one or two containers. That is, if the node
261 //! this is part of the element e1, the node x is part of the element e2
262 //! and both elements are included in the containers s1 and s2, then after
263 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
264 //! at the position of e1. If one element is not in a container, then
265 //! after the swap-operation the other element is not in a container.
266 //! Iterators to e1 and e2 related to those nodes are invalidated.
268 //! <b>Complexity</b>: Constant
270 //! <b>Throws</b>: Nothing.
271 void swap_nodes(avl_set_member_hook
&other
);
273 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
275 //! <b>Returns</b>: true, if the node belongs to a container, false
276 //! otherwise. This function can be used to test whether \c set::iterator_to
277 //! will return a valid iterator.
279 //! <b>Complexity</b>: Constant
280 bool is_linked() const;
282 //! <b>Effects</b>: Removes the node if it's inserted in a container.
283 //! This function is only allowed if link_mode is \c auto_unlink.
285 //! <b>Throws</b>: Nothing.
290 } //namespace intrusive
293 #include <boost/intrusive/detail/config_end.hpp>
295 #endif //BOOST_INTRUSIVE_AVL_SET_HOOK_HPP