1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2014
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_ANY_NODE_HPP
14 #define BOOST_INTRUSIVE_ANY_NODE_HPP
20 #include <boost/intrusive/pointer_rebind.hpp>
22 #include <boost/intrusive/detail/mpl.hpp>
27 template<class VoidPointer>
30 typedef any_node node;
31 typedef typename pointer_rebind<VoidPointer, node>::type node_ptr;
32 typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr;
39 template<class VoidPointer>
40 struct any_list_node_traits
42 typedef any_node<VoidPointer> node;
43 typedef typename node::node_ptr node_ptr;
44 typedef typename node::const_node_ptr const_node_ptr;
46 static const node_ptr &get_next(const const_node_ptr & n)
47 { return n->node_ptr_1; }
49 static void set_next(const node_ptr & n, const node_ptr & next)
50 { n->node_ptr_1 = next; }
52 static const node_ptr &get_previous(const const_node_ptr & n)
53 { return n->node_ptr_2; }
55 static void set_previous(const node_ptr & n, const node_ptr & prev)
56 { n->node_ptr_2 = prev; }
60 template<class VoidPointer>
61 struct any_slist_node_traits
63 typedef any_node<VoidPointer> node;
64 typedef typename node::node_ptr node_ptr;
65 typedef typename node::const_node_ptr const_node_ptr;
67 static const node_ptr &get_next(const const_node_ptr & n)
68 { return n->node_ptr_1; }
70 static void set_next(const node_ptr & n, const node_ptr & next)
71 { n->node_ptr_1 = next; }
75 template<class VoidPointer>
76 struct any_unordered_node_traits
77 : public any_slist_node_traits<VoidPointer>
79 typedef any_slist_node_traits<VoidPointer> reduced_slist_node_traits;
80 typedef typename reduced_slist_node_traits::node node;
81 typedef typename reduced_slist_node_traits::node_ptr node_ptr;
82 typedef typename reduced_slist_node_traits::const_node_ptr const_node_ptr;
84 static const bool store_hash = true;
85 static const bool optimize_multikey = true;
87 static const node_ptr &get_next(const const_node_ptr & n)
88 { return n->node_ptr_1; }
90 static void set_next(const node_ptr & n, const node_ptr & next)
91 { n->node_ptr_1 = next; }
93 static node_ptr get_prev_in_group(const const_node_ptr & n)
94 { return n->node_ptr_2; }
96 static void set_prev_in_group(const node_ptr & n, const node_ptr & prev)
97 { n->node_ptr_2 = prev; }
99 static std::size_t get_hash(const const_node_ptr & n)
100 { return n->size_t_1; }
102 static void set_hash(const node_ptr & n, std::size_t h)
107 template<class VoidPointer>
108 struct any_rbtree_node_traits
110 typedef any_node<VoidPointer> node;
111 typedef typename node::node_ptr node_ptr;
112 typedef typename node::const_node_ptr const_node_ptr;
114 typedef std::size_t color;
116 static const node_ptr &get_parent(const const_node_ptr & n)
117 { return n->node_ptr_1; }
119 static void set_parent(const node_ptr & n, const node_ptr & p)
120 { n->node_ptr_1 = p; }
122 static const node_ptr &get_left(const const_node_ptr & n)
123 { return n->node_ptr_2; }
125 static void set_left(const node_ptr & n, const node_ptr & l)
126 { n->node_ptr_2 = l; }
128 static const node_ptr &get_right(const const_node_ptr & n)
129 { return n->node_ptr_3; }
131 static void set_right(const node_ptr & n, const node_ptr & r)
132 { n->node_ptr_3 = r; }
134 static color get_color(const const_node_ptr & n)
135 { return n->size_t_1; }
137 static void set_color(const node_ptr & n, color c)
148 template<class VoidPointer>
149 struct any_avltree_node_traits
151 typedef any_node<VoidPointer> node;
152 typedef typename node::node_ptr node_ptr;
153 typedef typename node::const_node_ptr const_node_ptr;
155 typedef std::size_t balance;
157 static const node_ptr &get_parent(const const_node_ptr & n)
158 { return n->node_ptr_1; }
160 static void set_parent(const node_ptr & n, const node_ptr & p)
161 { n->node_ptr_1 = p; }
163 static const node_ptr &get_left(const const_node_ptr & n)
164 { return n->node_ptr_2; }
166 static void set_left(const node_ptr & n, const node_ptr & l)
167 { n->node_ptr_2 = l; }
169 static const node_ptr &get_right(const const_node_ptr & n)
170 { return n->node_ptr_3; }
172 static void set_right(const node_ptr & n, const node_ptr & r)
173 { n->node_ptr_3 = r; }
175 static balance get_balance(const const_node_ptr & n)
176 { return n->size_t_1; }
178 static void set_balance(const node_ptr & n, balance b)
181 static balance negative()
184 static balance zero()
187 static balance positive()
192 template<class VoidPointer>
193 struct any_tree_node_traits
195 typedef any_node<VoidPointer> node;
196 typedef typename node::node_ptr node_ptr;
197 typedef typename node::const_node_ptr const_node_ptr;
199 static const node_ptr &get_parent(const const_node_ptr & n)
200 { return n->node_ptr_1; }
202 static void set_parent(const node_ptr & n, const node_ptr & p)
203 { n->node_ptr_1 = p; }
205 static const node_ptr &get_left(const const_node_ptr & n)
206 { return n->node_ptr_2; }
208 static void set_left(const node_ptr & n, const node_ptr & l)
209 { n->node_ptr_2 = l; }
211 static const node_ptr &get_right(const const_node_ptr & n)
212 { return n->node_ptr_3; }
214 static void set_right(const node_ptr & n, const node_ptr & r)
215 { n->node_ptr_3 = r; }
218 template<class VoidPointer>
219 class any_node_traits
222 typedef any_node<VoidPointer> node;
223 typedef typename node::node_ptr node_ptr;
224 typedef typename node::const_node_ptr const_node_ptr;
227 template<class VoidPointer>
231 static void function_not_available_for_any_hooks(typename detail::enable_if<detail::is_same<T, bool> >::type)
235 typedef any_node<VoidPointer> node;
236 typedef typename node::node_ptr node_ptr;
237 typedef typename node::const_node_ptr const_node_ptr;
238 typedef any_node_traits<VoidPointer> node_traits;
240 //! <b>Requires</b>: node must not be part of any tree.
242 //! <b>Effects</b>: After the function unique(node) == true.
244 //! <b>Complexity</b>: Constant.
246 //! <b>Throws</b>: Nothing.
248 //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
249 static void init(const node_ptr & node)
250 { node->node_ptr_1 = 0; };
252 //! <b>Effects</b>: Returns true if node is in the same state as if called init(node)
254 //! <b>Complexity</b>: Constant.
256 //! <b>Throws</b>: Nothing.
257 static bool inited(const const_node_ptr & node)
258 { return !node->node_ptr_1; };
260 static bool unique(const const_node_ptr & node)
261 { return 0 == node->node_ptr_1; }
263 static void unlink(const node_ptr &)
265 //Auto-unlink hooks and unlink() are not available for any hooks
266 any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
269 static void swap_nodes(const node_ptr &, const node_ptr &)
271 //Any nodes have no swap_nodes capability because they don't know
272 //what algorithm they must use to unlink the node from the container
273 any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
277 } //namespace intrusive
280 #endif //BOOST_INTRUSIVE_ANY_NODE_HPP