diff --git a/include/boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp b/include/boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp index c254c1baf..93bad4178 100644 --- a/include/boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp +++ b/include/boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp @@ -72,12 +72,12 @@ inline Derived & get(dynamic_node & n) return static_cast(n); } -template -inline Derived * get(dynamic_node * n) -{ - BOOST_GEOMETRY_INDEX_ASSERT(dynamic_cast(n), "can't cast to a Derived type"); - return static_cast(n); -} +//template +//inline Derived * get(dynamic_node * n) +//{ +// BOOST_GEOMETRY_INDEX_ASSERT(dynamic_cast(n), "can't cast to a Derived type"); +// return static_cast(n); +//} // apply visitor diff --git a/include/boost/geometry/index/detail/rtree/node/node_auto_ptr.hpp b/include/boost/geometry/index/detail/rtree/node/node_auto_ptr.hpp index 4ae6707ef..5e25dcfbf 100644 --- a/include/boost/geometry/index/detail/rtree/node/node_auto_ptr.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node_auto_ptr.hpp @@ -24,9 +24,10 @@ class node_auto_ptr : boost::noncopyable { typedef typename rtree::node::type node; + typedef typename Allocators::node_pointer pointer; public: - node_auto_ptr(node * ptr, Allocators & allocators) + node_auto_ptr(pointer ptr, Allocators & allocators) : m_ptr(ptr) , m_allocators(allocators) {} @@ -36,7 +37,7 @@ public: reset(); } - void reset(node * ptr = 0) + void reset(pointer ptr = 0) { if ( m_ptr ) { @@ -51,7 +52,7 @@ public: m_ptr = 0; } - node * get() const + pointer get() const { return m_ptr; } @@ -61,13 +62,13 @@ public: return *m_ptr; } - node * operator->() const + pointer operator->() const { return m_ptr; } private: - node * m_ptr; + pointer m_ptr; Allocators & m_allocators; }; 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 c036554f8..a4d142725 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 @@ -24,7 +24,7 @@ struct dynamic_internal_node { typedef boost::container::vector< - std::pair *>, + std::pair, typename Allocators::internal_node_elements_allocator_type > elements_type; @@ -85,39 +85,61 @@ struct visitor type; }; -// element's indexable type - -template -struct element_indexable_type +template +struct translator_wrapper_helper { - typedef typename translator::indexable_type::type type; + typedef typename Element::first_type element_indexable_type; + typedef typename Element::first_type const& element_indexable_result; }; -template -struct element_indexable_type< - std::pair *>, - Translator -> +template +struct translator_wrapper_helper { - typedef Box type; + typedef typename translator::indexable_type::type element_indexable_type; + typedef typename Translator::result_type element_indexable_result; +}; + +template +struct translator_wrapper + : public Translator +{ + translator_wrapper(Translator const& t = Translator()) : Translator(t) {} + + template + struct element_indexable_type + { + typedef typename translator_wrapper_helper::element_indexable_type type; + }; + + template + struct element_indexable_result + { + typedef typename translator_wrapper_helper::element_indexable_result type; + }; + + typename element_indexable_result::type + element_indexable(Value const& v) const { return Translator::operator()(v); } + + template + typename element_indexable_result::type + element_indexable(Element const& el) const { return el.first; } +}; + +// element's indexable type + +template +struct element_indexable_type +{ + typedef typename Translator::template element_indexable_type::type type; }; // element's indexable getter -template -inline typename Translator::result_type -element_indexable(Value const& el, Translator const& tr) +template +typename Translator::template element_indexable_result::type +element_indexable(Element const& el, Translator const& tr) { - return tr(el); -} - -template -inline Box const& -element_indexable( - std::pair< Box, dynamic_node *> const& el, - Translator const&) -{ - return el.first; + return tr.element_indexable(el); } // nodes elements @@ -161,6 +183,10 @@ public: typedef Allocator allocator_type; typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::template rebind< + typename node::type + >::other::pointer node_pointer; + typedef typename allocator_type::template rebind< typename internal_node::type >::other internal_node_allocator_type; @@ -170,7 +196,7 @@ public: >::other leaf_allocator_type; typedef typename allocator_type::template rebind< - std::pair::type *> + std::pair >::other internal_node_elements_allocator_type; typedef typename allocator_type::template rebind< @@ -227,22 +253,25 @@ public: // create_node_impl -template +template struct create_dynamic_node { template - static inline BaseNode * apply(AllocNode & alloc_node, AllocElems & alloc_elems) + static inline BaseNodePtr apply(AllocNode & alloc_node, AllocElems & alloc_elems) { - Node * p = alloc_node.allocate(1); + typedef typename AllocNode::pointer P; + typedef typename AllocNode::value_type V; + + P p = alloc_node.allocate(1); if ( 0 == p ) - throw std::bad_alloc(); + throw std::bad_alloc(); // TODO throw different exception try { // NOTE/TODO // Here the whole node may be copied - alloc_node.construct(p, Node(alloc_elems)); + alloc_node.construct(p, V(alloc_elems)); } catch(...) { @@ -256,13 +285,15 @@ struct create_dynamic_node // destroy_node_impl -template struct destroy_dynamic_node { - template - static inline void apply(AllocNode & alloc_node, BaseNode * n) + template + static inline void apply(AllocNode & alloc_node, BaseNodePtr n) { - Node * p = rtree::get(n); + typedef typename AllocNode::value_type V; + typedef typename AllocNode::pointer P; + + P p(&static_cast(rtree::get(*n))); alloc_node.destroy(p); alloc_node.deallocate(p, 1); } @@ -276,12 +307,11 @@ struct create_node< dynamic_internal_node > { - static inline dynamic_node * + static inline typename Allocators::node_pointer apply(Allocators & allocators) { return create_dynamic_node< - dynamic_node, - dynamic_internal_node + typename Allocators::node_pointer >::apply(allocators.internal_node_allocator, allocators.internal_node_elements_allocator); } }; @@ -292,13 +322,12 @@ struct create_node< dynamic_leaf > { - static inline dynamic_node * + static inline typename Allocators::node_pointer apply(Allocators & allocators) { return create_dynamic_node< - dynamic_node, - dynamic_leaf - >::template apply(allocators.leaf_allocator, allocators.leaf_elements_allocator); + typename Allocators::node_pointer + >::apply(allocators.leaf_allocator, allocators.leaf_elements_allocator); } }; @@ -310,11 +339,9 @@ struct destroy_node< dynamic_internal_node > { - static inline void apply(Allocators & allocators, dynamic_node * n) + static inline void apply(Allocators & allocators, typename Allocators::node_pointer n) { - destroy_dynamic_node< - dynamic_internal_node - >::apply(allocators.internal_node_allocator, n); + destroy_dynamic_node::apply(allocators.internal_node_allocator, n); } }; @@ -324,11 +351,9 @@ struct destroy_node< dynamic_leaf > { - static inline void apply(Allocators & allocators, dynamic_node * n) + static inline void apply(Allocators & allocators, typename Allocators::node_pointer n) { - destroy_dynamic_node< - dynamic_leaf - >::apply(allocators.leaf_allocator, n); + destroy_dynamic_node::apply(allocators.leaf_allocator, n); } }; 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 a806d5395..21ca4de1c 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 @@ -25,7 +25,7 @@ struct dynamic_internal_node * + typename Allocators::node_pointer >, Parameters::max_elements + 1, typename Allocators::internal_node_elements_allocator_type @@ -104,6 +104,10 @@ public: typedef Allocator allocator_type; typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::template rebind< + typename node::type + >::other::pointer node_pointer; + typedef typename allocator_type::template rebind< typename internal_node::type >::other internal_node_allocator_type; @@ -113,7 +117,7 @@ public: >::other leaf_allocator_type; typedef typename allocator_type::template rebind< - std::pair::type *> + std::pair >::other internal_node_elements_allocator_type; typedef typename allocator_type::template rebind< @@ -164,13 +168,12 @@ struct create_node< dynamic_internal_node > { - static inline dynamic_node * + static inline typename Allocators::node_pointer apply(Allocators & allocators) { return create_dynamic_node< - dynamic_node, - dynamic_internal_node - >::template apply(allocators.internal_node_allocator, allocators.internal_node_allocator); + typename Allocators::node_pointer + >::apply(allocators.internal_node_allocator, allocators.internal_node_allocator); } }; @@ -180,13 +183,12 @@ struct create_node< dynamic_leaf > { - static inline typename node::type * + static inline typename Allocators::node_pointer apply(Allocators & allocators) { return create_dynamic_node< - dynamic_node, - dynamic_leaf - >::template apply(allocators.leaf_allocator, allocators.leaf_allocator); + typename Allocators::node_pointer + >::apply(allocators.leaf_allocator, allocators.leaf_allocator); } }; diff --git a/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp b/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp index 2cc1e96b4..5227715d9 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp @@ -27,16 +27,18 @@ public: typedef typename rtree::internal_node::type internal_node; typedef typename rtree::leaf::type leaf; - inline destroy(node * root_node, Allocators & allocators) + typedef typename Allocators::node_pointer node_pointer; + + inline destroy(node_pointer root_node, Allocators & allocators) : m_current_node(root_node) , m_allocators(allocators) {} inline void operator()(internal_node & n) { - BOOST_GEOMETRY_INDEX_ASSERT(&n == rtree::get(m_current_node), "invalid pointers"); + BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get(*m_current_node), "invalid pointers"); - node * node_to_destroy = m_current_node; + node_pointer node_to_destroy = m_current_node; typedef typename rtree::elements_type::type elements_type; elements_type & elements = rtree::elements(n); @@ -54,13 +56,13 @@ public: inline void operator()(leaf & BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM(l)) { - BOOST_GEOMETRY_INDEX_ASSERT(&l == rtree::get(m_current_node), "invalid pointers"); + BOOST_GEOMETRY_INDEX_ASSERT(&l == &rtree::get(*m_current_node), "invalid pointers"); rtree::destroy_node::apply(m_allocators, m_current_node); } private: - node * m_current_node; + node_pointer m_current_node; Allocators & m_allocators; }; diff --git a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp index 10e3f5ff3..034d1db8c 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp @@ -120,7 +120,10 @@ protected: typedef rtree::node_auto_ptr node_auto_ptr; public: - typedef index::detail::varray, 1> nodes_container_type; + typedef index::detail::varray< + typename rtree::elements_type::type::value_type, + 1 + > nodes_container_type; template static inline void apply(nodes_container_type & additional_nodes, @@ -230,8 +233,9 @@ protected: typedef typename rtree::leaf::type leaf; typedef rtree::node_auto_ptr node_auto_ptr; + typedef typename Allocators::node_pointer node_pointer; - inline insert(node* & root, + inline insert(node_pointer & root, size_t & leafs_level, Element const& element, parameters_type const& parameters, @@ -278,7 +282,7 @@ protected: inline void post_traverse(Node &n) { BOOST_GEOMETRY_INDEX_ASSERT(m_traverse_data.current_is_root() || - &n == rtree::get(m_traverse_data.current_element().second), + &n == &rtree::get(*m_traverse_data.current_element().second), "if node isn't the root current_child_index should be valid"); // handle overflow @@ -342,7 +346,7 @@ protected: // node is the root - add level else { - BOOST_GEOMETRY_INDEX_ASSERT(&n == rtree::get(m_root_node), "node should be the root"); + BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get(*m_root_node), "node should be the root"); // create new root and add nodes node_auto_ptr new_root(rtree::create_node::apply(m_allocators), m_allocators); // MAY THROW, STRONG (N:alloc) @@ -373,7 +377,7 @@ protected: const size_t m_relative_level; const size_t m_level; - node* & m_root_node; + node_pointer & m_root_node; size_t & m_leafs_level; // traversing input parameters @@ -403,8 +407,9 @@ public: typedef typename base::leaf leaf; typedef typename Options::parameters_type parameters_type; + typedef typename base::node_pointer node_pointer; - inline insert(node* & root, + inline insert(node_pointer & root, size_t & leafs_level, Element & element, parameters_type const& parameters, @@ -465,8 +470,9 @@ public: typedef typename base::leaf leaf; typedef typename Options::parameters_type parameters_type; + typedef typename base::node_pointer node_pointer; - inline insert(node* & root, + inline insert(node_pointer & root, size_t & leafs_level, Value const& value, parameters_type const& parameters, 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 345246ed5..18aee5404 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp @@ -201,7 +201,7 @@ public: // array of active nodes typename index::detail::rtree::container_from_elements_type< elements_type, - std::pair + std::pair >::type active_branch_list; active_branch_list.reserve(m_parameters.get_max_elements()); @@ -311,8 +311,8 @@ private: } static inline bool abl_less( - std::pair const& p1, - std::pair const& p2) + std::pair const& p1, + std::pair const& p2) { return index::detail::cdist_value ::template get(p1.first) diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index fc606a182..0121fc78f 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -130,7 +130,11 @@ private: typedef typename detail::rtree::internal_node::type internal_node; typedef typename detail::rtree::leaf::type leaf; + typedef detail::rtree::translator_wrapper translator_wrapper; + typedef typename allocators_type::node_pointer node_pointer; + public: + /*! \brief The constructor. @@ -782,7 +786,7 @@ public: if ( !m_root ) return 0; - detail::rtree::visitors::count + detail::rtree::visitors::count count_v(vori, m_translator); detail::rtree::apply_visitor(count_v, *m_root); @@ -900,7 +904,7 @@ private: detail::rtree::visitors::insert< value_type, - value_type, options_type, translator_type, box_type, allocators_type, + value_type, options_type, translator_wrapper, box_type, allocators_type, typename options_type::insert_tag > insert_v(m_root, m_leafs_level, value, m_parameters, m_translator, m_allocators); @@ -929,7 +933,7 @@ private: BOOST_GEOMETRY_INDEX_ASSERT(m_root, "The root must exist"); detail::rtree::visitors::remove< - value_type, options_type, translator_type, box_type, allocators_type + value_type, options_type, translator_wrapper, box_type, allocators_type > remove_v(m_root, m_leafs_level, m_box, value, m_parameters, m_translator, m_allocators); detail::rtree::apply_visitor(remove_v, *m_root); @@ -975,7 +979,7 @@ private: { if ( t.m_root ) { - detail::rtree::visitors::destroy del_v(t.m_root, t.m_allocators); + detail::rtree::visitors::destroy del_v(t.m_root, t.m_allocators); detail::rtree::apply_visitor(del_v, *t.m_root); t.m_root = 0; @@ -996,7 +1000,7 @@ private: */ inline void raw_copy(rtree const& src, rtree & dst, bool copy_all_internals) const { - detail::rtree::visitors::copy copy_v(dst.m_allocators); + detail::rtree::visitors::copy copy_v(dst.m_allocators); if ( src.m_root ) detail::rtree::apply_visitor(copy_v, *src.m_root); // MAY THROW (V, E: alloc, copy, N: alloc) @@ -1011,7 +1015,7 @@ private: if ( dst.m_root ) { - detail::rtree::visitors::destroy del_v(dst.m_root, dst.m_allocators); + detail::rtree::visitors::destroy del_v(dst.m_root, dst.m_allocators); detail::rtree::apply_visitor(del_v, *dst.m_root); dst.m_root = 0; } @@ -1030,7 +1034,7 @@ private: template size_type query_dispatch(Predicates const& predicates, OutIter out_it, boost::mpl::bool_ const& /*is_nearest*/) const { - detail::rtree::visitors::spatial_query + detail::rtree::visitors::spatial_query find_v(m_translator, predicates, out_it); detail::rtree::apply_visitor(find_v, *m_root); @@ -1068,7 +1072,7 @@ private: typedef detail::rtree::visitors::nearest_query_result_k< value_type, - translator_type, + translator_wrapper, point_type, OutIter > result_type; @@ -1078,7 +1082,7 @@ private: detail::rtree::visitors::nearest_query< value_type, options_type, - translator_type, + translator_wrapper, box_type, allocators_type, DistancesPredicates, @@ -1091,13 +1095,13 @@ private: return result.finish(); } - translator_type m_translator; + translator_wrapper m_translator; Parameters m_parameters; allocators_type m_allocators; size_type m_values_count; size_type m_leafs_level; - node * m_root; + node_pointer m_root; box_type m_box; }; diff --git a/test/rtree/rtree_interprocess.cpp b/test/rtree/rtree_interprocess.cpp index bb8c5d534..9e2af9e95 100644 --- a/test/rtree/rtree_interprocess.cpp +++ b/test/rtree/rtree_interprocess.cpp @@ -62,9 +62,9 @@ int test_main(int, char* []) typedef bg::model::box B2d; typedef std::pair PB2d; - test_rtree_interprocess(bgi::linear<32, 8>()); - /*test_rtree_interprocess(bgi::runtime::linear(32, 8)); - test_rtree_interprocess(bgi::quadratic<32, 8>()); + //test_rtree_interprocess(bgi::linear<32, 8>()); + test_rtree_interprocess(bgi::runtime::linear(32, 8)); + /*test_rtree_interprocess(bgi::quadratic<32, 8>()); test_rtree_interprocess(bgi::runtime::quadratic(32, 8)); test_rtree_interprocess(bgi::rstar<32, 8>()); test_rtree_interprocess(bgi::runtime::rstar(32, 8));