1 // Boost.Geometry Index
3 // R-tree iterator visitor implementation
5 // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
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)
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_ITERATOR_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_ITERATOR_HPP
14 namespace boost { namespace geometry { namespace index {
16 namespace detail { namespace rtree { namespace visitors {
18 template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
20 : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
23 typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
24 typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
25 typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
27 typedef typename Allocators::size_type size_type;
28 typedef typename Allocators::const_reference const_reference;
29 typedef typename Allocators::node_pointer node_pointer;
31 typedef typename rtree::elements_type<internal_node>::type::const_iterator internal_iterator;
32 typedef typename rtree::elements_type<leaf>::type leaf_elements;
33 typedef typename rtree::elements_type<leaf>::type::const_iterator leaf_iterator;
40 inline void operator()(internal_node const& n)
42 typedef typename rtree::elements_type<internal_node>::type elements_type;
43 elements_type const& elements = rtree::elements(n);
45 m_internal_stack.push_back(std::make_pair(elements.begin(), elements.end()));
48 inline void operator()(leaf const& n)
50 m_values = ::boost::addressof(rtree::elements(n));
51 m_current = rtree::elements(n).begin();
54 const_reference dereference() const
56 BOOST_GEOMETRY_INDEX_ASSERT(m_values, "not dereferencable");
60 void initialize(node_pointer root)
62 rtree::apply_visitor(*this, *root);
76 // if leaf is choosen, move to the next value in leaf
79 // there are more values in the current leaf
80 if ( m_current != m_values->end() )
84 // no more values, clear current leaf
90 // if leaf isn't choosen, move to the next leaf
93 // return if there is no more nodes to traverse
94 if ( m_internal_stack.empty() )
97 // no more children in current node, remove it from stack
98 if ( m_internal_stack.back().first == m_internal_stack.back().second )
100 m_internal_stack.pop_back();
104 internal_iterator it = m_internal_stack.back().first;
105 ++m_internal_stack.back().first;
107 // push the next node to the stack
108 rtree::apply_visitor(*this, *(it->second));
115 return 0 == m_values;
118 friend bool operator==(iterator const& l, iterator const& r)
120 return (l.m_values == r.m_values) && (0 == l.m_values || l.m_current == r.m_current );
125 std::vector< std::pair<internal_iterator, internal_iterator> > m_internal_stack;
126 const leaf_elements * m_values;
127 leaf_iterator m_current;
130 }}} // namespace detail::rtree::visitors
132 }}} // namespace boost::geometry::index
134 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_ITERATOR_HPP