1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2013
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_MEMBER_VALUE_TRAITS_HPP
14 #define BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP
16 #include <boost/intrusive/detail/config_begin.hpp>
17 #include <boost/intrusive/intrusive_fwd.hpp>
19 #include <boost/intrusive/link_mode.hpp>
20 #include <boost/intrusive/detail/parent_from_member.hpp>
21 #include <boost/intrusive/pointer_traits.hpp>
23 #if defined(BOOST_HAS_PRAGMA_ONCE)
30 //!This value traits template is used to create value traits
31 //!from user defined node traits where value_traits::value_type will
32 //!store a node_traits::node
33 template< class T, class NodeTraits
34 , typename NodeTraits::node T::* PtrToMember
35 , link_mode_type LinkMode
36 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
40 struct member_value_traits
43 typedef NodeTraits node_traits;
45 typedef typename node_traits::node node;
46 typedef typename node_traits::node_ptr node_ptr;
47 typedef typename node_traits::const_node_ptr const_node_ptr;
48 typedef pointer_traits<node_ptr> node_ptr_traits;
49 typedef typename pointer_traits<node_ptr>::template
50 rebind_pointer<T>::type pointer;
51 typedef typename pointer_traits<node_ptr>::template
52 rebind_pointer<const T>::type const_pointer;
53 //typedef typename pointer_traits<pointer>::reference reference;
54 //typedef typename pointer_traits<const_pointer>::reference const_reference;
55 typedef value_type & reference;
56 typedef const value_type & const_reference;
57 static const link_mode_type link_mode = LinkMode;
59 BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value)
60 { return pointer_traits<node_ptr>::pointer_to(value.*PtrToMember); }
62 BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value)
63 { return pointer_traits<const_node_ptr>::pointer_to(value.*PtrToMember); }
65 BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(const node_ptr &n)
67 return pointer_traits<pointer>::pointer_to(*detail::parent_from_member<value_type, node>
68 (boost::intrusive::detail::to_raw_pointer(n), PtrToMember));
71 BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const const_node_ptr &n)
73 return pointer_traits<const_pointer>::pointer_to(*detail::parent_from_member<value_type, node>
74 (boost::intrusive::detail::to_raw_pointer(n), PtrToMember));
79 } //namespace intrusive
82 #include <boost/intrusive/detail/config_end.hpp>
84 #endif //BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP