1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2008
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>
19 #include <boost/intrusive/detail/utilities.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>
30 template<class VoidPointer
>
31 struct get_slist_node_algo
33 typedef circular_slist_algorithms
<slist_node_traits
<VoidPointer
> > type
;
38 //! Helper metafunction to define a \c slist_base_hook that yields to the same
39 //! type when the same options (either explicitly or implicitly) are used.
40 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
41 template<class ...Options
>
43 template<class O1
= none
, class O2
= none
, class O3
= none
>
45 struct make_slist_base_hook
48 typedef typename pack_options
50 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
55 >::type packed_options
;
57 typedef detail::generic_hook
58 < get_slist_node_algo
<typename
packed_options::void_pointer
>
59 , typename
packed_options::tag
60 , packed_options::link_mode
61 , detail::SlistBaseHook
62 > implementation_defined
;
64 typedef implementation_defined type
;
67 //! Derive a class from slist_base_hook in order to store objects in
68 //! in an list. slist_base_hook holds the data necessary to maintain the
69 //! list and provides an appropriate value_traits class for list.
71 //! The hook admits the following options: \c tag<>, \c void_pointer<> and
74 //! \c tag<> defines a tag to identify the node.
75 //! The same tag value can be used in different classes, but if a class is
76 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
79 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
80 //! \c auto_unlink or \c safe_link).
82 //! \c void_pointer<> is the pointer type that will be used internally in the hook
83 //! and the the container configured to use this hook.
84 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
85 template<class ...Options
>
87 template<class O1
, class O2
, class O3
>
90 : public make_slist_base_hook
<
91 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
98 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
99 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
100 //! initializes the node to an unlinked state.
102 //! <b>Throws</b>: Nothing.
105 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
106 //! initializes the node to an unlinked state. The argument is ignored.
108 //! <b>Throws</b>: Nothing.
110 //! <b>Rationale</b>: Providing a copy-constructor
111 //! makes classes using the hook STL-compliant without forcing the
112 //! user to do some additional work. \c swap can be used to emulate
114 slist_base_hook(const slist_base_hook
& );
116 //! <b>Effects</b>: Empty function. The argument is ignored.
118 //! <b>Throws</b>: Nothing.
120 //! <b>Rationale</b>: Providing an assignment operator
121 //! makes classes using the hook STL-compliant without forcing the
122 //! user to do some additional work. \c swap can be used to emulate
124 slist_base_hook
& operator=(const slist_base_hook
& );
126 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
127 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
128 //! object is stored in an slist an assertion is raised. If link_mode is
129 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
131 //! <b>Throws</b>: Nothing.
134 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
135 //! related to those nodes in one or two containers. That is, if the node
136 //! this is part of the element e1, the node x is part of the element e2
137 //! and both elements are included in the containers s1 and s2, then after
138 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
139 //! at the position of e1. If one element is not in a container, then
140 //! after the swap-operation the other element is not in a container.
141 //! Iterators to e1 and e2 related to those nodes are invalidated.
143 //! <b>Complexity</b>: Constant
145 //! <b>Throws</b>: Nothing.
146 void swap_nodes(slist_base_hook
&other
);
148 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
150 //! <b>Returns</b>: true, if the node belongs to a container, false
151 //! otherwise. This function can be used to test whether \c slist::iterator_to
152 //! will return a valid iterator.
154 //! <b>Complexity</b>: Constant
155 bool is_linked() const;
157 //! <b>Effects</b>: Removes the node if it's inserted in a container.
158 //! This function is only allowed if link_mode is \c auto_unlink.
160 //! <b>Throws</b>: Nothing.
165 //! Helper metafunction to define a \c slist_member_hook that yields to the same
166 //! type when the same options (either explicitly or implicitly) are used.
167 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
168 template<class ...Options
>
170 template<class O1
= none
, class O2
= none
, class O3
= none
>
172 struct make_slist_member_hook
175 typedef typename pack_options
177 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
182 >::type packed_options
;
184 typedef detail::generic_hook
185 < get_slist_node_algo
<typename
packed_options::void_pointer
>
187 , packed_options::link_mode
189 > implementation_defined
;
191 typedef implementation_defined type
;
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.
198 //! The hook admits the following options: \c void_pointer<> and
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 void_pointer<> is the pointer type that will be used internally in the hook
205 //! and the the container configured to use this hook.
206 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
207 template<class ...Options
>
209 template<class O1
, class O2
, class O3
>
211 class slist_member_hook
212 : public make_slist_member_hook
<
213 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
220 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
221 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
222 //! initializes the node to an unlinked state.
224 //! <b>Throws</b>: Nothing.
227 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
228 //! initializes the node to an unlinked state. The argument is ignored.
230 //! <b>Throws</b>: Nothing.
232 //! <b>Rationale</b>: Providing a copy-constructor
233 //! makes classes using the hook STL-compliant without forcing the
234 //! user to do some additional work. \c swap can be used to emulate
236 slist_member_hook(const slist_member_hook
& );
238 //! <b>Effects</b>: Empty function. The argument is ignored.
240 //! <b>Throws</b>: Nothing.
242 //! <b>Rationale</b>: Providing an assignment operator
243 //! makes classes using the hook STL-compliant without forcing the
244 //! user to do some additional work. \c swap can be used to emulate
246 slist_member_hook
& operator=(const slist_member_hook
& );
248 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
249 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
250 //! object is stored in an slist an assertion is raised. If link_mode is
251 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
253 //! <b>Throws</b>: Nothing.
254 ~slist_member_hook();
256 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
257 //! related to those nodes in one or two containers. That is, if the node
258 //! this is part of the element e1, the node x is part of the element e2
259 //! and both elements are included in the containers s1 and s2, then after
260 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
261 //! at the position of e1. If one element is not in a container, then
262 //! after the swap-operation the other element is not in a container.
263 //! Iterators to e1 and e2 related to those nodes are invalidated.
265 //! <b>Complexity</b>: Constant
267 //! <b>Throws</b>: Nothing.
268 void swap_nodes(slist_member_hook
&other
);
270 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
272 //! <b>Returns</b>: true, if the node belongs to a container, false
273 //! otherwise. This function can be used to test whether \c slist::iterator_to
274 //! will return a valid iterator.
276 //! <b>Complexity</b>: Constant
277 bool is_linked() const;
279 //! <b>Effects</b>: Removes the node if it's inserted in a container.
280 //! This function is only allowed if link_mode is \c auto_unlink.
282 //! <b>Throws</b>: Nothing.
287 } //namespace intrusive
290 #include <boost/intrusive/detail/config_end.hpp>
292 #endif //BOOST_INTRUSIVE_SLIST_HOOK_HPP