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