diff --git a/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp b/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp index 65087d5a5..832335f24 100644 --- a/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp @@ -164,9 +164,20 @@ class allocators typename leaf, node_d_mem_dynamic_tag>::type >::other { + typedef typename Allocator::template rebind< + Value + >::other value_allocator_type; + public: typedef Allocator allocator_type; - typedef typename Allocator::size_type size_type; + + typedef Value value_type; + typedef typename value_allocator_type::reference reference; + typedef typename value_allocator_type::const_reference const_reference; + typedef typename value_allocator_type::size_type size_type; + typedef typename value_allocator_type::difference_type difference_type; + typedef typename value_allocator_type::pointer pointer; + typedef typename value_allocator_type::const_pointer const_pointer; typedef typename Allocator::template rebind< typename node::type diff --git a/include/boost/geometry/index/detail/rtree/node/node_d_mem_static.hpp b/include/boost/geometry/index/detail/rtree/node/node_d_mem_static.hpp index 0bf3fcc5a..c8f6593ef 100644 --- a/include/boost/geometry/index/detail/rtree/node/node_d_mem_static.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node_d_mem_static.hpp @@ -113,9 +113,20 @@ class allocators >::type >::other { + typedef typename Allocator::template rebind< + Value + >::other value_allocator_type; + public: typedef Allocator allocator_type; - typedef typename Allocator::size_type size_type; + + typedef Value value_type; + typedef value_type & reference; + typedef const value_type & const_reference; + typedef typename value_allocator_type::size_type size_type; + typedef typename value_allocator_type::difference_type difference_type; + typedef typename value_allocator_type::pointer pointer; + typedef typename value_allocator_type::const_pointer const_pointer; typedef typename Allocator::template rebind< typename node::type diff --git a/include/boost/geometry/index/detail/rtree/node/node_s_mem_dynamic.hpp b/include/boost/geometry/index/detail/rtree/node/node_s_mem_dynamic.hpp index 7038721f7..a37856c55 100644 --- a/include/boost/geometry/index/detail/rtree/node/node_s_mem_dynamic.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node_s_mem_dynamic.hpp @@ -96,9 +96,20 @@ class allocators typename node, node_s_mem_dynamic_tag>::type >::other { + typedef typename Allocator::template rebind< + Value + >::other value_allocator_type; + public: typedef Allocator allocator_type; - typedef typename Allocator::size_type size_type; + + typedef Value value_type; + typedef typename value_allocator_type::reference reference; + typedef typename value_allocator_type::const_reference const_reference; + typedef typename value_allocator_type::size_type size_type; + typedef typename value_allocator_type::difference_type difference_type; + typedef typename value_allocator_type::pointer pointer; + typedef typename value_allocator_type::const_pointer const_pointer; typedef typename Allocator::template rebind< typename node::type diff --git a/include/boost/geometry/index/detail/rtree/node/node_s_mem_static.hpp b/include/boost/geometry/index/detail/rtree/node/node_s_mem_static.hpp index a3e572576..4d04edf3d 100644 --- a/include/boost/geometry/index/detail/rtree/node/node_s_mem_static.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node_s_mem_static.hpp @@ -94,9 +94,20 @@ struct allocators typename node, node_s_mem_static_tag>::type >::other { + typedef typename Allocator::template rebind< + Value + >::other value_allocator_type; + public: typedef Allocator allocator_type; - typedef typename Allocator::size_type size_type; + + typedef Value value_type; + typedef value_type & reference; + typedef const value_type & const_reference; + typedef typename value_allocator_type::size_type size_type; + typedef typename value_allocator_type::difference_type difference_type; + typedef typename value_allocator_type::pointer pointer; + typedef typename value_allocator_type::const_pointer const_pointer; typedef typename Allocator::template rebind< typename node::type diff --git a/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp b/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp index fbb83e926..6466510a6 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp @@ -364,6 +364,7 @@ public: > value_distances_predicates_check; typedef typename Allocators::size_type size_type; + typedef typename Allocators::const_reference const_reference; typedef typename Allocators::node_pointer node_pointer; static const unsigned predicates_len = index::detail::predicates_length::value; @@ -390,7 +391,7 @@ public: BOOST_ASSERT_MSG(0 < max_count(), "k must be greather than 0"); } - Value const& dereference() const + const_reference dereference() const { return *(neighbors[current_neighbor].second); } @@ -622,14 +623,12 @@ class nearest_query_iterator typedef visitors::nearest_query_incremental visitor_type; typedef typename visitor_type::node_pointer node_pointer; - typedef typename Allocators::allocator_type::template rebind::other allocator_type; - public: typedef std::input_iterator_tag iterator_category; - typedef const Value value_type; - typedef Value const& reference; - typedef typename allocator_type::difference_type difference_type; - typedef typename allocator_type::const_pointer pointer; + typedef Value value_type; + typedef typename Allocators::const_reference reference; + typedef typename Allocators::difference_type difference_type; + typedef typename Allocators::const_pointer pointer; inline nearest_query_iterator(Translator const& t, Predicates const& p) : m_visitor(t, p) diff --git a/include/boost/geometry/index/detail/rtree/visitors/spatial_query.hpp b/include/boost/geometry/index/detail/rtree/visitors/spatial_query.hpp index 268443c6c..26b822610 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/spatial_query.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/spatial_query.hpp @@ -85,6 +85,7 @@ public: typedef typename rtree::leaf::type leaf; typedef typename Allocators::size_type size_type; + typedef typename Allocators::const_reference const_reference; typedef typename Allocators::node_pointer node_pointer; typedef typename rtree::elements_type::type::const_iterator internal_iterator; @@ -112,7 +113,7 @@ public: m_value_index = 0; } - Value const& dereference() const + const_reference dereference() const { BOOST_ASSERT_MSG(m_values, "not dereferencable"); return (*m_values)[m_value_index]; @@ -192,14 +193,12 @@ class spatial_query_iterator typedef visitors::spatial_query_incremental visitor_type; typedef typename visitor_type::node_pointer node_pointer; - typedef typename Allocators::allocator_type::template rebind::other allocator_type; - public: typedef std::input_iterator_tag iterator_category; - typedef const Value value_type; - typedef Value const& reference; - typedef typename allocator_type::difference_type difference_type; - typedef typename allocator_type::const_pointer pointer; + typedef Value value_type; + typedef typename Allocators::const_reference reference; + typedef typename Allocators::difference_type difference_type; + typedef typename Allocators::const_pointer pointer; inline spatial_query_iterator(Translator const& t, Predicates const& p) : m_visitor(t, p) diff --git a/include/boost/geometry/index/detail/type_erased_iterators.hpp b/include/boost/geometry/index/detail/type_erased_iterators.hpp new file mode 100644 index 000000000..92867a4ce --- /dev/null +++ b/include/boost/geometry/index/detail/type_erased_iterators.hpp @@ -0,0 +1,60 @@ +// Boost.Geometry Index +// +// Type-erased iterators +// +// 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_DETAIL_TYPE_ERASED_ITERATORS_HPP +#define BOOST_GEOMETRY_INDEX_DETAIL_TYPE_ERASED_ITERATORS_HPP + +#include +#include + +namespace boost { namespace geometry { namespace index { namespace detail { + +template +struct single_pass_iterator_concept : + ::boost::mpl::vector< + ::boost::type_erasure::copy_constructible, + ::boost::type_erasure::equality_comparable, + ::boost::type_erasure::dereferenceable, + ::boost::type_erasure::assignable, + ::boost::type_erasure::incrementable + > +{}; + +template +struct single_pass_iterator_type +{ + typedef ::boost::type_erasure::any< + single_pass_iterator_concept< + ::boost::type_erasure::_self, ValueType, Reference, Pointer, DifferenceType + > + > type; +}; + +}}}} // namespace boost::geometry::index::detail + +namespace boost { namespace type_erasure { + +template +struct concept_interface< + ::boost::geometry::index::detail::single_pass_iterator_concept< + T, ValueType, Reference, Pointer, DifferenceType + >, Base, T> + : Base +{ + typedef ValueType value_type; + typedef Reference reference; + typedef Pointer pointer; + typedef DifferenceType difference_type; + typedef ::std::input_iterator_tag iterator_category; +}; + +}} // namespace boost::type_erasure + +#endif // BOOST_GEOMETRY_INDEX_DETAIL_TYPE_ERASED_ITERATORS_HPP diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index 512ef29b0..384bad14e 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -57,6 +57,10 @@ #include +#ifdef BOOST_GEOMETRY_INDEX_DETAIL_ENABLE_TYPE_ERASED_ITERATORS +#include +#endif + // TODO change the name to bounding_tree /*! @@ -117,14 +121,12 @@ public: typedef Value value_type; /*! \brief R-tree parameters type. */ typedef Parameters parameters_type; - /*! \brief The type of allocator used by the container. */ - typedef Allocator allocator_type; - /*! \brief Unsigned integral type used by the container. */ - typedef typename allocator_type::size_type size_type; /*! \brief The function object extracting Indexable from Value. */ typedef IndexableGetter indexable_getter; /*! \brief The function object comparing objects of type Value. */ typedef EqualTo value_equal; + /*! \brief The type of allocator used by the container. */ + typedef Allocator allocator_type; // TODO: SHOULD THIS TYPE BE REMOVED? /*! \brief The Indexable type to which Value is translated. */ @@ -152,6 +154,21 @@ private: typedef typename allocators_type::node_pointer node_pointer; typedef ::boost::container::allocator_traits allocator_traits_type; +public: + + /*! \brief Type of reference to Value. */ + typedef typename allocators_type::reference reference; + /*! \brief Type of reference to const Value. */ + typedef typename allocators_type::const_reference const_reference; + /*! \brief Type of pointer to Value. */ + typedef typename allocators_type::pointer pointer; + /*! \brief Type of pointer to const Value. */ + typedef typename allocators_type::const_pointer const_pointer; + /*! \brief Type of difference type. */ + typedef typename allocators_type::difference_type difference_type; + /*! \brief Unsigned integral type used by the container. */ + typedef typename allocators_type::size_type size_type; + public: /*! @@ -724,6 +741,14 @@ public: #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL +#ifdef BOOST_GEOMETRY_INDEX_DETAIL_ENABLE_TYPE_ERASED_ITERATORS + + typedef typename index::detail::single_pass_iterator_type< + value_type, const_reference, const_pointer, difference_type + >::type const_query_iterator; + +#endif // BOOST_GEOMETRY_INDEX_DETAIL_ENABLE_TYPE_ERASED_ITERATORS + template typename boost::mpl::if_c< detail::predicates_count_nearest::value == 0,