Chris@102
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
2 //
|
Chris@102
|
3 // (C) Copyright Ion Gaztanaga 2014-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_NODE_TO_VALUE_HPP
|
Chris@102
|
14 #define BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_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/mpl.hpp>
|
Chris@102
|
26 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
|
Chris@102
|
27
|
Chris@102
|
28 namespace boost {
|
Chris@102
|
29 namespace intrusive {
|
Chris@102
|
30 namespace detail {
|
Chris@102
|
31
|
Chris@102
|
32 template<class VoidPointer>
|
Chris@102
|
33 struct dummy_constptr
|
Chris@102
|
34 {
|
Chris@102
|
35 typedef typename boost::intrusive::pointer_traits<VoidPointer>::
|
Chris@102
|
36 template rebind_pointer<const void>::type ConstVoidPtr;
|
Chris@102
|
37
|
Chris@102
|
38 explicit dummy_constptr(ConstVoidPtr)
|
Chris@102
|
39 {}
|
Chris@102
|
40
|
Chris@102
|
41 dummy_constptr()
|
Chris@102
|
42 {}
|
Chris@102
|
43
|
Chris@102
|
44 ConstVoidPtr get_ptr() const
|
Chris@102
|
45 { return ConstVoidPtr(); }
|
Chris@102
|
46 };
|
Chris@102
|
47
|
Chris@102
|
48 template<class VoidPointer>
|
Chris@102
|
49 struct constptr
|
Chris@102
|
50 {
|
Chris@102
|
51 typedef typename boost::intrusive::pointer_traits<VoidPointer>::
|
Chris@102
|
52 template rebind_pointer<const void>::type ConstVoidPtr;
|
Chris@102
|
53
|
Chris@102
|
54 constptr()
|
Chris@102
|
55 {}
|
Chris@102
|
56
|
Chris@102
|
57 explicit constptr(const ConstVoidPtr &ptr)
|
Chris@102
|
58 : const_void_ptr_(ptr)
|
Chris@102
|
59 {}
|
Chris@102
|
60
|
Chris@102
|
61 const void *get_ptr() const
|
Chris@102
|
62 { return boost::intrusive::detail::to_raw_pointer(const_void_ptr_); }
|
Chris@102
|
63
|
Chris@102
|
64 ConstVoidPtr const_void_ptr_;
|
Chris@102
|
65 };
|
Chris@102
|
66
|
Chris@102
|
67 template <class VoidPointer, bool store_ptr>
|
Chris@102
|
68 struct select_constptr
|
Chris@102
|
69 {
|
Chris@102
|
70 typedef typename if_c
|
Chris@102
|
71 < store_ptr
|
Chris@102
|
72 , constptr<VoidPointer>
|
Chris@102
|
73 , dummy_constptr<VoidPointer>
|
Chris@102
|
74 >::type type;
|
Chris@102
|
75 };
|
Chris@102
|
76
|
Chris@102
|
77
|
Chris@102
|
78 template<class ValueTraits, bool IsConst>
|
Chris@102
|
79 struct node_to_value
|
Chris@102
|
80 : public select_constptr
|
Chris@102
|
81 < typename pointer_traits
|
Chris@102
|
82 <typename ValueTraits::pointer>::template rebind_pointer<void>::type
|
Chris@102
|
83 , is_stateful_value_traits<ValueTraits>::value
|
Chris@102
|
84 >::type
|
Chris@102
|
85 {
|
Chris@102
|
86 static const bool stateful_value_traits = is_stateful_value_traits<ValueTraits>::value;
|
Chris@102
|
87 typedef typename select_constptr
|
Chris@102
|
88 < typename pointer_traits
|
Chris@102
|
89 <typename ValueTraits::pointer>::
|
Chris@102
|
90 template rebind_pointer<void>::type
|
Chris@102
|
91 , stateful_value_traits >::type Base;
|
Chris@102
|
92
|
Chris@102
|
93 typedef ValueTraits value_traits;
|
Chris@102
|
94 typedef typename value_traits::value_type value_type;
|
Chris@102
|
95 typedef typename value_traits::node_traits::node node;
|
Chris@102
|
96 typedef typename add_const_if_c
|
Chris@102
|
97 <value_type, IsConst>::type vtype;
|
Chris@102
|
98 typedef typename add_const_if_c
|
Chris@102
|
99 <node, IsConst>::type ntype;
|
Chris@102
|
100 typedef typename pointer_traits
|
Chris@102
|
101 <typename ValueTraits::pointer>::
|
Chris@102
|
102 template rebind_pointer<ntype>::type npointer;
|
Chris@102
|
103 typedef typename pointer_traits<npointer>::
|
Chris@102
|
104 template rebind_pointer<const ValueTraits>::type const_value_traits_ptr;
|
Chris@102
|
105
|
Chris@102
|
106 node_to_value(const const_value_traits_ptr &ptr)
|
Chris@102
|
107 : Base(ptr)
|
Chris@102
|
108 {}
|
Chris@102
|
109
|
Chris@102
|
110 typedef vtype & result_type;
|
Chris@102
|
111 typedef ntype & first_argument_type;
|
Chris@102
|
112
|
Chris@102
|
113 const_value_traits_ptr get_value_traits() const
|
Chris@102
|
114 { return pointer_traits<const_value_traits_ptr>::static_cast_from(Base::get_ptr()); }
|
Chris@102
|
115
|
Chris@102
|
116 result_type to_value(first_argument_type arg, false_) const
|
Chris@102
|
117 { return *(value_traits::to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); }
|
Chris@102
|
118
|
Chris@102
|
119 result_type to_value(first_argument_type arg, true_) const
|
Chris@102
|
120 { return *(this->get_value_traits()->to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); }
|
Chris@102
|
121
|
Chris@102
|
122 result_type operator()(first_argument_type arg) const
|
Chris@102
|
123 { return this->to_value(arg, bool_<stateful_value_traits>()); }
|
Chris@102
|
124 };
|
Chris@102
|
125
|
Chris@102
|
126 } //namespace detail{
|
Chris@102
|
127 } //namespace intrusive{
|
Chris@102
|
128 } //namespace boost{
|
Chris@102
|
129
|
Chris@102
|
130 #endif //BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP
|