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