File indexing completed on 2025-01-18 09:38:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
0014 #define BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP
0015
0016 #ifndef BOOST_CONFIG_HPP
0017 # include <boost/config.hpp>
0018 #endif
0019
0020 #if defined(BOOST_HAS_PRAGMA_ONCE)
0021 # pragma once
0022 #endif
0023
0024 #include <boost/intrusive/detail/workaround.hpp>
0025 #include <boost/intrusive/pointer_traits.hpp>
0026 #include <boost/intrusive/detail/parent_from_member.hpp>
0027 #include <boost/intrusive/link_mode.hpp>
0028 #include <boost/intrusive/detail/mpl.hpp>
0029 #include <boost/move/detail/to_raw_pointer.hpp>
0030 #include <boost/intrusive/detail/node_holder.hpp>
0031 #include <boost/assert.hpp>
0032
0033 namespace boost {
0034 namespace intrusive {
0035
0036 template<class T, class NodePtr, class Tag, unsigned int Type>
0037 struct bhtraits_base
0038 {
0039 public:
0040 typedef NodePtr node_ptr;
0041 typedef typename pointer_traits<node_ptr>::element_type node;
0042 typedef node_holder<node, Tag, Type> node_holder_type;
0043 typedef T value_type;
0044 typedef typename pointer_traits<node_ptr>::
0045 template rebind_pointer<const node>::type const_node_ptr;
0046 typedef typename pointer_traits<node_ptr>::
0047 template rebind_pointer<T>::type pointer;
0048 typedef typename pointer_traits<node_ptr>::
0049 template rebind_pointer<const T>::type const_pointer;
0050
0051
0052 typedef T & reference;
0053 typedef const T & const_reference;
0054 typedef node_holder_type & node_holder_reference;
0055 typedef const node_holder_type & const_node_holder_reference;
0056 typedef node& node_reference;
0057 typedef const node & const_node_reference;
0058
0059 BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(node_ptr n)
0060 {
0061 pointer p = pointer_traits<pointer>::pointer_to
0062 (static_cast<reference>(static_cast<node_holder_reference>(*n)));
0063 BOOST_ASSERT(!!p);
0064 return p;
0065 }
0066
0067 BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const_node_ptr n)
0068 {
0069 const_pointer p = pointer_traits<const_pointer>::pointer_to
0070 (static_cast<const_reference>(static_cast<const_node_holder_reference>(*n)));
0071 BOOST_ASSERT(!!p);
0072 return p;
0073 }
0074
0075 BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value)
0076 {
0077 node_ptr p = pointer_traits<node_ptr>::pointer_to
0078 (static_cast<node_reference>(static_cast<node_holder_reference>(value)));
0079 BOOST_ASSERT(!!p);
0080 return p;
0081 }
0082
0083 BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value)
0084 {
0085 const_node_ptr p = pointer_traits<const_node_ptr>::pointer_to
0086 (static_cast<const_node_reference>(static_cast<const_node_holder_reference>(value)));
0087 BOOST_ASSERT(!!p);
0088 return p;
0089 }
0090 };
0091
0092 template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, unsigned int Type>
0093 struct bhtraits
0094 : public bhtraits_base<T, typename NodeTraits::node_ptr, Tag, Type>
0095 {
0096 static const link_mode_type link_mode = LinkMode;
0097 typedef NodeTraits node_traits;
0098 };
0099
0100
0101 template<class T, class Hook, Hook T::* P>
0102 struct mhtraits
0103 {
0104 public:
0105 typedef Hook hook_type;
0106 typedef typename hook_type::hooktags::node_traits node_traits;
0107 typedef typename node_traits::node node;
0108 typedef T value_type;
0109 typedef typename node_traits::node_ptr node_ptr;
0110 typedef typename node_traits::const_node_ptr const_node_ptr;
0111 typedef typename pointer_traits<node_ptr>::
0112 template rebind_pointer<T>::type pointer;
0113 typedef typename pointer_traits<node_ptr>::
0114 template rebind_pointer<const T>::type const_pointer;
0115 typedef T & reference;
0116 typedef const T & const_reference;
0117 typedef node& node_reference;
0118 typedef const node & const_node_reference;
0119 typedef hook_type& hook_reference;
0120 typedef const hook_type & const_hook_reference;
0121
0122 static const link_mode_type link_mode = Hook::hooktags::link_mode;
0123
0124 BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value)
0125 {
0126 return pointer_traits<node_ptr>::pointer_to
0127 (static_cast<node_reference>(static_cast<hook_reference>(value.*P)));
0128 }
0129
0130 BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value)
0131 {
0132 return pointer_traits<const_node_ptr>::pointer_to
0133 (static_cast<const_node_reference>(static_cast<const_hook_reference>(value.*P)));
0134 }
0135
0136 BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(node_ptr n)
0137 {
0138 return pointer_traits<pointer>::pointer_to
0139 (*detail::parent_from_member<T, Hook>
0140 (static_cast<Hook*>(boost::movelib::to_raw_pointer(n)), P));
0141 }
0142
0143 BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const_node_ptr n)
0144 {
0145 return pointer_traits<const_pointer>::pointer_to
0146 (*detail::parent_from_member<T, Hook>
0147 (static_cast<const Hook*>(boost::movelib::to_raw_pointer(n)), P));
0148 }
0149 };
0150
0151
0152 template<class Functor>
0153 struct fhtraits
0154 {
0155 public:
0156 typedef typename Functor::hook_type hook_type;
0157 typedef typename Functor::hook_ptr hook_ptr;
0158 typedef typename Functor::const_hook_ptr const_hook_ptr;
0159 typedef typename hook_type::hooktags::node_traits node_traits;
0160 typedef typename node_traits::node node;
0161 typedef typename Functor::value_type value_type;
0162 typedef typename node_traits::node_ptr node_ptr;
0163 typedef typename node_traits::const_node_ptr const_node_ptr;
0164 typedef typename pointer_traits<node_ptr>::
0165 template rebind_pointer<value_type>::type pointer;
0166 typedef typename pointer_traits<node_ptr>::
0167 template rebind_pointer<const value_type>::type const_pointer;
0168 typedef value_type & reference;
0169 typedef const value_type & const_reference;
0170 static const link_mode_type link_mode = hook_type::hooktags::link_mode;
0171
0172 static node_ptr to_node_ptr(reference value)
0173 { return static_cast<node*>(boost::movelib::to_raw_pointer(Functor::to_hook_ptr(value))); }
0174
0175 static const_node_ptr to_node_ptr(const_reference value)
0176 { return static_cast<const node*>(boost::movelib::to_raw_pointer(Functor::to_hook_ptr(value))); }
0177
0178 static pointer to_value_ptr(node_ptr n)
0179 { return Functor::to_value_ptr(to_hook_ptr(n)); }
0180
0181 static const_pointer to_value_ptr(const_node_ptr n)
0182 { return Functor::to_value_ptr(to_hook_ptr(n)); }
0183
0184 private:
0185 static hook_ptr to_hook_ptr(node_ptr n)
0186 { return hook_ptr(&*static_cast<hook_type*>(&*n)); }
0187
0188 static const_hook_ptr to_hook_ptr(const_node_ptr n)
0189 { return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); }
0190 };
0191
0192
0193 }
0194 }
0195
0196 #endif