iiterator.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2006-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_IITERATOR_HPP
  13. #define BOOST_INTRUSIVE_DETAIL_IITERATOR_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/detail/iterator.hpp>
  22. #include <boost/intrusive/pointer_traits.hpp>
  23. #include <boost/intrusive/detail/mpl.hpp>
  24. #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
  25. namespace boost {
  26. namespace intrusive {
  27. template<class ValueTraits>
  28. struct value_traits_pointers
  29. {
  30. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
  31. (boost::intrusive::detail::
  32. , ValueTraits, value_traits_ptr
  33. , typename boost::intrusive::pointer_traits<typename ValueTraits::node_traits::node_ptr>::template
  34. rebind_pointer<ValueTraits>::type) value_traits_ptr;
  35. typedef typename boost::intrusive::pointer_traits<value_traits_ptr>::template
  36. rebind_pointer<ValueTraits const>::type const_value_traits_ptr;
  37. };
  38. template<class ValueTraits, bool IsConst, class Category>
  39. struct iiterator
  40. {
  41. typedef ValueTraits value_traits;
  42. typedef typename value_traits::node_traits node_traits;
  43. typedef typename node_traits::node node;
  44. typedef typename node_traits::node_ptr node_ptr;
  45. typedef ::boost::intrusive::pointer_traits<node_ptr> nodepointer_traits_t;
  46. typedef typename nodepointer_traits_t::template
  47. rebind_pointer<void>::type void_pointer;
  48. typedef typename ValueTraits::value_type value_type;
  49. typedef typename ValueTraits::pointer nonconst_pointer;
  50. typedef typename ValueTraits::const_pointer yesconst_pointer;
  51. typedef typename ::boost::intrusive::pointer_traits
  52. <nonconst_pointer>::reference nonconst_reference;
  53. typedef typename ::boost::intrusive::pointer_traits
  54. <yesconst_pointer>::reference yesconst_reference;
  55. typedef typename nodepointer_traits_t::difference_type difference_type;
  56. typedef typename detail::if_c
  57. <IsConst, yesconst_pointer, nonconst_pointer>::type pointer;
  58. typedef typename detail::if_c
  59. <IsConst, yesconst_reference, nonconst_reference>::type reference;
  60. typedef iterator
  61. < Category
  62. , value_type
  63. , difference_type
  64. , pointer
  65. , reference
  66. > iterator_type;
  67. typedef typename value_traits_pointers
  68. <ValueTraits>::value_traits_ptr value_traits_ptr;
  69. typedef typename value_traits_pointers
  70. <ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
  71. static const bool stateful_value_traits =
  72. detail::is_stateful_value_traits<value_traits>::value;
  73. };
  74. template<class NodePtr, class StoredPointer, bool StatefulValueTraits = true>
  75. struct iiterator_members
  76. {
  77. BOOST_INTRUSIVE_FORCEINLINE iiterator_members()
  78. : nodeptr_()//Value initialization to achieve "null iterators" (N3644)
  79. {}
  80. BOOST_INTRUSIVE_FORCEINLINE iiterator_members(const NodePtr &n_ptr, const StoredPointer &data)
  81. : nodeptr_(n_ptr), ptr_(data)
  82. {}
  83. BOOST_INTRUSIVE_FORCEINLINE StoredPointer get_ptr() const
  84. { return ptr_; }
  85. NodePtr nodeptr_;
  86. StoredPointer ptr_;
  87. };
  88. template<class NodePtr, class StoredPointer>
  89. struct iiterator_members<NodePtr, StoredPointer, false>
  90. {
  91. BOOST_INTRUSIVE_FORCEINLINE iiterator_members()
  92. : nodeptr_()//Value initialization to achieve "null iterators" (N3644)
  93. {}
  94. BOOST_INTRUSIVE_FORCEINLINE iiterator_members(const NodePtr &n_ptr, const StoredPointer &)
  95. : nodeptr_(n_ptr)
  96. {}
  97. BOOST_INTRUSIVE_FORCEINLINE StoredPointer get_ptr() const
  98. { return StoredPointer(); }
  99. NodePtr nodeptr_;
  100. };
  101. } //namespace intrusive
  102. } //namespace boost
  103. #endif //BOOST_INTRUSIVE_DETAIL_IITERATOR_HPP