default_header_holder.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014
  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_DETAIL_DEFAULT_HEADER_HOLDER_HPP
  13. #define BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #if defined(BOOST_HAS_PRAGMA_ONCE)
  18. # pragma once
  19. #endif
  20. #include <boost/intrusive/detail/workaround.hpp>
  21. #include <boost/intrusive/pointer_traits.hpp>
  22. #include <boost/move/detail/to_raw_pointer.hpp>
  23. namespace boost {
  24. namespace intrusive {
  25. namespace detail {
  26. // trivial header node holder
  27. template < typename NodeTraits >
  28. struct default_header_holder : public NodeTraits::node
  29. {
  30. typedef NodeTraits node_traits;
  31. typedef typename node_traits::node node;
  32. typedef typename node_traits::node_ptr node_ptr;
  33. typedef typename node_traits::const_node_ptr const_node_ptr;
  34. default_header_holder() : node() {}
  35. BOOST_INTRUSIVE_FORCEINLINE const_node_ptr get_node() const
  36. { return pointer_traits< const_node_ptr >::pointer_to(*static_cast< const node* >(this)); }
  37. BOOST_INTRUSIVE_FORCEINLINE node_ptr get_node()
  38. { return pointer_traits< node_ptr >::pointer_to(*static_cast< node* >(this)); }
  39. // (unsafe) downcast used to implement container-from-iterator
  40. BOOST_INTRUSIVE_FORCEINLINE static default_header_holder* get_holder(const node_ptr &p)
  41. { return static_cast< default_header_holder* >(boost::movelib::to_raw_pointer(p)); }
  42. };
  43. // type function producing the header node holder
  44. template < typename ValueTraits, typename HeaderHolder >
  45. struct get_header_holder_type
  46. {
  47. typedef HeaderHolder type;
  48. };
  49. template < typename ValueTraits >
  50. struct get_header_holder_type< ValueTraits, void >
  51. {
  52. typedef default_header_holder< typename ValueTraits::node_traits > type;
  53. };
  54. } //namespace detail
  55. } //namespace intrusive
  56. } //namespace boost
  57. #endif //BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP