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_SLIST_HOOK_HPP
15#define BOOST_INTRUSIVE_SLIST_HOOK_HPP
16
17#include <boost/intrusive/detail/config_begin.hpp>
18#include <boost/intrusive/intrusive_fwd.hpp>
19
20#include <boost/intrusive/detail/slist_node.hpp>
21#include <boost/intrusive/circular_slist_algorithms.hpp>
22#include <boost/intrusive/link_mode.hpp>
23#include <boost/intrusive/options.hpp>
24#include <boost/intrusive/detail/generic_hook.hpp>
25
26#if defined(BOOST_HAS_PRAGMA_ONCE)
27# pragma once
28#endif
29
30namespace boost {
31namespace intrusive {
32
33//! Helper metafunction to define a \c slist_base_hook that yields to the same
34//! type when the same options (either explicitly or implicitly) are used.
35#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
36template<class ...Options>
37#else
38template<class O1 = void, class O2 = void, class O3 = void>
39#endif
40struct make_slist_base_hook
41{
42 /// @cond
43 typedef typename pack_options
44 < hook_defaults,
45 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
46 O1, O2, O3
47 #else
48 Options...
49 #endif
50 >::type packed_options;
51
52 typedef generic_hook
53 < CircularSListAlgorithms
54 , slist_node_traits<typename packed_options::void_pointer>
55 , typename packed_options::tag
56 , packed_options::link_mode
57 , SlistBaseHookId
58 > implementation_defined;
59 /// @endcond
60 typedef implementation_defined type;
61};
62
63//! Derive a class from slist_base_hook in order to store objects in
64//! in an list. slist_base_hook holds the data necessary to maintain the
65//! list and provides an appropriate value_traits class for list.
66//!
67//! The hook admits the following options: \c tag<>, \c void_pointer<> and
68//! \c link_mode<>.
69//!
70//! \c tag<> defines a tag to identify the node.
71//! The same tag value can be used in different classes, but if a class is
72//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
73//! unique tag.
74//!
75//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
76//! \c auto_unlink or \c safe_link).
77//!
78//! \c void_pointer<> is the pointer type that will be used internally in the hook
79//! and the container configured to use this hook.
80#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
81template<class ...Options>
82#else
83template<class O1, class O2, class O3>
84#endif
85class slist_base_hook
86 : public make_slist_base_hook<
87 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
88 O1, O2, O3
89 #else
90 Options...
91 #endif
92 >::type
93{
94 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
95 public:
96 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
97 //! initializes the node to an unlinked state.
98 //!
99 //! <b>Throws</b>: Nothing.
100 slist_base_hook() BOOST_NOEXCEPT;
101
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.
104 //!
105 //! <b>Throws</b>: Nothing.
106 //!
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
110 //! move-semantics.
111 slist_base_hook(const slist_base_hook& ) BOOST_NOEXCEPT;
112
113 //! <b>Effects</b>: Empty function. The argument is ignored.
114 //!
115 //! <b>Throws</b>: Nothing.
116 //!
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
120 //! move-semantics.
121 slist_base_hook& operator=(const slist_base_hook& ) BOOST_NOEXCEPT;
122
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 an slist an assertion is raised. If link_mode is
126 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
127 //!
128 //! <b>Throws</b>: Nothing.
129 ~slist_base_hook();
130
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.
139 //!
140 //! <b>Complexity</b>: Constant
141 //!
142 //! <b>Throws</b>: Nothing.
143 void swap_nodes(slist_base_hook &other) BOOST_NOEXCEPT;
144
145 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
146 //!
147 //! <b>Returns</b>: true, if the node belongs to a container, false
148 //! otherwise. This function can be used to test whether \c slist::iterator_to
149 //! will return a valid iterator.
150 //!
151 //! <b>Throws</b>: Nothing.
152 //!
153 //! <b>Complexity</b>: Constant
154 bool is_linked() const BOOST_NOEXCEPT;
155
156 //! <b>Effects</b>: Removes the node if it's inserted in a container.
157 //! This function is only allowed if link_mode is \c auto_unlink.
158 //!
159 //! <b>Throws</b>: Nothing.
160 void unlink() BOOST_NOEXCEPT;
161 #endif
162};
163
164//! Helper metafunction to define a \c slist_member_hook that yields to the same
165//! type when the same options (either explicitly or implicitly) are used.
166#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
167template<class ...Options>
168#else
169template<class O1 = void, class O2 = void, class O3 = void>
170#endif
171struct make_slist_member_hook
172{
173 /// @cond
174 typedef typename pack_options
175 < hook_defaults,
176 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
177 O1, O2, O3
178 #else
179 Options...
180 #endif
181 >::type packed_options;
182
183 typedef generic_hook
184 < CircularSListAlgorithms
185 , slist_node_traits<typename packed_options::void_pointer>
186 , member_tag
187 , packed_options::link_mode
188 , NoBaseHookId
189 > implementation_defined;
190 /// @endcond
191 typedef implementation_defined type;
192};
193
194//! Put a public data member slist_member_hook in order to store objects of this class in
195//! an list. slist_member_hook holds the data necessary for maintaining the list and
196//! provides an appropriate value_traits class for list.
197//!
198//! The hook admits the following options: \c void_pointer<> and
199//! \c link_mode<>.
200//!
201//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
202//! \c auto_unlink or \c safe_link).
203//!
204//! \c void_pointer<> is the pointer type that will be used internally in the hook
205//! and the container configured to use this hook.
206#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
207template<class ...Options>
208#else
209template<class O1, class O2, class O3>
210#endif
211class slist_member_hook
212 : public make_slist_member_hook<
213 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
214 O1, O2, O3
215 #else
216 Options...
217 #endif
218 >::type
219{
220 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
221 public:
222 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
223 //! initializes the node to an unlinked state.
224 //!
225 //! <b>Throws</b>: Nothing.
226 slist_member_hook();
227
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.
230 //!
231 //! <b>Throws</b>: Nothing.
232 //!
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
236 //! move-semantics.
237 slist_member_hook(const slist_member_hook& );
238
239 //! <b>Effects</b>: Empty function. The argument is ignored.
240 //!
241 //! <b>Throws</b>: Nothing.
242 //!
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
246 //! move-semantics.
247 slist_member_hook& operator=(const slist_member_hook& );
248
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 an slist an assertion is raised. If link_mode is
252 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
253 //!
254 //! <b>Throws</b>: Nothing.
255 ~slist_member_hook();
256
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.
265 //!
266 //! <b>Complexity</b>: Constant
267 //!
268 //! <b>Throws</b>: Nothing.
269 void swap_nodes(slist_member_hook &other);
270
271 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
272 //!
273 //! <b>Returns</b>: true, if the node belongs to a container, false
274 //! otherwise. This function can be used to test whether \c slist::iterator_to
275 //! will return a valid iterator.
276 //!
277 //! <b>Note</b>: If this member is called when the value is inserted in a
278 //! slist with the option linear<true>, this function will return "false"
279 //! for the last element, as it is not linked to anything (the next element is null),
280 //! so use with care.
281 //!
282 //! <b>Complexity</b>: Constant
283 bool is_linked() const;
284
285 //! <b>Effects</b>: Removes the node if it's inserted in a container.
286 //! This function is only allowed if link_mode is \c auto_unlink.
287 //!
288 //! <b>Throws</b>: Nothing.
289 void unlink();
290 #endif
291};
292
293} //namespace intrusive
294} //namespace boost
295
296#include <boost/intrusive/detail/config_end.hpp>
297
298#endif //BOOST_INTRUSIVE_SLIST_HOOK_HPP
299

source code of boost/libs/intrusive/include/boost/intrusive/slist_hook.hpp