derivation_value_traits.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_DERIVATION_VALUE_TRAITS_HPP
  13. #define BOOST_INTRUSIVE_DERIVATION_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/pointer_traits.hpp>
  18. #if defined(BOOST_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. namespace boost {
  22. namespace intrusive {
  23. //!This value traits template is used to create value traits
  24. //!from user defined node traits where value_traits::value_type will
  25. //!derive from node_traits::node
  26. template<class T, class NodeTraits, link_mode_type LinkMode
  27. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  28. = safe_link
  29. #endif
  30. >
  31. struct derivation_value_traits
  32. {
  33. public:
  34. typedef NodeTraits node_traits;
  35. typedef T value_type;
  36. typedef typename node_traits::node node;
  37. typedef typename node_traits::node_ptr node_ptr;
  38. typedef typename node_traits::const_node_ptr const_node_ptr;
  39. typedef typename pointer_traits<node_ptr>::
  40. template rebind_pointer<value_type>::type pointer;
  41. typedef typename pointer_traits<node_ptr>::
  42. template rebind_pointer<const value_type>::type const_pointer;
  43. typedef typename boost::intrusive::
  44. pointer_traits<pointer>::reference reference;
  45. typedef typename boost::intrusive::
  46. pointer_traits<const_pointer>::reference const_reference;
  47. static const link_mode_type link_mode = LinkMode;
  48. static node_ptr to_node_ptr(reference value)
  49. { return node_ptr(&value); }
  50. static const_node_ptr to_node_ptr(const_reference value)
  51. { return node_ptr(&value); }
  52. static pointer to_value_ptr(const node_ptr &n)
  53. {
  54. return pointer_traits<pointer>::pointer_to(static_cast<reference>(*n));
  55. }
  56. static const_pointer to_value_ptr(const const_node_ptr &n)
  57. {
  58. return pointer_traits<const_pointer>::pointer_to(static_cast<const_reference>(*n));
  59. }
  60. };
  61. } //namespace intrusive
  62. } //namespace boost
  63. #include <boost/intrusive/detail/config_end.hpp>
  64. #endif //BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP