From 24626df0cfe3ae730e844221d5fb1c8f5dc24b78 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sat, 16 Feb 2013 14:54:52 +0000 Subject: [PATCH] rtree: unneeded allocators removed from members. [SVN r82924] --- .../detail/rtree/node/node_d_mem_dynamic.hpp | 67 ++++-------- .../detail/rtree/node/node_d_mem_static.hpp | 38 +++---- .../detail/rtree/node/node_s_mem_dynamic.hpp | 103 ++++++++---------- .../detail/rtree/node/node_s_mem_static.hpp | 83 +++++++------- .../exceptions/test_rtree_exceptions.hpp | 13 +-- 5 files changed, 125 insertions(+), 179 deletions(-) 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 3b82d5184..d0da104fc 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 @@ -23,12 +23,17 @@ template : public dynamic_node { + typedef typename Allocators::leaf_allocator_type::template rebind< + std::pair + >::other elements_allocator_type; + typedef boost::container::vector< std::pair, - typename Allocators::internal_node_elements_allocator_type + elements_allocator_type > elements_type; - inline dynamic_internal_node(typename Allocators::internal_node_elements_allocator_type & al) + template + inline dynamic_internal_node(Al const& al) : elements(al) {} @@ -42,12 +47,17 @@ template : public dynamic_node { + typedef typename Allocators::leaf_allocator_type::template rebind< + Value + >::other elements_allocator_type; + typedef boost::container::vector< Value, - typename Allocators::leaf_elements_allocator_type + elements_allocator_type > elements_type; - inline dynamic_leaf(typename Allocators::leaf_elements_allocator_type & al) + template + inline dynamic_leaf(Al const& al) : elements(al) {} @@ -181,18 +191,6 @@ class allocators , public Allocator::template rebind< typename leaf, node_d_mem_dynamic_tag>::type >::other - , public Allocator::template rebind< - std::pair< - Box, - typename Allocator::template rebind< - typename node, node_d_mem_dynamic_tag>::type - >::other::pointer - > - >::other - , public Allocator::template rebind< - Value - >::other - , nonassignable { public: typedef typename Allocator::size_type size_type; @@ -213,58 +211,37 @@ public: typename leaf::type >::other leaf_allocator_type; - typedef typename Allocator::template rebind< - std::pair - >::other internal_node_elements_allocator_type; - - typedef typename Allocator::template rebind< - Value - >::other leaf_elements_allocator_type; - inline allocators() : internal_node_allocator_type() , leaf_allocator_type() - , internal_node_elements_allocator_type() - , leaf_elements_allocator_type() {} inline explicit allocators(Allocator const& alloc) : internal_node_allocator_type(alloc) , leaf_allocator_type(alloc) - , internal_node_elements_allocator_type(alloc) - , leaf_elements_allocator_type(alloc) {} inline allocators(BOOST_FWD_REF(allocators) a) : internal_node_allocator_type(boost::move(a.internal_node_allocator())) , leaf_allocator_type(boost::move(a.leaf_allocator())) - , internal_node_elements_allocator_type(boost::move(a.internal_node_elements_allocator())) - , leaf_elements_allocator_type(boost::move(a.leaf_elements_allocator())) {} void swap(allocators & a) { boost::swap(internal_node_allocator(), a.internal_node_allocator()); boost::swap(leaf_allocator(), a.leaf_allocator()); - boost::swap(internal_node_elements_allocator(), a.internal_node_elements_allocator()); - boost::swap(leaf_elements_allocator(), a.leaf_elements_allocator()); } - bool operator==(allocators const& a) const { return leaf_elements_allocator() == a.leaf_elements_allocator(); } - bool operator==(leaf_elements_allocator_type const& a) const { return leaf_elements_allocator() == a; } + bool operator==(allocators const& a) const { return leaf_allocator() == a.leaf_allocator(); } template - bool operator==(Alloc const& a) const { return leaf_elements_allocator() == leaf_elements_allocator_type(a); } + bool operator==(Alloc const& a) const { return leaf_allocator() == leaf_allocator_type(a); } - Allocator allocator() const { return Allocator(leaf_elements_allocator()); } + Allocator allocator() const { return Allocator(leaf_allocator()); } internal_node_allocator_type & internal_node_allocator() { return *this; } internal_node_allocator_type const& internal_node_allocator() const { return *this; } leaf_allocator_type & leaf_allocator() { return *this; } leaf_allocator_type const& leaf_allocator() const { return *this; } - internal_node_elements_allocator_type & internal_node_elements_allocator() { return *this; } - internal_node_elements_allocator_type const& internal_node_elements_allocator() const { return *this; } - leaf_elements_allocator_type & leaf_elements_allocator() { return *this; } - leaf_elements_allocator_type const& leaf_elements_allocator() const { return *this; } }; // create_node_impl @@ -272,8 +249,8 @@ public: template struct create_dynamic_node { - template - static inline BaseNodePtr apply(AllocNode & alloc_node, AllocElems & alloc_elems) + template + static inline BaseNodePtr apply(AllocNode & alloc_node) { typedef typename AllocNode::pointer P; @@ -286,7 +263,7 @@ struct create_dynamic_node { // NOTE/TODO // Here the whole node may be copied - alloc_node.construct(p, Node(alloc_elems)); + alloc_node.construct(p, Node(alloc_node)); } catch(...) { @@ -328,7 +305,7 @@ struct create_node< return create_dynamic_node< typename Allocators::node_pointer, dynamic_internal_node - >::apply(allocators.internal_node_allocator(), allocators.internal_node_elements_allocator()); + >::apply(allocators.internal_node_allocator()); } }; @@ -344,7 +321,7 @@ struct create_node< return create_dynamic_node< typename Allocators::node_pointer, dynamic_leaf - >::apply(allocators.leaf_allocator(), allocators.leaf_elements_allocator()); + >::apply(allocators.leaf_allocator()); } }; 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 4c9df9790..b263c4c5b 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 @@ -22,17 +22,18 @@ template : public dynamic_node { + typedef typename Allocators::leaf_allocator_type::template rebind< + std::pair + >::other elements_allocator_type; + typedef detail::varray< - std::pair< - Box, - typename Allocators::node_pointer - >, + std::pair, Parameters::max_elements + 1, - typename Allocators::internal_node_elements_allocator_type + elements_allocator_type > elements_type; - template - inline dynamic_internal_node(Dummy) {} + template + inline dynamic_internal_node(Alloc const&) {} void apply_visitor(dynamic_visitor & v) { v(*this); } void apply_visitor(dynamic_visitor & v) const { v(*this); } @@ -44,14 +45,18 @@ template : public dynamic_node { + typedef typename Allocators::leaf_allocator_type::template rebind< + Value + >::other elements_allocator_type; + typedef detail::varray< Value, Parameters::max_elements + 1, - typename Allocators::leaf_elements_allocator_type + elements_allocator_type > elements_type; - template - inline dynamic_leaf(Dummy) {} + template + inline dynamic_leaf(Alloc const&) {} void apply_visitor(dynamic_visitor & v) { v(*this); } void apply_visitor(dynamic_visitor & v) const { v(*this); } @@ -110,7 +115,6 @@ class allocators node_d_mem_static_tag >::type >::other - , detail::nonassignable { public: typedef typename Allocator::size_type size_type; @@ -131,14 +135,6 @@ public: typename leaf::type >::other leaf_allocator_type; - typedef typename Allocator::template rebind< - std::pair - >::other internal_node_elements_allocator_type; - - typedef typename Allocator::template rebind< - Value - >::other leaf_elements_allocator_type; - inline allocators() : internal_node_allocator_type() , leaf_allocator_type() @@ -186,7 +182,7 @@ struct create_node< return create_dynamic_node< typename Allocators::node_pointer, dynamic_internal_node - >::apply(allocators.internal_node_allocator(), allocators.internal_node_allocator()); + >::apply(allocators.internal_node_allocator()); } }; @@ -202,7 +198,7 @@ struct create_node< return create_dynamic_node< typename Allocators::node_pointer, dynamic_leaf - >::apply(allocators.leaf_allocator(), allocators.leaf_allocator()); + >::apply(allocators.leaf_allocator()); } }; 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 b95316338..e3f66544f 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 @@ -24,15 +24,17 @@ namespace detail { namespace rtree { template struct static_internal_node { + typedef typename Allocators::node_allocator_type::template rebind< + std::pair + >::other elements_allocator_type; + typedef boost::container::vector< - std::pair< - Box, - typename Allocators::node_pointer - >, - typename Allocators::internal_node_elements_allocator_type + std::pair, + elements_allocator_type > elements_type; - inline static_internal_node(typename Allocators::internal_node_elements_allocator_type & al) + template + inline static_internal_node(Al const& al) : elements(al) {} @@ -42,12 +44,17 @@ struct static_internal_node template struct static_leaf { + typedef typename Allocators::node_allocator_type::template rebind< + Value + >::other elements_allocator_type; + typedef boost::container::vector< Value, - typename Allocators::leaf_elements_allocator_type + elements_allocator_type > elements_type; - inline static_leaf(typename Allocators::leaf_elements_allocator_type & al) + template + inline static_leaf(Al const& al) : elements(al) {} @@ -89,74 +96,50 @@ struct visitor class allocators - : nonassignable + : public Allocator::template rebind< + typename node, node_s_mem_dynamic_tag>::type + >::other { - BOOST_COPYABLE_AND_MOVABLE_ALT(allocators) - public: - typedef Allocator allocator_type; - typedef typename allocator_type::size_type size_type; + typedef typename Allocator::size_type size_type; - typedef typename allocator_type::template rebind< + typedef typename Allocator::template rebind< typename node::type >::other::pointer node_pointer; - typedef typename allocator_type::template rebind< + typedef typename Allocator::template rebind< typename internal_node::type >::other::pointer internal_node_pointer; - typedef typename allocator_type::template rebind< + typedef typename Allocator::template rebind< typename node::type >::other node_allocator_type; - typedef typename allocator_type::template rebind< - std::pair - >::other internal_node_elements_allocator_type; - - typedef typename allocator_type::template rebind< - Value - >::other leaf_elements_allocator_type; - inline allocators() - : allocator() - , node_allocator() - , internal_node_elements_allocator() - , leaf_elements_allocator() + : node_allocator_type() {} - inline explicit allocators(Allocator alloc) - : allocator(alloc) - , node_allocator(allocator) - , internal_node_elements_allocator(allocator) - , leaf_elements_allocator(allocator) + inline explicit allocators(Allocator const& alloc) + : node_allocator_type(alloc) {} - inline allocators(allocators const& a) - : allocator(a.allocator) - , node_allocator(a.node_allocator) - , internal_node_elements_allocator(a.internal_node_elements_allocator) - , leaf_elements_allocator(a.leaf_elements_allocator) - {} - - inline allocators(BOOST_RV_REF(allocators) a) - : allocator(boost::move(a.allocator)) - , node_allocator(boost::move(a.node_allocator)) - , internal_node_elements_allocator(boost::move(a.internal_node_elements_allocator)) - , leaf_elements_allocator(boost::move(a.leaf_elements_allocator)) + inline allocators(BOOST_FWD_REF(allocators) a) + : node_allocator_type(boost::move(a.node_allocator())) {} void swap(allocators & a) { - boost::swap(allocator, a.allocator); - boost::swap(node_allocator, a.node_allocator); - boost::swap(internal_node_elements_allocator, a.internal_node_elements_allocator); - boost::swap(leaf_elements_allocator, a.leaf_elements_allocator); + boost::swap(node_allocator(), a.node_allocator()); } - allocator_type allocator; - node_allocator_type node_allocator; - internal_node_elements_allocator_type internal_node_elements_allocator; - leaf_elements_allocator_type leaf_elements_allocator; + bool operator==(allocators const& a) const { return node_allocator() == a.node_allocator(); } + template + bool operator==(Alloc const& a) const { return node_allocator() == node_allocator_type(a); } + + Allocator allocator() const { return Allocator(node_allocator()); } + + node_allocator_type & node_allocator() { return *this; } + node_allocator_type const& node_allocator() const { return *this; } }; // create_node_variant @@ -164,8 +147,8 @@ public: template struct create_static_node { - template - static inline VariantPtr apply(AllocNode & alloc_node, AllocElems & alloc_elems) + template + static inline VariantPtr apply(AllocNode & alloc_node) { VariantPtr p = alloc_node.allocate(1); @@ -176,7 +159,7 @@ struct create_static_node { // NOTE/TODO // Here the whole node may be copied - alloc_node.construct(p, Node(alloc_elems)); // implicit cast to Variant + alloc_node.construct(p, Node(alloc_node)); // implicit cast to Variant } catch(...) { @@ -215,7 +198,7 @@ struct create_node< return create_static_node< typename Allocators::node_pointer, static_internal_node - >::apply(allocators.node_allocator, allocators.internal_node_elements_allocator); + >::apply(allocators.node_allocator()); } }; @@ -231,7 +214,7 @@ struct create_node< return create_static_node< typename Allocators::node_pointer, static_leaf - >::apply(allocators.node_allocator, allocators.leaf_elements_allocator); + >::apply(allocators.node_allocator()); } }; @@ -247,7 +230,7 @@ struct destroy_node< { destroy_static_node< static_internal_node - >::apply(allocators.node_allocator, n); + >::apply(allocators.node_allocator(), n); } }; @@ -261,7 +244,7 @@ struct destroy_node< { destroy_static_node< static_leaf - >::apply(allocators.node_allocator, n); + >::apply(allocators.node_allocator(), n); } }; 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 7d183538d..a480034ef 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 @@ -24,17 +24,18 @@ namespace detail { namespace rtree { template struct static_internal_node { + typedef typename Allocators::node_allocator_type::template rebind< + std::pair + >::other elements_allocator_type; + typedef detail::varray< - std::pair< - Box, - typename Allocators::node_pointer - >, + std::pair, Parameters::max_elements + 1, - typename Allocators::internal_node_elements_allocator_type + elements_allocator_type > elements_type; - template - inline static_internal_node(Dummy) {} + template + inline static_internal_node(Alloc const&) {} elements_type elements; }; @@ -42,14 +43,18 @@ struct static_internal_node struct static_leaf { + typedef typename Allocators::node_allocator_type::template rebind< + Value + >::other elements_allocator_type; + typedef detail::varray< Value, Parameters::max_elements + 1, - typename Allocators::leaf_elements_allocator_type + elements_allocator_type > elements_type; - template - inline static_leaf(Dummy) {} + template + inline static_leaf(Alloc const&) {} elements_type elements; }; @@ -89,62 +94,50 @@ struct visitor struct allocators - : nonassignable + : public Allocator::template rebind< + typename node, node_s_mem_static_tag>::type + >::other { - BOOST_COPYABLE_AND_MOVABLE_ALT(allocators) - public: - typedef Allocator allocator_type; - typedef typename allocator_type::size_type size_type; + typedef typename Allocator::size_type size_type; - typedef typename allocator_type::template rebind< + typedef typename Allocator::template rebind< typename node::type >::other::pointer node_pointer; - typedef typename allocator_type::template rebind< + typedef typename Allocator::template rebind< typename internal_node::type >::other::pointer internal_node_pointer; - typedef typename allocator_type::template rebind< + typedef typename Allocator::template rebind< typename node::type >::other node_allocator_type; - typedef typename allocator_type::template rebind< - std::pair - >::other internal_node_elements_allocator_type; - - typedef typename allocator_type::template rebind< - Value - >::other leaf_elements_allocator_type; - inline allocators() - : allocator() - , node_allocator() + : node_allocator_type() {} - inline explicit allocators(Allocator alloc) - : allocator(alloc) - , node_allocator(allocator) + inline explicit allocators(Allocator const& alloc) + : node_allocator_type(alloc) {} - inline allocators(allocators const& a) - : allocator(a.allocator) - , node_allocator(a.node_allocator) - {} - - inline allocators(BOOST_RV_REF(allocators) a) - : allocator(boost::move(a.allocator)) - , node_allocator(boost::move(a.node_allocator)) + inline allocators(BOOST_FWD_REF(allocators) a) + : node_allocator_type(boost::move(a.node_allocator())) {} void swap(allocators & a) { - boost::swap(allocator, a.allocator); - boost::swap(node_allocator, a.node_allocator); + boost::swap(node_allocator(), a.node_allocator()); } - allocator_type allocator; - node_allocator_type node_allocator; + bool operator==(allocators const& a) const { return node_allocator() == a.node_allocator(); } + template + bool operator==(Alloc const& a) const { return node_allocator() == node_allocator_type(a); } + + Allocator allocator() const { return Allocator(node_allocator()); } + + node_allocator_type & node_allocator() { return *this; } + node_allocator_type const& node_allocator() const { return *this; } }; // create_node @@ -161,7 +154,7 @@ struct create_node< return create_static_node< typename Allocators::node_pointer, static_internal_node - >::template apply(allocators.node_allocator, allocators.node_allocator); + >::template apply(allocators.node_allocator()); } }; @@ -177,7 +170,7 @@ struct create_node< return create_static_node< typename Allocators::node_pointer, static_leaf - >::template apply(allocators.node_allocator, allocators.node_allocator); + >::template apply(allocators.node_allocator()); } }; diff --git a/test/rtree/exceptions/test_rtree_exceptions.hpp b/test/rtree/exceptions/test_rtree_exceptions.hpp index ef39bd045..db1520bcf 100644 --- a/test/rtree/exceptions/test_rtree_exceptions.hpp +++ b/test/rtree/exceptions/test_rtree_exceptions.hpp @@ -76,15 +76,12 @@ struct dynamic_internal_node { typedef throwing_varray< - std::pair< - Box, - typename Allocators::node_pointer - >, + std::pair, Parameters::max_elements + 1 > elements_type; template - inline dynamic_internal_node(Dummy) {} + inline dynamic_internal_node(Dummy const&) {} void apply_visitor(dynamic_visitor & v) { v(*this); } void apply_visitor(dynamic_visitor & v) const { v(*this); } @@ -99,7 +96,7 @@ struct dynamic_leaf elements_type; template - inline dynamic_leaf(Dummy) {} + inline dynamic_leaf(Dummy const&) {} void apply_visitor(dynamic_visitor & v) { v(*this); } void apply_visitor(dynamic_visitor & v) const { v(*this); } @@ -251,7 +248,7 @@ struct create_node< return create_dynamic_node< typename Allocators::node_pointer, dynamic_internal_node - >::apply(allocators.internal_node_allocator(), allocators.internal_node_allocator()); + >::apply(allocators.internal_node_allocator()); } }; @@ -270,7 +267,7 @@ struct create_node< return create_dynamic_node< typename Allocators::node_pointer, dynamic_leaf - >::apply(allocators.leaf_allocator(), allocators.leaf_allocator()); + >::apply(allocators.leaf_allocator()); } };