1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2013
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)
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef BOOST_INTRUSIVE_SLIST_HOOK_HPP
15 #define BOOST_INTRUSIVE_SLIST_HOOK_HPP
17 #include <boost/intrusive/detail/config_begin.hpp>
18 #include <boost/intrusive/intrusive_fwd.hpp>
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>
26 #if defined(BOOST_HAS_PRAGMA_ONCE)
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)
36 template<class ...Options>
38 template<class O1 = void, class O2 = void, class O3 = void>
40 struct make_slist_base_hook
43 typedef typename pack_options
45 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
50 >::type packed_options;
53 < CircularSListAlgorithms
54 , slist_node_traits<typename packed_options::void_pointer>
55 , typename packed_options::tag
56 , packed_options::link_mode
58 > implementation_defined;
60 typedef implementation_defined type;
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.
67 //! The hook admits the following options: \c tag<>, \c void_pointer<> and
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
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 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)
81 template<class ...Options>
83 template<class O1, class O2, class O3>
86 : public make_slist_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 slist_base_hook(const slist_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 slist_base_hook& operator=(const slist_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 an slist 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.
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(slist_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 slist::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 slist_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>
169 struct make_slist_member_hook
172 typedef typename pack_options
174 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
179 >::type packed_options;
182 < CircularSListAlgorithms
183 , slist_node_traits<typename packed_options::void_pointer>
185 , packed_options::link_mode
187 > implementation_defined;
189 typedef implementation_defined type;
192 //! Put a public data member slist_member_hook in order to store objects of this class in
193 //! an list. slist_member_hook holds the data necessary for maintaining the list and
194 //! provides an appropriate value_traits class for list.
196 //! The hook admits the following options: \c void_pointer<> and
199 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
200 //! \c auto_unlink or \c safe_link).
202 //! \c void_pointer<> is the pointer type that will be used internally in the hook
203 //! and the container configured to use this hook.
204 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
205 template<class ...Options>
207 template<class O1, class O2, class O3>
209 class slist_member_hook
210 : public make_slist_member_hook<
211 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
218 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
220 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
221 //! initializes the node to an unlinked state.
223 //! <b>Throws</b>: Nothing.
226 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
227 //! initializes the node to an unlinked state. The argument is ignored.
229 //! <b>Throws</b>: Nothing.
231 //! <b>Rationale</b>: Providing a copy-constructor
232 //! makes classes using the hook STL-compliant without forcing the
233 //! user to do some additional work. \c swap can be used to emulate
235 slist_member_hook(const slist_member_hook& );
237 //! <b>Effects</b>: Empty function. The argument is ignored.
239 //! <b>Throws</b>: Nothing.
241 //! <b>Rationale</b>: Providing an assignment operator
242 //! makes classes using the hook STL-compliant without forcing the
243 //! user to do some additional work. \c swap can be used to emulate
245 slist_member_hook& operator=(const slist_member_hook& );
247 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
248 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
249 //! object is stored in an slist an assertion is raised. If link_mode is
250 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
252 //! <b>Throws</b>: Nothing.
253 ~slist_member_hook();
255 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
256 //! related to those nodes in one or two containers. That is, if the node
257 //! this is part of the element e1, the node x is part of the element e2
258 //! and both elements are included in the containers s1 and s2, then after
259 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
260 //! at the position of e1. If one element is not in a container, then
261 //! after the swap-operation the other element is not in a container.
262 //! Iterators to e1 and e2 related to those nodes are invalidated.
264 //! <b>Complexity</b>: Constant
266 //! <b>Throws</b>: Nothing.
267 void swap_nodes(slist_member_hook &other);
269 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
271 //! <b>Returns</b>: true, if the node belongs to a container, false
272 //! otherwise. This function can be used to test whether \c slist::iterator_to
273 //! will return a valid iterator.
275 //! <b>Note</b>: If this member is called when the value is inserted in a
276 //! slist with the option linear<true>, this function will return "false"
277 //! for the last element, as it is not linked to anything (the next element is null),
278 //! so use with care.
280 //! <b>Complexity</b>: Constant
281 bool is_linked() const;
283 //! <b>Effects</b>: Removes the node if it's inserted in a container.
284 //! This function is only allowed if link_mode is \c auto_unlink.
286 //! <b>Throws</b>: Nothing.
291 } //namespace intrusive
294 #include <boost/intrusive/detail/config_end.hpp>
296 #endif //BOOST_INTRUSIVE_SLIST_HOOK_HPP