From fb25dff48eac2562c07de905834e399df6a232cc Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Fri, 25 Jan 2013 18:43:48 +0000 Subject: [PATCH] Added rtree free function insert. Added adaptors::queried(). nearest_query_range and spatial_query_range moved to adaptors::detail. [SVN r82611] --- .../geometry/index/adaptors/nearest_query.hpp | 8 +- .../boost/geometry/index/adaptors/query.hpp | 88 +++++++++++++++++++ .../geometry/index/adaptors/spatial_query.hpp | 8 +- .../geometry/index/detail/rtree/adaptors.hpp | 29 +++++- include/boost/geometry/index/rtree.hpp | 18 ++++ 5 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 include/boost/geometry/index/adaptors/query.hpp diff --git a/include/boost/geometry/index/adaptors/nearest_query.hpp b/include/boost/geometry/index/adaptors/nearest_query.hpp index fd86465eb..9c042ac85 100644 --- a/include/boost/geometry/index/adaptors/nearest_query.hpp +++ b/include/boost/geometry/index/adaptors/nearest_query.hpp @@ -19,6 +19,8 @@ namespace boost { namespace geometry { namespace index { namespace adaptors { +namespace detail { + template class nearest_query_range { @@ -45,8 +47,6 @@ class nearest_query_range inline const_iterator end() const { return 0; } }; -namespace detail { - // TODO: awulkiew - consider removing references from predicates template @@ -108,12 +108,12 @@ nearest_queried( } // namespace adaptors template -index::adaptors::nearest_query_range +index::adaptors::detail::nearest_query_range operator|( Index const& si, index::adaptors::detail::nearest_query const& f) { - return index::adaptors::nearest_query_range( + return index::adaptors::detail::nearest_query_range( si, f.distances_predicates, f.count, f.predicates); } diff --git a/include/boost/geometry/index/adaptors/query.hpp b/include/boost/geometry/index/adaptors/query.hpp new file mode 100644 index 000000000..d1647bcb6 --- /dev/null +++ b/include/boost/geometry/index/adaptors/query.hpp @@ -0,0 +1,88 @@ +// Boost.Geometry Index +// +// Query range adaptor +// +// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. +// +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_INDEX_ADAPTORS_QUERY_HPP +#define BOOST_GEOMETRY_INDEX_ADAPTORS_QUERY_HPP + +/*! +\defgroup adaptors Adaptors (boost::geometry::index::adaptors::) +*/ + +namespace boost { namespace geometry { namespace index { + +namespace adaptors { + +namespace detail { + +template +class query_range +{ + BOOST_MPL_ASSERT_MSG( + (false), + NOT_IMPLEMENTED_FOR_THIS_INDEX, + (query_range)); + + typedef int* iterator; + typedef const int* const_iterator; + + template + inline query_range( + Index const&, + Predicates const&) + {} + + inline iterator begin() { return 0; } + inline iterator end() { return 0; } + inline const_iterator begin() const { return 0; } + inline const_iterator end() const { return 0; } +}; + +// TODO: awulkiew - consider removing reference from predicates + +template +struct query +{ + inline explicit query(Predicates const& pred) + : predicates(pred) + {} + + Predicates const& predicates; +}; + +} // namespace detail + +/*! +\brief The query index adaptor generator. + +\ingroup adaptors + +\param pred Predicates. +*/ +template +detail::query +queried(Predicates const& pred) +{ + return detail::query(pred); +} + +} // namespace adaptors + +template +index::adaptors::detail::query_range +operator|( + Index const& si, + index::adaptors::detail::query const& f) +{ + return index::adaptors::detail::query_range(si, f.predicates); +} + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_INDEX_ADAPTORS_QUERY_HPP diff --git a/include/boost/geometry/index/adaptors/spatial_query.hpp b/include/boost/geometry/index/adaptors/spatial_query.hpp index 46331e02d..ef84fd325 100644 --- a/include/boost/geometry/index/adaptors/spatial_query.hpp +++ b/include/boost/geometry/index/adaptors/spatial_query.hpp @@ -19,6 +19,8 @@ namespace boost { namespace geometry { namespace index { namespace adaptors { +namespace detail { + template class spatial_query_range { @@ -42,8 +44,6 @@ class spatial_query_range inline const_iterator end() const { return 0; } }; -namespace detail { - // TODO: awulkiew - consider removing reference from predicates template @@ -75,12 +75,12 @@ spatial_queried(Predicates const& pred) } // namespace adaptors template -index::adaptors::spatial_query_range +index::adaptors::detail::spatial_query_range operator|( Index const& si, index::adaptors::detail::spatial_query const& f) { - return index::adaptors::spatial_query_range(si, f.predicates); + return index::adaptors::detail::spatial_query_range(si, f.predicates); } }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/index/detail/rtree/adaptors.hpp b/include/boost/geometry/index/detail/rtree/adaptors.hpp index 0066766df..c9c160394 100644 --- a/include/boost/geometry/index/detail/rtree/adaptors.hpp +++ b/include/boost/geometry/index/detail/rtree/adaptors.hpp @@ -16,13 +16,14 @@ #include #include +#include namespace boost { namespace geometry { namespace index { template class rtree; -namespace adaptors { +namespace adaptors { namespace detail { template class spatial_query_range< index::rtree > @@ -78,7 +79,31 @@ private: result_type m_result; }; -} // namespace adaptors +template +class query_range< index::rtree > +{ +public: + typedef std::vector result_type; + typedef typename result_type::iterator iterator; + typedef typename result_type::const_iterator const_iterator; + + template inline + query_range(index::rtree const& rtree, + Predicates const& pred) + { + rtree.query(pred, std::back_inserter(m_result)); + } + + inline iterator begin() { return m_result.begin(); } + inline iterator end() { return m_result.end(); } + inline const_iterator begin() const { return m_result.begin(); } + inline const_iterator end() const { return m_result.end(); } + +private: + result_type m_result; +}; + +}} // namespace adaptors::detail }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index b6c7734cb..4c283abba 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -1461,6 +1461,24 @@ remove(rtree & tree, Range const& rng) return tree.remove(rng); } +template inline +typename rtree::size_type +query(rtree const& tree, + Predicates const& pred, + OutIter out_it) +{ + return tree.query(pred, out_it); +} + +template inline +typename rtree::size_type +query(rtree const& tree, + Predicates const& pred, + typename rtree::value_type & v) +{ + return tree.query(pred, v); +} + /*! \brief Find values meeting spatial predicates.