1 // Boost.Geometry Index
3 // R-tree levels validating visitor implementation
5 // Copyright (c) 2011-2013 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_UTILITIES_ARE_LEVELS_OK_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_LEVELS_OK_HPP
14 #include <boost/geometry/index/detail/rtree/node/node.hpp>
16 namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
20 template <typename Value, typename Options, typename Box, typename Allocators>
22 : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
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;
28 inline are_levels_ok()
29 : result(true), m_leafs_level((std::numeric_limits<size_t>::max)()), m_current_level(0)
32 inline void operator()(internal_node const& n)
34 typedef typename rtree::elements_type<internal_node>::type elements_type;
35 elements_type const& elements = rtree::elements(n);
43 size_t current_level_backup = m_current_level;
46 for ( typename elements_type::const_iterator it = elements.begin();
47 it != elements.end() ; ++it)
49 rtree::apply_visitor(*this, *it->second);
51 if ( result == false )
55 m_current_level = current_level_backup;
58 inline void operator()(leaf const& n)
60 typedef typename rtree::elements_type<leaf>::type elements_type;
61 elements_type const& elements = rtree::elements(n);
63 // empty leaf in non-root node
64 if (0 < m_current_level && elements.empty())
70 if ( m_leafs_level == (std::numeric_limits<size_t>::max)() )
72 m_leafs_level = m_current_level;
74 else if ( m_leafs_level != m_current_level )
84 size_t m_current_level;
87 } // namespace visitors
89 template <typename Rtree> inline
90 bool are_levels_ok(Rtree const& tree)
92 typedef utilities::view<Rtree> RTV;
95 visitors::are_levels_ok<
96 typename RTV::value_type,
97 typename RTV::options_type,
98 typename RTV::box_type,
99 typename RTV::allocators_type
102 rtv.apply_visitor(v);
107 }}}}}} // namespace boost::geometry::index::detail::rtree::utilities
109 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_LEVELS_OK_HPP