File indexing completed on 2025-01-18 09:35:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COUNT_HPP
0017 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COUNT_HPP
0018
0019 #include <boost/geometry/index/equal_to.hpp>
0020 #include <boost/geometry/index/detail/algorithms/bounds.hpp>
0021 #include <boost/geometry/index/detail/rtree/node/node_elements.hpp>
0022 #include <boost/geometry/index/detail/rtree/node/variant_visitor.hpp>
0023 #include <boost/geometry/index/parameters.hpp>
0024
0025 namespace boost { namespace geometry { namespace index {
0026
0027 namespace detail { namespace rtree { namespace visitors {
0028
0029 template <typename Indexable, typename Value>
0030 struct count_helper
0031 {
0032 template <typename Translator>
0033 static inline typename Translator::result_type indexable(Indexable const& i, Translator const&)
0034 {
0035 return i;
0036 }
0037 template <typename Translator, typename Strategy>
0038 static inline bool equals(Indexable const& i, Value const& v, Translator const& tr, Strategy const& s)
0039 {
0040 return index::detail::equals<Indexable>::apply(i, tr(v), s);
0041 }
0042 };
0043
0044 template <typename Value>
0045 struct count_helper<Value, Value>
0046 {
0047 template <typename Translator>
0048 static inline typename Translator::result_type indexable(Value const& v, Translator const& tr)
0049 {
0050 return tr(v);
0051 }
0052 template <typename Translator, typename Strategy>
0053 static inline bool equals(Value const& v1, Value const& v2, Translator const& tr, Strategy const& s)
0054 {
0055 return tr.equals(v1, v2, s);
0056 }
0057 };
0058
0059 template <typename ValueOrIndexable, typename MembersHolder>
0060 struct count
0061 : public MembersHolder::visitor_const
0062 {
0063 typedef typename MembersHolder::value_type value_type;
0064 typedef typename MembersHolder::parameters_type parameters_type;
0065 typedef typename MembersHolder::translator_type translator_type;
0066
0067 typedef typename MembersHolder::node node;
0068 typedef typename MembersHolder::internal_node internal_node;
0069 typedef typename MembersHolder::leaf leaf;
0070
0071 typedef count_helper<ValueOrIndexable, value_type> count_help;
0072
0073 inline count(ValueOrIndexable const& vori, parameters_type const& parameters, translator_type const& t)
0074 : value_or_indexable(vori), m_parameters(parameters), tr(t), found_count(0)
0075 {}
0076
0077 inline void operator()(internal_node const& n)
0078 {
0079 typedef typename rtree::elements_type<internal_node>::type elements_type;
0080 elements_type const& elements = rtree::elements(n);
0081
0082
0083 for (typename elements_type::const_iterator it = elements.begin();
0084 it != elements.end(); ++it)
0085 {
0086 if ( index::detail::covered_by_bounds(count_help::indexable(value_or_indexable, tr),
0087 it->first,
0088 index::detail::get_strategy(m_parameters)) )
0089 {
0090 rtree::apply_visitor(*this, *it->second);
0091 }
0092 }
0093 }
0094
0095 inline void operator()(leaf const& n)
0096 {
0097 typedef typename rtree::elements_type<leaf>::type elements_type;
0098 elements_type const& elements = rtree::elements(n);
0099
0100
0101 for (typename elements_type::const_iterator it = elements.begin();
0102 it != elements.end(); ++it)
0103 {
0104
0105 if ( count_help::equals(value_or_indexable, *it, tr,
0106 index::detail::get_strategy(m_parameters)) )
0107 {
0108 ++found_count;
0109 }
0110 }
0111 }
0112
0113 ValueOrIndexable const& value_or_indexable;
0114 parameters_type const& m_parameters;
0115 translator_type const& tr;
0116 typename MembersHolder::size_type found_count;
0117 };
0118
0119 }}}
0120
0121 }}}
0122
0123 #endif