1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2014-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_NODE_TO_VALUE_HPP
14 #define BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP
20 #include <boost/intrusive/pointer_traits.hpp>
21 #include <boost/intrusive/detail/mpl.hpp>
22 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
28 template<class VoidPointer>
31 typedef typename boost::intrusive::pointer_traits<VoidPointer>::
32 template rebind_pointer<const void>::type ConstVoidPtr;
34 explicit dummy_constptr(ConstVoidPtr)
40 ConstVoidPtr get_ptr() const
41 { return ConstVoidPtr(); }
44 template<class VoidPointer>
47 typedef typename boost::intrusive::pointer_traits<VoidPointer>::
48 template rebind_pointer<const void>::type ConstVoidPtr;
53 explicit constptr(const ConstVoidPtr &ptr)
54 : const_void_ptr_(ptr)
57 const void *get_ptr() const
58 { return boost::intrusive::detail::to_raw_pointer(const_void_ptr_); }
60 ConstVoidPtr const_void_ptr_;
63 template <class VoidPointer, bool store_ptr>
64 struct select_constptr
68 , constptr<VoidPointer>
69 , dummy_constptr<VoidPointer>
74 template<class ValueTraits, bool IsConst>
76 : public select_constptr
77 < typename pointer_traits
78 <typename ValueTraits::pointer>::template rebind_pointer<void>::type
79 , is_stateful_value_traits<ValueTraits>::value
82 static const bool stateful_value_traits = is_stateful_value_traits<ValueTraits>::value;
83 typedef typename select_constptr
84 < typename pointer_traits
85 <typename ValueTraits::pointer>::
86 template rebind_pointer<void>::type
87 , stateful_value_traits >::type Base;
89 typedef ValueTraits value_traits;
90 typedef typename value_traits::value_type value_type;
91 typedef typename value_traits::node_traits::node node;
92 typedef typename add_const_if_c
93 <value_type, IsConst>::type vtype;
94 typedef typename add_const_if_c
95 <node, IsConst>::type ntype;
96 typedef typename pointer_traits
97 <typename ValueTraits::pointer>::
98 template rebind_pointer<ntype>::type npointer;
99 typedef typename pointer_traits<npointer>::
100 template rebind_pointer<const ValueTraits>::type const_value_traits_ptr;
102 node_to_value(const const_value_traits_ptr &ptr)
106 typedef vtype & result_type;
107 typedef ntype & first_argument_type;
109 const_value_traits_ptr get_value_traits() const
110 { return pointer_traits<const_value_traits_ptr>::static_cast_from(Base::get_ptr()); }
112 result_type to_value(first_argument_type arg, false_) const
113 { return *(value_traits::to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); }
115 result_type to_value(first_argument_type arg, true_) const
116 { return *(this->get_value_traits()->to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); }
118 result_type operator()(first_argument_type arg) const
119 { return this->to_value(arg, bool_<stateful_value_traits>()); }
122 } //namespace detail{
123 } //namespace intrusive{
126 #endif //BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP