slist_iterator.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Olaf Krzikalla 2004-2006.
  4. // (C) Copyright Ion Gaztanaga 2006-2013
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/intrusive for documentation.
  11. //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef BHO_INTRUSIVE_SLIST_ITERATOR_HPP
  14. #define BHO_INTRUSIVE_SLIST_ITERATOR_HPP
  15. #ifndef BHO_CONFIG_HPP
  16. # include <asio2/bho/config.hpp>
  17. #endif
  18. #if defined(BHO_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. #include <asio2/bho/intrusive/detail/config_begin.hpp>
  22. #include <asio2/bho/intrusive/detail/workaround.hpp>
  23. #include <asio2/bho/intrusive/detail/std_fwd.hpp>
  24. #include <asio2/bho/intrusive/detail/iiterator.hpp>
  25. #include <asio2/bho/intrusive/detail/mpl.hpp>
  26. #include <asio2/bho/static_assert.hpp>
  27. namespace bho {
  28. namespace intrusive {
  29. // slist_iterator provides some basic functions for a
  30. // node oriented bidirectional iterator:
  31. template<class ValueTraits, bool IsConst>
  32. class slist_iterator
  33. {
  34. private:
  35. typedef iiterator
  36. <ValueTraits, IsConst, std::forward_iterator_tag> types_t;
  37. static const bool stateful_value_traits = types_t::stateful_value_traits;
  38. typedef ValueTraits value_traits;
  39. typedef typename types_t::node_traits node_traits;
  40. typedef typename types_t::node node;
  41. typedef typename types_t::node_ptr node_ptr;
  42. typedef typename types_t::const_value_traits_ptr const_value_traits_ptr;
  43. class nat;
  44. typedef typename
  45. detail::if_c< IsConst
  46. , slist_iterator<value_traits, false>
  47. , nat>::type nonconst_iterator;
  48. public:
  49. typedef typename types_t::iterator_type::difference_type difference_type;
  50. typedef typename types_t::iterator_type::value_type value_type;
  51. typedef typename types_t::iterator_type::pointer pointer;
  52. typedef typename types_t::iterator_type::reference reference;
  53. typedef typename types_t::iterator_type::iterator_category iterator_category;
  54. BHO_INTRUSIVE_FORCEINLINE slist_iterator()
  55. {}
  56. BHO_INTRUSIVE_FORCEINLINE slist_iterator(node_ptr nodeptr, const_value_traits_ptr traits_ptr)
  57. : members_(nodeptr, traits_ptr)
  58. {}
  59. BHO_INTRUSIVE_FORCEINLINE explicit slist_iterator(node_ptr nodeptr)
  60. : members_(nodeptr, const_value_traits_ptr())
  61. { BHO_STATIC_ASSERT((stateful_value_traits == false)); }
  62. BHO_INTRUSIVE_FORCEINLINE slist_iterator(const slist_iterator &other)
  63. : members_(other.pointed_node(), other.get_value_traits())
  64. {}
  65. BHO_INTRUSIVE_FORCEINLINE slist_iterator(const nonconst_iterator &other)
  66. : members_(other.pointed_node(), other.get_value_traits())
  67. {}
  68. BHO_INTRUSIVE_FORCEINLINE slist_iterator &operator=(const slist_iterator &other)
  69. { members_.nodeptr_ = other.members_.nodeptr_; return *this; }
  70. BHO_INTRUSIVE_FORCEINLINE node_ptr pointed_node() const
  71. { return members_.nodeptr_; }
  72. BHO_INTRUSIVE_FORCEINLINE slist_iterator &operator=(node_ptr n)
  73. { members_.nodeptr_ = n; return static_cast<slist_iterator&>(*this); }
  74. BHO_INTRUSIVE_FORCEINLINE const_value_traits_ptr get_value_traits() const
  75. { return members_.get_ptr(); }
  76. BHO_INTRUSIVE_FORCEINLINE bool operator!() const
  77. { return !members_.nodeptr_; }
  78. public:
  79. BHO_INTRUSIVE_FORCEINLINE slist_iterator& operator++()
  80. {
  81. members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
  82. return static_cast<slist_iterator&> (*this);
  83. }
  84. BHO_INTRUSIVE_FORCEINLINE slist_iterator operator++(int)
  85. {
  86. slist_iterator result (*this);
  87. members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
  88. return result;
  89. }
  90. BHO_INTRUSIVE_FORCEINLINE friend bool operator== (const slist_iterator& l, const slist_iterator& r)
  91. { return l.pointed_node() == r.pointed_node(); }
  92. BHO_INTRUSIVE_FORCEINLINE friend bool operator!= (const slist_iterator& l, const slist_iterator& r)
  93. { return l.pointed_node() != r.pointed_node(); }
  94. BHO_INTRUSIVE_FORCEINLINE reference operator*() const
  95. { return *operator->(); }
  96. BHO_INTRUSIVE_FORCEINLINE pointer operator->() const
  97. { return this->operator_arrow(detail::bool_<stateful_value_traits>()); }
  98. BHO_INTRUSIVE_FORCEINLINE slist_iterator<ValueTraits, false> unconst() const
  99. { return slist_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); }
  100. private:
  101. BHO_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::false_) const
  102. { return ValueTraits::to_value_ptr(members_.nodeptr_); }
  103. BHO_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::true_) const
  104. { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); }
  105. iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_;
  106. };
  107. } //namespace intrusive
  108. } //namespace bho
  109. #include <asio2/bho/intrusive/detail/config_end.hpp>
  110. #endif //BHO_INTRUSIVE_SLIST_ITERATOR_HPP