Chris@102
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
2 //
|
Chris@102
|
3 // (C) Copyright Ion Gaztanaga 2006-2014
|
Chris@102
|
4 //
|
Chris@102
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@102
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
8 //
|
Chris@102
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@102
|
10 //
|
Chris@102
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
12
|
Chris@102
|
13 #ifndef BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
|
Chris@102
|
14 #define BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
|
Chris@102
|
15
|
Chris@102
|
16 #ifndef BOOST_CONFIG_HPP
|
Chris@102
|
17 # include <boost/config.hpp>
|
Chris@102
|
18 #endif
|
Chris@102
|
19
|
Chris@102
|
20 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@102
|
21 # pragma once
|
Chris@102
|
22 #endif
|
Chris@102
|
23
|
Chris@102
|
24 #include <boost/intrusive/pointer_traits.hpp>
|
Chris@102
|
25 #include <boost/intrusive/detail/parent_from_member.hpp>
|
Chris@102
|
26 #include <boost/intrusive/link_mode.hpp>
|
Chris@102
|
27 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@102
|
28 #include <boost/intrusive/detail/to_raw_pointer.hpp>
|
Chris@102
|
29 #include <boost/intrusive/detail/node_holder.hpp>
|
Chris@102
|
30
|
Chris@102
|
31 namespace boost {
|
Chris@102
|
32 namespace intrusive {
|
Chris@102
|
33
|
Chris@102
|
34 template<class T, class NodePtr, class Tag, unsigned int Type>
|
Chris@102
|
35 struct bhtraits_base
|
Chris@102
|
36 {
|
Chris@102
|
37 public:
|
Chris@102
|
38 typedef NodePtr node_ptr;
|
Chris@102
|
39 typedef typename pointer_traits<node_ptr>::element_type node;
|
Chris@102
|
40 typedef node_holder<node, Tag, Type> node_holder_type;
|
Chris@102
|
41 typedef T value_type;
|
Chris@102
|
42 typedef typename pointer_traits<node_ptr>::
|
Chris@102
|
43 template rebind_pointer<const node>::type const_node_ptr;
|
Chris@102
|
44 typedef typename pointer_traits<node_ptr>::
|
Chris@102
|
45 template rebind_pointer<T>::type pointer;
|
Chris@102
|
46 typedef typename pointer_traits<node_ptr>::
|
Chris@102
|
47 template rebind_pointer<const T>::type const_pointer;
|
Chris@102
|
48 //typedef typename pointer_traits<pointer>::reference reference;
|
Chris@102
|
49 //typedef typename pointer_traits<const_pointer>::reference const_reference;
|
Chris@102
|
50 typedef T & reference;
|
Chris@102
|
51 typedef const T & const_reference;
|
Chris@102
|
52 typedef node_holder_type & node_holder_reference;
|
Chris@102
|
53 typedef const node_holder_type & const_node_holder_reference;
|
Chris@102
|
54 typedef node& node_reference;
|
Chris@102
|
55 typedef const node & const_node_reference;
|
Chris@102
|
56
|
Chris@102
|
57 static pointer to_value_ptr(const node_ptr & n)
|
Chris@102
|
58 {
|
Chris@102
|
59 return pointer_traits<pointer>::pointer_to
|
Chris@102
|
60 (static_cast<reference>(static_cast<node_holder_reference>(*n)));
|
Chris@102
|
61 }
|
Chris@102
|
62
|
Chris@102
|
63 static const_pointer to_value_ptr(const const_node_ptr & n)
|
Chris@102
|
64 {
|
Chris@102
|
65 return pointer_traits<const_pointer>::pointer_to
|
Chris@102
|
66 (static_cast<const_reference>(static_cast<const_node_holder_reference>(*n)));
|
Chris@102
|
67 }
|
Chris@102
|
68
|
Chris@102
|
69 static node_ptr to_node_ptr(reference value)
|
Chris@102
|
70 {
|
Chris@102
|
71 return pointer_traits<node_ptr>::pointer_to
|
Chris@102
|
72 (static_cast<node_reference>(static_cast<node_holder_reference>(value)));
|
Chris@102
|
73 }
|
Chris@102
|
74
|
Chris@102
|
75 static const_node_ptr to_node_ptr(const_reference value)
|
Chris@102
|
76 {
|
Chris@102
|
77 return pointer_traits<const_node_ptr>::pointer_to
|
Chris@102
|
78 (static_cast<const_node_reference>(static_cast<const_node_holder_reference>(value)));
|
Chris@102
|
79 }
|
Chris@102
|
80 };
|
Chris@102
|
81
|
Chris@102
|
82 template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, unsigned int Type>
|
Chris@102
|
83 struct bhtraits
|
Chris@102
|
84 : public bhtraits_base<T, typename NodeTraits::node_ptr, Tag, Type>
|
Chris@102
|
85 {
|
Chris@102
|
86 static const link_mode_type link_mode = LinkMode;
|
Chris@102
|
87 typedef NodeTraits node_traits;
|
Chris@102
|
88 };
|
Chris@102
|
89
|
Chris@102
|
90
|
Chris@102
|
91 template<class T, class Hook, Hook T::* P>
|
Chris@102
|
92 struct mhtraits
|
Chris@102
|
93 {
|
Chris@102
|
94 public:
|
Chris@102
|
95 typedef Hook hook_type;
|
Chris@102
|
96 typedef typename hook_type::hooktags::node_traits node_traits;
|
Chris@102
|
97 typedef typename node_traits::node node;
|
Chris@102
|
98 typedef T value_type;
|
Chris@102
|
99 typedef typename node_traits::node_ptr node_ptr;
|
Chris@102
|
100 typedef typename node_traits::const_node_ptr const_node_ptr;
|
Chris@102
|
101 typedef typename pointer_traits<node_ptr>::
|
Chris@102
|
102 template rebind_pointer<T>::type pointer;
|
Chris@102
|
103 typedef typename pointer_traits<node_ptr>::
|
Chris@102
|
104 template rebind_pointer<const T>::type const_pointer;
|
Chris@102
|
105 typedef T & reference;
|
Chris@102
|
106 typedef const T & const_reference;
|
Chris@102
|
107 typedef node& node_reference;
|
Chris@102
|
108 typedef const node & const_node_reference;
|
Chris@102
|
109 typedef hook_type& hook_reference;
|
Chris@102
|
110 typedef const hook_type & const_hook_reference;
|
Chris@102
|
111
|
Chris@102
|
112 static const link_mode_type link_mode = Hook::hooktags::link_mode;
|
Chris@102
|
113
|
Chris@102
|
114 static node_ptr to_node_ptr(reference value)
|
Chris@102
|
115 {
|
Chris@102
|
116 return pointer_traits<node_ptr>::pointer_to
|
Chris@102
|
117 (static_cast<node_reference>(static_cast<hook_reference>(value.*P)));
|
Chris@102
|
118 }
|
Chris@102
|
119
|
Chris@102
|
120 static const_node_ptr to_node_ptr(const_reference value)
|
Chris@102
|
121 {
|
Chris@102
|
122 return pointer_traits<const_node_ptr>::pointer_to
|
Chris@102
|
123 (static_cast<const_node_reference>(static_cast<const_hook_reference>(value.*P)));
|
Chris@102
|
124 }
|
Chris@102
|
125
|
Chris@102
|
126 static pointer to_value_ptr(const node_ptr & n)
|
Chris@102
|
127 {
|
Chris@102
|
128 return pointer_traits<pointer>::pointer_to
|
Chris@102
|
129 (*detail::parent_from_member<T, Hook>
|
Chris@102
|
130 (static_cast<Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P));
|
Chris@102
|
131 }
|
Chris@102
|
132
|
Chris@102
|
133 static const_pointer to_value_ptr(const const_node_ptr & n)
|
Chris@102
|
134 {
|
Chris@102
|
135 return pointer_traits<const_pointer>::pointer_to
|
Chris@102
|
136 (*detail::parent_from_member<T, Hook>
|
Chris@102
|
137 (static_cast<const Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P));
|
Chris@102
|
138 }
|
Chris@102
|
139 };
|
Chris@102
|
140
|
Chris@102
|
141
|
Chris@102
|
142 template<class Functor>
|
Chris@102
|
143 struct fhtraits
|
Chris@102
|
144 {
|
Chris@102
|
145 public:
|
Chris@102
|
146 typedef typename Functor::hook_type hook_type;
|
Chris@102
|
147 typedef typename Functor::hook_ptr hook_ptr;
|
Chris@102
|
148 typedef typename Functor::const_hook_ptr const_hook_ptr;
|
Chris@102
|
149 typedef typename hook_type::hooktags::node_traits node_traits;
|
Chris@102
|
150 typedef typename node_traits::node node;
|
Chris@102
|
151 typedef typename Functor::value_type value_type;
|
Chris@102
|
152 typedef typename node_traits::node_ptr node_ptr;
|
Chris@102
|
153 typedef typename node_traits::const_node_ptr const_node_ptr;
|
Chris@102
|
154 typedef typename pointer_traits<node_ptr>::
|
Chris@102
|
155 template rebind_pointer<value_type>::type pointer;
|
Chris@102
|
156 typedef typename pointer_traits<node_ptr>::
|
Chris@102
|
157 template rebind_pointer<const value_type>::type const_pointer;
|
Chris@102
|
158 typedef value_type & reference;
|
Chris@102
|
159 typedef const value_type & const_reference;
|
Chris@102
|
160 static const link_mode_type link_mode = hook_type::hooktags::link_mode;
|
Chris@102
|
161
|
Chris@102
|
162 static node_ptr to_node_ptr(reference value)
|
Chris@102
|
163 { return static_cast<node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); }
|
Chris@102
|
164
|
Chris@102
|
165 static const_node_ptr to_node_ptr(const_reference value)
|
Chris@102
|
166 { return static_cast<const node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); }
|
Chris@102
|
167
|
Chris@102
|
168 static pointer to_value_ptr(const node_ptr & n)
|
Chris@102
|
169 { return Functor::to_value_ptr(to_hook_ptr(n)); }
|
Chris@102
|
170
|
Chris@102
|
171 static const_pointer to_value_ptr(const const_node_ptr & n)
|
Chris@102
|
172 { return Functor::to_value_ptr(to_hook_ptr(n)); }
|
Chris@102
|
173
|
Chris@102
|
174 private:
|
Chris@102
|
175 static hook_ptr to_hook_ptr(const node_ptr & n)
|
Chris@102
|
176 { return hook_ptr(&*static_cast<hook_type*>(&*n)); }
|
Chris@102
|
177
|
Chris@102
|
178 static const_hook_ptr to_hook_ptr(const const_node_ptr & n)
|
Chris@102
|
179 { return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); }
|
Chris@102
|
180 };
|
Chris@102
|
181
|
Chris@102
|
182
|
Chris@102
|
183 } //namespace intrusive
|
Chris@102
|
184 } //namespace boost
|
Chris@102
|
185
|
Chris@102
|
186 #endif //BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
|