1 // Boost.Geometry Index
3 // R-tree count visitor implementation
5 // Copyright (c) 2011-2014 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_COUNT_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COUNT_HPP
14 namespace boost { namespace geometry { namespace index {
16 namespace detail { namespace rtree { namespace visitors {
18 template <typename Indexable, typename Value>
21 template <typename Translator>
22 static inline typename Translator::result_type indexable(Indexable const& i, Translator const&)
26 template <typename Translator>
27 static inline bool equals(Indexable const& i, Value const& v, Translator const& tr)
29 return geometry::equals(i, tr(v));
33 template <typename Value>
34 struct count_helper<Value, Value>
36 template <typename Translator>
37 static inline typename Translator::result_type indexable(Value const& v, Translator const& tr)
41 template <typename Translator>
42 static inline bool equals(Value const& v1, Value const& v2, Translator const& tr)
44 return tr.equals(v1, v2);
48 template <typename ValueOrIndexable, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
50 : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
52 typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
53 typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
54 typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
56 typedef count_helper<ValueOrIndexable, Value> count_help;
58 inline count(ValueOrIndexable const& vori, Translator const& t)
59 : value_or_indexable(vori), tr(t), found_count(0)
62 inline void operator()(internal_node const& n)
64 typedef typename rtree::elements_type<internal_node>::type elements_type;
65 elements_type const& elements = rtree::elements(n);
67 // traverse nodes meeting predicates
68 for (typename elements_type::const_iterator it = elements.begin();
69 it != elements.end(); ++it)
71 if ( geometry::covered_by(
73 count_help::indexable(value_or_indexable, tr)),
76 rtree::apply_visitor(*this, *it->second);
81 inline void operator()(leaf const& n)
83 typedef typename rtree::elements_type<leaf>::type elements_type;
84 elements_type const& elements = rtree::elements(n);
86 // get all values meeting predicates
87 for (typename elements_type::const_iterator it = elements.begin();
88 it != elements.end(); ++it)
90 // if value meets predicates
91 if ( count_help::equals(value_or_indexable, *it, tr) )
98 ValueOrIndexable const& value_or_indexable;
100 typename Allocators::size_type found_count;
103 }}} // namespace detail::rtree::visitors
105 }}} // namespace boost::geometry::index
107 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COUNT_HPP