member_value_traits.hpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2006-2013
  4. //
  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)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP
  13. #define BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <boost/intrusive/intrusive_fwd.hpp>
  16. #include <boost/intrusive/link_mode.hpp>
  17. #include <boost/intrusive/detail/parent_from_member.hpp>
  18. #include <boost/move/detail/to_raw_pointer.hpp>
  19. #include <boost/intrusive/pointer_traits.hpp>
  20. #if defined(BOOST_HAS_PRAGMA_ONCE)
  21. # pragma once
  22. #endif
  23. namespace boost {
  24. namespace intrusive {
  25. //!This value traits template is used to create value traits
  26. //!from user defined node traits where value_traits::value_type will
  27. //!store a node_traits::node
  28. template< class T, class NodeTraits
  29. , typename NodeTraits::node T::* PtrToMember
  30. , link_mode_type LinkMode
  31. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  32. = safe_link
  33. #endif
  34. >
  35. struct member_value_traits
  36. {
  37. public:
  38. typedef NodeTraits node_traits;
  39. typedef T value_type;
  40. typedef typename node_traits::node node;
  41. typedef typename node_traits::node_ptr node_ptr;
  42. typedef typename node_traits::const_node_ptr const_node_ptr;
  43. typedef pointer_traits<node_ptr> node_ptr_traits;
  44. typedef typename pointer_traits<node_ptr>::template
  45. rebind_pointer<T>::type pointer;
  46. typedef typename pointer_traits<node_ptr>::template
  47. rebind_pointer<const T>::type const_pointer;
  48. //typedef typename pointer_traits<pointer>::reference reference;
  49. //typedef typename pointer_traits<const_pointer>::reference const_reference;
  50. typedef value_type & reference;
  51. typedef const value_type & const_reference;
  52. static const link_mode_type link_mode = LinkMode;
  53. BOOST_INTRUSIVE_FORCEINLINE static node_ptr to_node_ptr(reference value) BOOST_NOEXCEPT
  54. { return pointer_traits<node_ptr>::pointer_to(value.*PtrToMember); }
  55. BOOST_INTRUSIVE_FORCEINLINE static const_node_ptr to_node_ptr(const_reference value) BOOST_NOEXCEPT
  56. { return pointer_traits<const_node_ptr>::pointer_to(value.*PtrToMember); }
  57. BOOST_INTRUSIVE_FORCEINLINE static pointer to_value_ptr(node_ptr n) BOOST_NOEXCEPT
  58. {
  59. return pointer_traits<pointer>::pointer_to(*detail::parent_from_member<value_type, node>
  60. (boost::movelib::to_raw_pointer(n), PtrToMember));
  61. }
  62. BOOST_INTRUSIVE_FORCEINLINE static const_pointer to_value_ptr(const_node_ptr n) BOOST_NOEXCEPT
  63. {
  64. return pointer_traits<const_pointer>::pointer_to(*detail::parent_from_member<value_type, node>
  65. (boost::movelib::to_raw_pointer(n), PtrToMember));
  66. }
  67. };
  68. } //namespace intrusive
  69. } //namespace boost
  70. #include <boost/intrusive/detail/config_end.hpp>
  71. #endif //BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP