1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2007-2013
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_BS_SET_HOOK_HPP
14 #define BOOST_INTRUSIVE_BS_SET_HOOK_HPP
16 #include <boost/intrusive/detail/config_begin.hpp>
17 #include <boost/intrusive/intrusive_fwd.hpp>
19 #include <boost/intrusive/detail/tree_node.hpp>
20 #include <boost/intrusive/bstree_algorithms.hpp>
21 #include <boost/intrusive/options.hpp>
22 #include <boost/intrusive/detail/generic_hook.hpp>
24 #if defined(BOOST_HAS_PRAGMA_ONCE)
31 //! Helper metafunction to define a \c bs_set_base_hook that yields to the same
32 //! type when the same options (either explicitly or implicitly) are used.
33 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
34 template<class ...Options>
36 template<class O1 = void, class O2 = void, class O3 = void>
38 struct make_bs_set_base_hook
41 typedef typename pack_options
42 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
43 < hook_defaults, O1, O2, O3>
45 < hook_defaults, Options...>
47 ::type packed_options;
51 , tree_node_traits<typename packed_options::void_pointer>
52 , typename packed_options::tag
53 , packed_options::link_mode
55 > implementation_defined;
57 typedef implementation_defined type;
60 //! Derive a class from bs_set_base_hook in order to store objects in
61 //! in a bs_set/bs_multiset. bs_set_base_hook holds the data necessary to maintain
62 //! the bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
64 //! The hook admits the following options: \c tag<>, \c void_pointer<>,
67 //! \c tag<> defines a tag to identify the node.
68 //! The same tag value can be used in different classes, but if a class is
69 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
72 //! \c void_pointer<> is the pointer type that will be used internally in the hook
73 //! and the container configured to use this hook.
75 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
76 //! \c auto_unlink or \c safe_link).
77 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
78 template<class ...Options>
80 template<class O1, class O2, class O3>
82 class bs_set_base_hook
83 : public make_bs_set_base_hook
84 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
92 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
94 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
95 //! initializes the node to an unlinked state.
97 //! <b>Throws</b>: Nothing.
100 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
101 //! initializes the node to an unlinked state. The argument is ignored.
103 //! <b>Throws</b>: Nothing.
105 //! <b>Rationale</b>: Providing a copy-constructor
106 //! makes classes using the hook STL-compliant without forcing the
107 //! user to do some additional work. \c swap can be used to emulate
109 bs_set_base_hook(const bs_set_base_hook& );
111 //! <b>Effects</b>: Empty function. The argument is ignored.
113 //! <b>Throws</b>: Nothing.
115 //! <b>Rationale</b>: Providing an assignment operator
116 //! makes classes using the hook STL-compliant without forcing the
117 //! user to do some additional work. \c swap can be used to emulate
119 bs_set_base_hook& operator=(const bs_set_base_hook& );
121 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
122 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
123 //! object is stored in a set an assertion is raised. If link_mode is
124 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
126 //! <b>Throws</b>: Nothing.
129 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
130 //! related to those nodes in one or two containers. That is, if the node
131 //! this is part of the element e1, the node x is part of the element e2
132 //! and both elements are included in the containers s1 and s2, then after
133 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
134 //! at the position of e1. If one element is not in a container, then
135 //! after the swap-operation the other element is not in a container.
136 //! Iterators to e1 and e2 related to those nodes are invalidated.
138 //! <b>Complexity</b>: Constant
140 //! <b>Throws</b>: Nothing.
141 void swap_nodes(bs_set_base_hook &other);
143 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
145 //! <b>Returns</b>: true, if the node belongs to a container, false
146 //! otherwise. This function can be used to test whether \c set::iterator_to
147 //! will return a valid iterator.
149 //! <b>Complexity</b>: Constant
150 bool is_linked() const;
152 //! <b>Effects</b>: Removes the node if it's inserted in a container.
153 //! This function is only allowed if link_mode is \c auto_unlink.
155 //! <b>Throws</b>: Nothing.
160 //! Helper metafunction to define a \c bs_set_member_hook that yields to the same
161 //! type when the same options (either explicitly or implicitly) are used.
162 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
163 template<class ...Options>
165 template<class O1 = void, class O2 = void, class O3 = void>
167 struct make_bs_set_member_hook
170 typedef typename pack_options
171 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
172 < hook_defaults, O1, O2, O3>
174 < hook_defaults, Options...>
177 ::type packed_options;
181 , tree_node_traits<typename packed_options::void_pointer>
183 , packed_options::link_mode
185 > implementation_defined;
187 typedef implementation_defined type;
190 //! Put a public data member bs_set_member_hook in order to store objects of this class in
191 //! a bs_set/bs_multiset. bs_set_member_hook holds the data necessary for maintaining the
192 //! bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
194 //! The hook admits the following options: \c void_pointer<>, \c link_mode<>.
196 //! \c void_pointer<> is the pointer type that will be used internally in the hook
197 //! and the container configured to use this hook.
199 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
200 //! \c auto_unlink or \c safe_link).
201 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
202 template<class ...Options>
204 template<class O1, class O2, class O3>
206 class bs_set_member_hook
207 : public make_bs_set_member_hook
208 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
215 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
217 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
218 //! initializes the node to an unlinked state.
220 //! <b>Throws</b>: Nothing.
221 bs_set_member_hook();
223 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
224 //! initializes the node to an unlinked state. The argument is ignored.
226 //! <b>Throws</b>: Nothing.
228 //! <b>Rationale</b>: Providing a copy-constructor
229 //! makes classes using the hook STL-compliant without forcing the
230 //! user to do some additional work. \c swap can be used to emulate
232 bs_set_member_hook(const bs_set_member_hook& );
234 //! <b>Effects</b>: Empty function. The argument is ignored.
236 //! <b>Throws</b>: Nothing.
238 //! <b>Rationale</b>: Providing an assignment operator
239 //! makes classes using the hook STL-compliant without forcing the
240 //! user to do some additional work. \c swap can be used to emulate
242 bs_set_member_hook& operator=(const bs_set_member_hook& );
244 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
245 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
246 //! object is stored in a set an assertion is raised. If link_mode is
247 //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
249 //! <b>Throws</b>: Nothing.
250 ~bs_set_member_hook();
252 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
253 //! related to those nodes in one or two containers. That is, if the node
254 //! this is part of the element e1, the node x is part of the element e2
255 //! and both elements are included in the containers s1 and s2, then after
256 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
257 //! at the position of e1. If one element is not in a container, then
258 //! after the swap-operation the other element is not in a container.
259 //! Iterators to e1 and e2 related to those nodes are invalidated.
261 //! <b>Complexity</b>: Constant
263 //! <b>Throws</b>: Nothing.
264 void swap_nodes(bs_set_member_hook &other);
266 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
268 //! <b>Returns</b>: true, if the node belongs to a container, false
269 //! otherwise. This function can be used to test whether \c set::iterator_to
270 //! will return a valid iterator.
272 //! <b>Complexity</b>: Constant
273 bool is_linked() const;
275 //! <b>Effects</b>: Removes the node if it's inserted in a container.
276 //! This function is only allowed if link_mode is \c auto_unlink.
278 //! <b>Throws</b>: Nothing.
283 } //namespace intrusive
286 #include <boost/intrusive/detail/config_end.hpp>
288 #endif //BOOST_INTRUSIVE_BS_SET_HOOK_HPP