Chris@16
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2007-2013
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@16
|
10 //
|
Chris@16
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_INTRUSIVE_AVL_SET_HOOK_HPP
|
Chris@16
|
14 #define BOOST_INTRUSIVE_AVL_SET_HOOK_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/intrusive/detail/config_begin.hpp>
|
Chris@16
|
17 #include <boost/intrusive/intrusive_fwd.hpp>
|
Chris@101
|
18
|
Chris@16
|
19 #include <boost/intrusive/detail/avltree_node.hpp>
|
Chris@16
|
20 #include <boost/intrusive/avltree_algorithms.hpp>
|
Chris@16
|
21 #include <boost/intrusive/options.hpp>
|
Chris@16
|
22 #include <boost/intrusive/detail/generic_hook.hpp>
|
Chris@16
|
23
|
Chris@101
|
24 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
25 # pragma once
|
Chris@101
|
26 #endif
|
Chris@101
|
27
|
Chris@16
|
28 namespace boost {
|
Chris@16
|
29 namespace intrusive {
|
Chris@16
|
30
|
Chris@16
|
31 //! Helper metafunction to define a \c avl_set_base_hook that yields to the same
|
Chris@16
|
32 //! type when the same options (either explicitly or implicitly) are used.
|
Chris@16
|
33 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
34 template<class ...Options>
|
Chris@16
|
35 #else
|
Chris@16
|
36 template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
|
Chris@16
|
37 #endif
|
Chris@16
|
38 struct make_avl_set_base_hook
|
Chris@16
|
39 {
|
Chris@16
|
40 /// @cond
|
Chris@16
|
41 typedef typename pack_options
|
Chris@16
|
42 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
43 <hook_defaults, O1, O2, O3, O4>
|
Chris@16
|
44 #else
|
Chris@16
|
45 <hook_defaults, Options...>
|
Chris@16
|
46 #endif
|
Chris@16
|
47 ::type packed_options;
|
Chris@16
|
48
|
Chris@16
|
49 typedef generic_hook
|
Chris@101
|
50 < avltree_algorithms<avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> >
|
Chris@16
|
51 , typename packed_options::tag
|
Chris@16
|
52 , packed_options::link_mode
|
Chris@16
|
53 , AvlTreeBaseHookId
|
Chris@16
|
54 > implementation_defined;
|
Chris@16
|
55 /// @endcond
|
Chris@16
|
56 typedef implementation_defined type;
|
Chris@16
|
57 };
|
Chris@16
|
58
|
Chris@16
|
59 //! Derive a class from avl_set_base_hook in order to store objects in
|
Chris@16
|
60 //! in an avl_set/avl_multiset. avl_set_base_hook holds the data necessary to maintain
|
Chris@16
|
61 //! the avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_multiset.
|
Chris@16
|
62 //!
|
Chris@16
|
63 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
|
Chris@16
|
64 //! \c link_mode<> and \c optimize_size<>.
|
Chris@16
|
65 //!
|
Chris@16
|
66 //! \c tag<> defines a tag to identify the node.
|
Chris@16
|
67 //! The same tag value can be used in different classes, but if a class is
|
Chris@16
|
68 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
|
Chris@16
|
69 //! unique tag.
|
Chris@16
|
70 //!
|
Chris@16
|
71 //! \c void_pointer<> is the pointer type that will be used internally in the hook
|
Chris@101
|
72 //! and the container configured to use this hook.
|
Chris@16
|
73 //!
|
Chris@16
|
74 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
|
Chris@16
|
75 //! \c auto_unlink or \c safe_link).
|
Chris@16
|
76 //!
|
Chris@16
|
77 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
|
Chris@16
|
78 //! of speed.
|
Chris@16
|
79 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
80 template<class ...Options>
|
Chris@16
|
81 #else
|
Chris@16
|
82 template<class O1, class O2, class O3, class O4>
|
Chris@16
|
83 #endif
|
Chris@16
|
84 class avl_set_base_hook
|
Chris@16
|
85 : public make_avl_set_base_hook
|
Chris@16
|
86 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
87 <O1, O2, O3, O4>
|
Chris@16
|
88 #else
|
Chris@16
|
89 <Options...>
|
Chris@16
|
90 #endif
|
Chris@16
|
91 ::type
|
Chris@16
|
92 {
|
Chris@16
|
93 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
94 public:
|
Chris@16
|
95 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
|
Chris@16
|
96 //! initializes the node to an unlinked state.
|
Chris@16
|
97 //!
|
Chris@16
|
98 //! <b>Throws</b>: Nothing.
|
Chris@16
|
99 avl_set_base_hook();
|
Chris@16
|
100
|
Chris@16
|
101 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
|
Chris@16
|
102 //! initializes the node to an unlinked state. The argument is ignored.
|
Chris@16
|
103 //!
|
Chris@16
|
104 //! <b>Throws</b>: Nothing.
|
Chris@16
|
105 //!
|
Chris@16
|
106 //! <b>Rationale</b>: Providing a copy-constructor
|
Chris@16
|
107 //! makes classes using the hook STL-compliant without forcing the
|
Chris@16
|
108 //! user to do some additional work. \c swap can be used to emulate
|
Chris@16
|
109 //! move-semantics.
|
Chris@16
|
110 avl_set_base_hook(const avl_set_base_hook& );
|
Chris@16
|
111
|
Chris@16
|
112 //! <b>Effects</b>: Empty function. The argument is ignored.
|
Chris@16
|
113 //!
|
Chris@16
|
114 //! <b>Throws</b>: Nothing.
|
Chris@16
|
115 //!
|
Chris@16
|
116 //! <b>Rationale</b>: Providing an assignment operator
|
Chris@16
|
117 //! makes classes using the hook STL-compliant without forcing the
|
Chris@16
|
118 //! user to do some additional work. \c swap can be used to emulate
|
Chris@16
|
119 //! move-semantics.
|
Chris@16
|
120 avl_set_base_hook& operator=(const avl_set_base_hook& );
|
Chris@16
|
121
|
Chris@16
|
122 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
|
Chris@16
|
123 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
|
Chris@16
|
124 //! object is stored in a set an assertion is raised. If link_mode is
|
Chris@16
|
125 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
|
Chris@16
|
126 //!
|
Chris@16
|
127 //! <b>Throws</b>: Nothing.
|
Chris@16
|
128 ~avl_set_base_hook();
|
Chris@16
|
129
|
Chris@16
|
130 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
|
Chris@16
|
131 //! related to those nodes in one or two containers. That is, if the node
|
Chris@16
|
132 //! this is part of the element e1, the node x is part of the element e2
|
Chris@16
|
133 //! and both elements are included in the containers s1 and s2, then after
|
Chris@16
|
134 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
|
Chris@16
|
135 //! at the position of e1. If one element is not in a container, then
|
Chris@16
|
136 //! after the swap-operation the other element is not in a container.
|
Chris@16
|
137 //! Iterators to e1 and e2 related to those nodes are invalidated.
|
Chris@16
|
138 //!
|
Chris@16
|
139 //! <b>Complexity</b>: Constant
|
Chris@16
|
140 //!
|
Chris@16
|
141 //! <b>Throws</b>: Nothing.
|
Chris@16
|
142 void swap_nodes(avl_set_base_hook &other);
|
Chris@16
|
143
|
Chris@16
|
144 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
|
Chris@16
|
145 //!
|
Chris@16
|
146 //! <b>Returns</b>: true, if the node belongs to a container, false
|
Chris@16
|
147 //! otherwise. This function can be used to test whether \c set::iterator_to
|
Chris@16
|
148 //! will return a valid iterator.
|
Chris@16
|
149 //!
|
Chris@16
|
150 //! <b>Complexity</b>: Constant
|
Chris@16
|
151 bool is_linked() const;
|
Chris@16
|
152
|
Chris@16
|
153 //! <b>Effects</b>: Removes the node if it's inserted in a container.
|
Chris@16
|
154 //! This function is only allowed if link_mode is \c auto_unlink.
|
Chris@16
|
155 //!
|
Chris@16
|
156 //! <b>Throws</b>: Nothing.
|
Chris@16
|
157 void unlink();
|
Chris@16
|
158 #endif
|
Chris@16
|
159 };
|
Chris@16
|
160
|
Chris@16
|
161 //! Helper metafunction to define a \c avl_set_member_hook that yields to the same
|
Chris@16
|
162 //! type when the same options (either explicitly or implicitly) are used.
|
Chris@16
|
163 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
164 template<class ...Options>
|
Chris@16
|
165 #else
|
Chris@16
|
166 template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
|
Chris@16
|
167 #endif
|
Chris@16
|
168 struct make_avl_set_member_hook
|
Chris@16
|
169 {
|
Chris@16
|
170 /// @cond
|
Chris@16
|
171 typedef typename pack_options
|
Chris@16
|
172 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
173 <hook_defaults, O1, O2, O3, O4>
|
Chris@16
|
174 #else
|
Chris@16
|
175 <hook_defaults, Options...>
|
Chris@16
|
176 #endif
|
Chris@16
|
177 ::type packed_options;
|
Chris@16
|
178
|
Chris@16
|
179 typedef generic_hook
|
Chris@101
|
180 < avltree_algorithms<avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> >
|
Chris@16
|
181 , member_tag
|
Chris@16
|
182 , packed_options::link_mode
|
Chris@16
|
183 , NoBaseHookId
|
Chris@16
|
184 > implementation_defined;
|
Chris@16
|
185 /// @endcond
|
Chris@16
|
186 typedef implementation_defined type;
|
Chris@16
|
187 };
|
Chris@16
|
188
|
Chris@16
|
189 //! Put a public data member avl_set_member_hook in order to store objects of this class in
|
Chris@16
|
190 //! an avl_set/avl_multiset. avl_set_member_hook holds the data necessary for maintaining the
|
Chris@16
|
191 //! avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_multiset.
|
Chris@16
|
192 //!
|
Chris@16
|
193 //! The hook admits the following options: \c void_pointer<>,
|
Chris@16
|
194 //! \c link_mode<> and \c optimize_size<>.
|
Chris@16
|
195 //!
|
Chris@16
|
196 //! \c void_pointer<> is the pointer type that will be used internally in the hook
|
Chris@101
|
197 //! and the container configured to use this hook.
|
Chris@16
|
198 //!
|
Chris@16
|
199 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
|
Chris@16
|
200 //! \c auto_unlink or \c safe_link).
|
Chris@16
|
201 //!
|
Chris@16
|
202 //! \c optimize_size<> will tell the hook to optimize the hook for size instead
|
Chris@16
|
203 //! of speed.
|
Chris@16
|
204 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
205 template<class ...Options>
|
Chris@16
|
206 #else
|
Chris@16
|
207 template<class O1, class O2, class O3, class O4>
|
Chris@16
|
208 #endif
|
Chris@16
|
209 class avl_set_member_hook
|
Chris@16
|
210 : public make_avl_set_member_hook
|
Chris@16
|
211 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
212 <O1, O2, O3, O4>
|
Chris@16
|
213 #else
|
Chris@16
|
214 <Options...>
|
Chris@16
|
215 #endif
|
Chris@16
|
216 ::type
|
Chris@16
|
217 {
|
Chris@16
|
218 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
219 public:
|
Chris@16
|
220 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
|
Chris@16
|
221 //! initializes the node to an unlinked state.
|
Chris@16
|
222 //!
|
Chris@16
|
223 //! <b>Throws</b>: Nothing.
|
Chris@16
|
224 avl_set_member_hook();
|
Chris@16
|
225
|
Chris@16
|
226 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
|
Chris@16
|
227 //! initializes the node to an unlinked state. The argument is ignored.
|
Chris@16
|
228 //!
|
Chris@16
|
229 //! <b>Throws</b>: Nothing.
|
Chris@16
|
230 //!
|
Chris@16
|
231 //! <b>Rationale</b>: Providing a copy-constructor
|
Chris@16
|
232 //! makes classes using the hook STL-compliant without forcing the
|
Chris@16
|
233 //! user to do some additional work. \c swap can be used to emulate
|
Chris@16
|
234 //! move-semantics.
|
Chris@16
|
235 avl_set_member_hook(const avl_set_member_hook& );
|
Chris@16
|
236
|
Chris@16
|
237 //! <b>Effects</b>: Empty function. The argument is ignored.
|
Chris@16
|
238 //!
|
Chris@16
|
239 //! <b>Throws</b>: Nothing.
|
Chris@16
|
240 //!
|
Chris@16
|
241 //! <b>Rationale</b>: Providing an assignment operator
|
Chris@16
|
242 //! makes classes using the hook STL-compliant without forcing the
|
Chris@16
|
243 //! user to do some additional work. \c swap can be used to emulate
|
Chris@16
|
244 //! move-semantics.
|
Chris@16
|
245 avl_set_member_hook& operator=(const avl_set_member_hook& );
|
Chris@16
|
246
|
Chris@16
|
247 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
|
Chris@16
|
248 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
|
Chris@16
|
249 //! object is stored in a set an assertion is raised. If link_mode is
|
Chris@16
|
250 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
|
Chris@16
|
251 //!
|
Chris@16
|
252 //! <b>Throws</b>: Nothing.
|
Chris@16
|
253 ~avl_set_member_hook();
|
Chris@16
|
254
|
Chris@16
|
255 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
|
Chris@16
|
256 //! related to those nodes in one or two containers. That is, if the node
|
Chris@16
|
257 //! this is part of the element e1, the node x is part of the element e2
|
Chris@16
|
258 //! and both elements are included in the containers s1 and s2, then after
|
Chris@16
|
259 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
|
Chris@16
|
260 //! at the position of e1. If one element is not in a container, then
|
Chris@16
|
261 //! after the swap-operation the other element is not in a container.
|
Chris@16
|
262 //! Iterators to e1 and e2 related to those nodes are invalidated.
|
Chris@16
|
263 //!
|
Chris@16
|
264 //! <b>Complexity</b>: Constant
|
Chris@16
|
265 //!
|
Chris@16
|
266 //! <b>Throws</b>: Nothing.
|
Chris@16
|
267 void swap_nodes(avl_set_member_hook &other);
|
Chris@16
|
268
|
Chris@16
|
269 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
|
Chris@16
|
270 //!
|
Chris@16
|
271 //! <b>Returns</b>: true, if the node belongs to a container, false
|
Chris@16
|
272 //! otherwise. This function can be used to test whether \c set::iterator_to
|
Chris@16
|
273 //! will return a valid iterator.
|
Chris@16
|
274 //!
|
Chris@16
|
275 //! <b>Complexity</b>: Constant
|
Chris@16
|
276 bool is_linked() const;
|
Chris@16
|
277
|
Chris@16
|
278 //! <b>Effects</b>: Removes the node if it's inserted in a container.
|
Chris@16
|
279 //! This function is only allowed if link_mode is \c auto_unlink.
|
Chris@16
|
280 //!
|
Chris@16
|
281 //! <b>Throws</b>: Nothing.
|
Chris@16
|
282 void unlink();
|
Chris@16
|
283 #endif
|
Chris@16
|
284 };
|
Chris@16
|
285
|
Chris@16
|
286 } //namespace intrusive
|
Chris@16
|
287 } //namespace boost
|
Chris@16
|
288
|
Chris@16
|
289 #include <boost/intrusive/detail/config_end.hpp>
|
Chris@16
|
290
|
Chris@16
|
291 #endif //BOOST_INTRUSIVE_AVL_SET_HOOK_HPP
|