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 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP
14 #define BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP
16 #include <boost/intrusive/detail/config_begin.hpp>
17 #include <boost/intrusive/intrusive_fwd.hpp>
18 #include <boost/intrusive/detail/utilities.hpp>
19 #include <boost/intrusive/detail/tree_node.hpp>
20 #include <boost/intrusive/splaytree_algorithms.hpp>
21 #include <boost/intrusive/options.hpp>
22 #include <boost/intrusive/detail/generic_hook.hpp>
28 template<class VoidPointer
>
29 struct get_splay_set_node_algo
31 typedef splaytree_algorithms
<tree_node_traits
<VoidPointer
> > type
;
35 //! Helper metafunction to define a \c splay_set_base_hook that yields to the same
36 //! type when the same options (either explicitly or implicitly) are used.
37 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
38 template<class ...Options
>
40 template<class O1
= none
, class O2
= none
, class O3
= none
>
42 struct make_splay_set_base_hook
45 typedef typename pack_options
47 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
52 >::type packed_options
;
54 typedef detail::generic_hook
55 < get_splay_set_node_algo
<typename
packed_options::void_pointer
>
56 , typename
packed_options::tag
57 , packed_options::link_mode
58 , detail::SplaySetBaseHook
59 > implementation_defined
;
61 typedef implementation_defined type
;
64 //! Derive a class from splay_set_base_hook in order to store objects in
65 //! in a splay_set/splay_multiset. splay_set_base_hook holds the data necessary to maintain
66 //! the splay_set/splay_multiset and provides an appropriate value_traits class for splay_set/splay_multiset.
68 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
69 //! \c link_mode<> and \c optimize_size<>.
71 //! \c tag<> defines a tag to identify the node.
72 //! The same tag value can be used in different classes, but if a class is
73 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
76 //! \c void_pointer<> is the pointer type that will be used internally in the hook
77 //! and the the container configured to use this hook.
79 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
80 //! \c auto_unlink or \c safe_link).
81 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
82 template<class ...Options
>
84 template<class O1
, class O2
, class O3
>
86 class splay_set_base_hook
87 : public make_splay_set_base_hook
<
88 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
95 #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.
100 splay_set_base_hook();
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 splay_set_base_hook(const splay_set_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 splay_set_base_hook
& operator=(const splay_set_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 a set 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.
129 ~splay_set_base_hook();
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(splay_set_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 set::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 splay_set_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
= none
, class O2
= none
, class O3
= none
>
169 struct make_splay_set_member_hook
172 typedef typename pack_options
174 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
179 >::type packed_options
;
181 typedef detail::generic_hook
182 < get_splay_set_node_algo
<typename
packed_options::void_pointer
>
184 , packed_options::link_mode
186 > implementation_defined
;
188 typedef implementation_defined type
;
191 //! Put a public data member splay_set_member_hook in order to store objects of this
192 //! class in a splay_set/splay_multiset. splay_set_member_hook holds the data
193 //! necessary for maintaining the splay_set/splay_multiset and provides an appropriate
194 //! value_traits class for splay_set/splay_multiset.
196 //! The hook admits the following options: \c void_pointer<>,
197 //! \c link_mode<> and \c optimize_size<>.
199 //! \c void_pointer<> is the pointer type that will be used internally in the hook
200 //! and the the container configured to use this hook.
202 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
203 //! \c auto_unlink or \c safe_link).
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 splay_set_member_hook
210 : public make_splay_set_member_hook
<
211 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
218 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
219 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
220 //! initializes the node to an unlinked state.
222 //! <b>Throws</b>: Nothing.
223 splay_set_member_hook();
225 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
226 //! initializes the node to an unlinked state. The argument is ignored.
228 //! <b>Throws</b>: Nothing.
230 //! <b>Rationale</b>: Providing a copy-constructor
231 //! makes classes using the hook STL-compliant without forcing the
232 //! user to do some additional work. \c swap can be used to emulate
234 splay_set_member_hook(const splay_set_member_hook
& );
236 //! <b>Effects</b>: Empty function. The argument is ignored.
238 //! <b>Throws</b>: Nothing.
240 //! <b>Rationale</b>: Providing an assignment operator
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
244 splay_set_member_hook
& operator=(const splay_set_member_hook
& );
246 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
247 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
248 //! object is stored in a set an assertion is raised. If link_mode is
249 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
251 //! <b>Throws</b>: Nothing.
252 ~splay_set_member_hook();
254 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
255 //! related to those nodes in one or two containers. That is, if the node
256 //! this is part of the element e1, the node x is part of the element e2
257 //! and both elements are included in the containers s1 and s2, then after
258 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
259 //! at the position of e1. If one element is not in a container, then
260 //! after the swap-operation the other element is not in a container.
261 //! Iterators to e1 and e2 related to those nodes are invalidated.
263 //! <b>Complexity</b>: Constant
265 //! <b>Throws</b>: Nothing.
266 void swap_nodes(splay_set_member_hook
&other
);
268 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
270 //! <b>Returns</b>: true, if the node belongs to a container, false
271 //! otherwise. This function can be used to test whether \c set::iterator_to
272 //! will return a valid iterator.
274 //! <b>Complexity</b>: Constant
275 bool is_linked() const;
277 //! <b>Effects</b>: Removes the node if it's inserted in a container.
278 //! This function is only allowed if link_mode is \c auto_unlink.
280 //! <b>Throws</b>: Nothing.
285 } //namespace intrusive
288 #include <boost/intrusive/detail/config_end.hpp>
290 #endif //BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP