comparison DEPENDENCIES/generic/include/boost/intrusive/detail/generic_hook.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2007-2013
4 //
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)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef BOOST_INTRUSIVE_GENERIC_HOOK_HPP
14 #define BOOST_INTRUSIVE_GENERIC_HOOK_HPP
15
16 #include <boost/intrusive/detail/config_begin.hpp>
17 #include <boost/intrusive/intrusive_fwd.hpp>
18 #include <boost/intrusive/pointer_traits.hpp>
19 #include <boost/intrusive/link_mode.hpp>
20 #include <boost/intrusive/detail/utilities.hpp>
21 #include <boost/intrusive/detail/mpl.hpp>
22 #include <boost/intrusive/pointer_traits.hpp>
23 #include <boost/static_assert.hpp>
24
25 namespace boost {
26 namespace intrusive {
27
28 /// @cond
29
30 enum base_hook_type
31 { NoBaseHookId
32 , ListBaseHookId
33 , SlistBaseHookId
34 , RbTreeBaseHookId
35 , HashBaseHookId
36 , SplayTreeBaseHookId
37 , AvlTreeBaseHookId
38 , BsTreeBaseHookId
39 , AnyBaseHookId
40 };
41
42
43 template <class HookTags, unsigned int>
44 struct hook_tags_definer{};
45
46 template <class HookTags>
47 struct hook_tags_definer<HookTags, ListBaseHookId>
48 { typedef HookTags default_list_hook; };
49
50 template <class HookTags>
51 struct hook_tags_definer<HookTags, SlistBaseHookId>
52 { typedef HookTags default_slist_hook; };
53
54 template <class HookTags>
55 struct hook_tags_definer<HookTags, RbTreeBaseHookId>
56 { typedef HookTags default_rbtree_hook; };
57
58 template <class HookTags>
59 struct hook_tags_definer<HookTags, HashBaseHookId>
60 { typedef HookTags default_hashtable_hook; };
61
62 template <class HookTags>
63 struct hook_tags_definer<HookTags, SplayTreeBaseHookId>
64 { typedef HookTags default_splaytree_hook; };
65
66 template <class HookTags>
67 struct hook_tags_definer<HookTags, AvlTreeBaseHookId>
68 { typedef HookTags default_avltree_hook; };
69
70 template <class HookTags>
71 struct hook_tags_definer<HookTags, BsTreeBaseHookId>
72 { typedef HookTags default_bstree_hook; };
73
74 template <class HookTags>
75 struct hook_tags_definer<HookTags, AnyBaseHookId>
76 { typedef HookTags default_any_hook; };
77
78 template
79 < class NodeTraits
80 , class Tag
81 , link_mode_type LinkMode
82 , base_hook_type BaseHookType
83 >
84 struct hooktags_impl
85 {
86 static const link_mode_type link_mode = LinkMode;
87 typedef Tag tag;
88 typedef NodeTraits node_traits;
89 static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value;
90 static const bool safemode_or_autounlink = is_safe_autounlink<link_mode>::value;
91 static const unsigned int type = BaseHookType;
92 };
93
94 /// @endcond
95
96 template
97 < class GetNodeAlgorithms
98 , class Tag
99 , link_mode_type LinkMode
100 , base_hook_type BaseHookType
101 >
102 class generic_hook
103 /// @cond
104 //If the hook is a base hook, derive generic hook from node_holder
105 //so that a unique base class is created to convert from the node
106 //to the type. This mechanism will be used by bhtraits.
107 //
108 //If the hook is a member hook, generic hook will directly derive
109 //from the hook.
110 : public detail::if_c
111 < detail::is_same<Tag, member_tag>::value
112 , typename GetNodeAlgorithms::type::node
113 , node_holder<typename GetNodeAlgorithms::type::node, Tag, BaseHookType>
114 >::type
115 //If this is the a default-tagged base hook derive from a class that
116 //will define an special internal typedef. Containers will be able to detect this
117 //special typedef and obtain generic_hook's internal types in order to deduce
118 //value_traits for this hook.
119 , public hook_tags_definer
120 < generic_hook<GetNodeAlgorithms, Tag, LinkMode, BaseHookType>
121 , detail::is_same<Tag, default_tag>::value*BaseHookType>
122 /// @endcond
123 {
124 /// @cond
125 typedef typename GetNodeAlgorithms::type node_algorithms;
126 typedef typename node_algorithms::node node;
127 typedef typename node_algorithms::node_ptr node_ptr;
128 typedef typename node_algorithms::const_node_ptr const_node_ptr;
129
130 public:
131
132 typedef hooktags_impl
133 < typename GetNodeAlgorithms::type::node_traits
134 , Tag, LinkMode, BaseHookType> hooktags;
135
136 node_ptr this_ptr()
137 { return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*this)); }
138
139 const_node_ptr this_ptr() const
140 { return pointer_traits<const_node_ptr>::pointer_to(static_cast<const node&>(*this)); }
141
142 public:
143 /// @endcond
144
145 generic_hook()
146 {
147 if(hooktags::safemode_or_autounlink){
148 node_algorithms::init(this->this_ptr());
149 }
150 }
151
152 generic_hook(const generic_hook& )
153 {
154 if(hooktags::safemode_or_autounlink){
155 node_algorithms::init(this->this_ptr());
156 }
157 }
158
159 generic_hook& operator=(const generic_hook& )
160 { return *this; }
161
162 ~generic_hook()
163 {
164 destructor_impl
165 (*this, detail::link_dispatch<hooktags::link_mode>());
166 }
167
168 void swap_nodes(generic_hook &other)
169 {
170 node_algorithms::swap_nodes
171 (this->this_ptr(), other.this_ptr());
172 }
173
174 bool is_linked() const
175 {
176 //is_linked() can be only used in safe-mode or auto-unlink
177 BOOST_STATIC_ASSERT(( hooktags::safemode_or_autounlink ));
178 return !node_algorithms::unique(this->this_ptr());
179 }
180
181 void unlink()
182 {
183 BOOST_STATIC_ASSERT(( (int)hooktags::link_mode == (int)auto_unlink ));
184 node_algorithms::unlink(this->this_ptr());
185 node_algorithms::init(this->this_ptr());
186 }
187 };
188
189 } //namespace intrusive
190 } //namespace boost
191
192 #include <boost/intrusive/detail/config_end.hpp>
193
194 #endif //BOOST_INTRUSIVE_GENERIC_HOOK_HPP