1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2007-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_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>
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>
24 #if defined(BOOST_HAS_PRAGMA_ONCE)
31 //! Helper metafunction to define a \c avl_set_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, class O4 = void>
38 struct make_avl_set_base_hook
41 typedef typename pack_options
42 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
43 <hook_defaults, O1, O2, O3, O4>
45 <hook_defaults, Options...>
47 ::type packed_options;
51 , avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size>
52 , typename packed_options::tag
53 , packed_options::link_mode
55 > implementation_defined;
57 typedef implementation_defined type;
60 //! Derive a class from avl_set_base_hook in order to store objects in
61 //! in an avl_set/avl_multiset. avl_set_base_hook holds the data necessary to maintain
62 //! the avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_multiset.
64 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
65 //! \c link_mode<> and \c optimize_size<>.
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 list_base_hook, then each \c list_base_hook needs its
72 //! \c void_pointer<> is the pointer type that will be used internally in the hook
73 //! and the container configured to use this hook.
75 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
76 //! \c auto_unlink or \c safe_link).
78 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
80 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
81 template<class ...Options>
83 template<class O1, class O2, class O3, class O4>
85 class avl_set_base_hook
86 : public make_avl_set_base_hook
87 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
94 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
96 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
97 //! initializes the node to an unlinked state.
99 //! <b>Throws</b>: Nothing.
102 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
103 //! initializes the node to an unlinked state. The argument is ignored.
105 //! <b>Throws</b>: Nothing.
107 //! <b>Rationale</b>: Providing a copy-constructor
108 //! makes classes using the hook STL-compliant without forcing the
109 //! user to do some additional work. \c swap can be used to emulate
111 avl_set_base_hook(const avl_set_base_hook& );
113 //! <b>Effects</b>: Empty function. The argument is ignored.
115 //! <b>Throws</b>: Nothing.
117 //! <b>Rationale</b>: Providing an assignment operator
118 //! makes classes using the hook STL-compliant without forcing the
119 //! user to do some additional work. \c swap can be used to emulate
121 avl_set_base_hook& operator=(const avl_set_base_hook& );
123 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
124 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
125 //! object is stored in a set an assertion is raised. If link_mode is
126 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
128 //! <b>Throws</b>: Nothing.
129 ~avl_set_base_hook();
131 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
132 //! related to those nodes in one or two containers. That is, if the node
133 //! this is part of the element e1, the node x is part of the element e2
134 //! and both elements are included in the containers s1 and s2, then after
135 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
136 //! at the position of e1. If one element is not in a container, then
137 //! after the swap-operation the other element is not in a container.
138 //! Iterators to e1 and e2 related to those nodes are invalidated.
140 //! <b>Complexity</b>: Constant
142 //! <b>Throws</b>: Nothing.
143 void swap_nodes(avl_set_base_hook &other);
145 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
147 //! <b>Returns</b>: true, if the node belongs to a container, false
148 //! otherwise. This function can be used to test whether \c set::iterator_to
149 //! will return a valid iterator.
151 //! <b>Complexity</b>: Constant
152 bool is_linked() const;
154 //! <b>Effects</b>: Removes the node if it's inserted in a container.
155 //! This function is only allowed if link_mode is \c auto_unlink.
157 //! <b>Throws</b>: Nothing.
162 //! Helper metafunction to define a \c avl_set_member_hook that yields to the same
163 //! type when the same options (either explicitly or implicitly) are used.
164 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
165 template<class ...Options>
167 template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
169 struct make_avl_set_member_hook
172 typedef typename pack_options
173 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
174 <hook_defaults, O1, O2, O3, O4>
176 <hook_defaults, Options...>
178 ::type packed_options;
182 , avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size>
184 , packed_options::link_mode
186 > implementation_defined;
188 typedef implementation_defined type;
191 //! Put a public data member avl_set_member_hook in order to store objects of this class in
192 //! an avl_set/avl_multiset. avl_set_member_hook holds the data necessary for maintaining the
193 //! avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_multiset.
195 //! The hook admits the following options: \c void_pointer<>,
196 //! \c link_mode<> and \c optimize_size<>.
198 //! \c void_pointer<> is the pointer type that will be used internally in the hook
199 //! and the container configured to use this hook.
201 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
202 //! \c auto_unlink or \c safe_link).
204 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
206 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
207 template<class ...Options>
209 template<class O1, class O2, class O3, class O4>
211 class avl_set_member_hook
212 : public make_avl_set_member_hook
213 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
220 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
222 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
223 //! initializes the node to an unlinked state.
225 //! <b>Throws</b>: Nothing.
226 avl_set_member_hook();
228 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
229 //! initializes the node to an unlinked state. The argument is ignored.
231 //! <b>Throws</b>: Nothing.
233 //! <b>Rationale</b>: Providing a copy-constructor
234 //! makes classes using the hook STL-compliant without forcing the
235 //! user to do some additional work. \c swap can be used to emulate
237 avl_set_member_hook(const avl_set_member_hook& );
239 //! <b>Effects</b>: Empty function. The argument is ignored.
241 //! <b>Throws</b>: Nothing.
243 //! <b>Rationale</b>: Providing an assignment operator
244 //! makes classes using the hook STL-compliant without forcing the
245 //! user to do some additional work. \c swap can be used to emulate
247 avl_set_member_hook& operator=(const avl_set_member_hook& );
249 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
250 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
251 //! object is stored in a set an assertion is raised. If link_mode is
252 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
254 //! <b>Throws</b>: Nothing.
255 ~avl_set_member_hook();
257 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
258 //! related to those nodes in one or two containers. That is, if the node
259 //! this is part of the element e1, the node x is part of the element e2
260 //! and both elements are included in the containers s1 and s2, then after
261 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
262 //! at the position of e1. If one element is not in a container, then
263 //! after the swap-operation the other element is not in a container.
264 //! Iterators to e1 and e2 related to those nodes are invalidated.
266 //! <b>Complexity</b>: Constant
268 //! <b>Throws</b>: Nothing.
269 void swap_nodes(avl_set_member_hook &other);
271 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
273 //! <b>Returns</b>: true, if the node belongs to a container, false
274 //! otherwise. This function can be used to test whether \c set::iterator_to
275 //! will return a valid iterator.
277 //! <b>Complexity</b>: Constant
278 bool is_linked() const;
280 //! <b>Effects</b>: Removes the node if it's inserted in a container.
281 //! This function is only allowed if link_mode is \c auto_unlink.
283 //! <b>Throws</b>: Nothing.
288 } //namespace intrusive
291 #include <boost/intrusive/detail/config_end.hpp>
293 #endif //BOOST_INTRUSIVE_AVL_SET_HOOK_HPP