comparison DEPENDENCIES/generic/include/boost/intrusive/set_hook.hpp @ 16:2665513ce2d3

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