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_DETAIL_HOOK_TRAITS_HPP
14 #define BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
16 #ifndef BOOST_CONFIG_HPP
17 # include <boost/config.hpp>
20 #if defined(BOOST_HAS_PRAGMA_ONCE)
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>
35 template<class T, class NodePtr, class Tag, unsigned int Type>
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;
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;
58 BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(const node_ptr & n)
60 pointer p = pointer_traits<pointer>::pointer_to
61 (static_cast<reference>(static_cast<node_holder_reference>(*n)));
66 BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const const_node_ptr & n)
68 const_pointer p = pointer_traits<const_pointer>::pointer_to
69 (static_cast<const_reference>(static_cast<const_node_holder_reference>(*n)));
74 BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value)
76 node_ptr p = pointer_traits<node_ptr>::pointer_to
77 (static_cast<node_reference>(static_cast<node_holder_reference>(value)));
82 BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value)
84 const_node_ptr p = pointer_traits<const_node_ptr>::pointer_to
85 (static_cast<const_node_reference>(static_cast<const_node_holder_reference>(value)));
91 template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, unsigned int Type>
93 : public bhtraits_base<T, typename NodeTraits::node_ptr, Tag, Type>
95 static const link_mode_type link_mode = LinkMode;
96 typedef NodeTraits node_traits;
100 template<class T, class Hook, Hook T::* P>
104 typedef Hook hook_type;
105 typedef typename hook_type::hooktags::node_traits node_traits;
106 typedef typename node_traits::node node;
107 typedef T value_type;
108 typedef typename node_traits::node_ptr node_ptr;
109 typedef typename node_traits::const_node_ptr const_node_ptr;
110 typedef typename pointer_traits<node_ptr>::
111 template rebind_pointer<T>::type pointer;
112 typedef typename pointer_traits<node_ptr>::
113 template rebind_pointer<const T>::type const_pointer;
114 typedef T & reference;
115 typedef const T & const_reference;
116 typedef node& node_reference;
117 typedef const node & const_node_reference;
118 typedef hook_type& hook_reference;
119 typedef const hook_type & const_hook_reference;
121 static const link_mode_type link_mode = Hook::hooktags::link_mode;
123 BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value)
125 return pointer_traits<node_ptr>::pointer_to
126 (static_cast<node_reference>(static_cast<hook_reference>(value.*P)));
129 BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value)
131 return pointer_traits<const_node_ptr>::pointer_to
132 (static_cast<const_node_reference>(static_cast<const_hook_reference>(value.*P)));
135 BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(const node_ptr & n)
137 return pointer_traits<pointer>::pointer_to
138 (*detail::parent_from_member<T, Hook>
139 (static_cast<Hook*>(boost::movelib::to_raw_pointer(n)), P));
142 BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const const_node_ptr & n)
144 return pointer_traits<const_pointer>::pointer_to
145 (*detail::parent_from_member<T, Hook>
146 (static_cast<const Hook*>(boost::movelib::to_raw_pointer(n)), P));
151 template<class Functor>
155 typedef typename Functor::hook_type hook_type;
156 typedef typename Functor::hook_ptr hook_ptr;
157 typedef typename Functor::const_hook_ptr const_hook_ptr;
158 typedef typename hook_type::hooktags::node_traits node_traits;
159 typedef typename node_traits::node node;
160 typedef typename Functor::value_type value_type;
161 typedef typename node_traits::node_ptr node_ptr;
162 typedef typename node_traits::const_node_ptr const_node_ptr;
163 typedef typename pointer_traits<node_ptr>::
164 template rebind_pointer<value_type>::type pointer;
165 typedef typename pointer_traits<node_ptr>::
166 template rebind_pointer<const value_type>::type const_pointer;
167 typedef value_type & reference;
168 typedef const value_type & const_reference;
169 static const link_mode_type link_mode = hook_type::hooktags::link_mode;
171 static node_ptr to_node_ptr(reference value)
172 { return static_cast<node*>(boost::movelib::to_raw_pointer(Functor::to_hook_ptr(value))); }
174 static const_node_ptr to_node_ptr(const_reference value)
175 { return static_cast<const node*>(boost::movelib::to_raw_pointer(Functor::to_hook_ptr(value))); }
177 static pointer to_value_ptr(const node_ptr & n)
178 { return Functor::to_value_ptr(to_hook_ptr(n)); }
180 static const_pointer to_value_ptr(const const_node_ptr & n)
181 { return Functor::to_value_ptr(to_hook_ptr(n)); }
184 static hook_ptr to_hook_ptr(const node_ptr & n)
185 { return hook_ptr(&*static_cast<hook_type*>(&*n)); }
187 static const_hook_ptr to_hook_ptr(const const_node_ptr & n)
188 { return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); }
192 } //namespace intrusive
195 #endif //BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP