iterators.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Boost.Geometry Index
  2. //
  3. // R-tree iterators
  4. //
  5. // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2021.
  8. // Modifications copyright (c) 2021 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. //
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_ITERATORS_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_ITERATORS_HPP
  16. #include <iterator>
  17. #include <boost/geometry/index/detail/rtree/visitors/iterator.hpp>
  18. namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace iterators {
  19. template <typename Value, typename Allocators>
  20. struct end_iterator
  21. {
  22. typedef std::forward_iterator_tag iterator_category;
  23. typedef Value value_type;
  24. typedef typename Allocators::const_reference reference;
  25. typedef typename Allocators::difference_type difference_type;
  26. typedef typename Allocators::const_pointer pointer;
  27. reference operator*() const
  28. {
  29. BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not dereferencable");
  30. pointer p(0);
  31. return *p;
  32. }
  33. const value_type * operator->() const
  34. {
  35. BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not dereferencable");
  36. const value_type * p = 0;
  37. return p;
  38. }
  39. end_iterator & operator++()
  40. {
  41. BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not incrementable");
  42. return *this;
  43. }
  44. end_iterator operator++(int)
  45. {
  46. BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not incrementable");
  47. return *this;
  48. }
  49. friend bool operator==(end_iterator const& /*l*/, end_iterator const& /*r*/)
  50. {
  51. return true;
  52. }
  53. };
  54. template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
  55. class iterator
  56. {
  57. typedef visitors::iterator<Value, Options, Translator, Box, Allocators> visitor_type;
  58. typedef typename visitor_type::node_pointer node_pointer;
  59. public:
  60. typedef std::forward_iterator_tag iterator_category;
  61. typedef Value value_type;
  62. typedef typename Allocators::const_reference reference;
  63. typedef typename Allocators::difference_type difference_type;
  64. typedef typename Allocators::const_pointer pointer;
  65. inline iterator()
  66. {}
  67. inline iterator(node_pointer root)
  68. {
  69. m_visitor.initialize(root);
  70. }
  71. reference operator*() const
  72. {
  73. return m_visitor.dereference();
  74. }
  75. const value_type * operator->() const
  76. {
  77. return boost::addressof(m_visitor.dereference());
  78. }
  79. iterator & operator++()
  80. {
  81. m_visitor.increment();
  82. return *this;
  83. }
  84. iterator operator++(int)
  85. {
  86. iterator temp = *this;
  87. this->operator++();
  88. return temp;
  89. }
  90. friend bool operator==(iterator const& l, iterator const& r)
  91. {
  92. return l.m_visitor == r.m_visitor;
  93. }
  94. friend bool operator==(iterator const& l, end_iterator<Value, Allocators> const& /*r*/)
  95. {
  96. return l.m_visitor.is_end();
  97. }
  98. friend bool operator==(end_iterator<Value, Allocators> const& /*l*/, iterator const& r)
  99. {
  100. return r.m_visitor.is_end();
  101. }
  102. private:
  103. visitor_type m_visitor;
  104. };
  105. }}}}}} // namespace boost::geometry::index::detail::rtree::iterators
  106. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_ITERATORS_HPP