diff --git a/include/boost/geometry/index/detail/nonassignable.hpp b/include/boost/geometry/index/detail/nonassignable.hpp deleted file mode 100644 index 944fc1547..000000000 --- a/include/boost/geometry/index/detail/nonassignable.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Boost.Geometry Index -// -// Nonassignable base class. -// -// 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_NONASSIGNABLE_HPP -#define BOOST_GEOMETRY_INDEX_DETAIL_NONASSIGNABLE_HPP - -namespace boost { namespace geometry { namespace index { namespace detail { - -class nonassignable -{ - nonassignable & operator=(nonassignable const&); -}; - -}}}} // namespace boost::geometry::index::detail - -#endif // BOOST_GEOMETRY_INDEX_DETAIL_NONASSIGNABLE_HPP diff --git a/include/boost/geometry/index/detail/rtree/node/auto_deallocator.hpp b/include/boost/geometry/index/detail/rtree/node/auto_deallocator.hpp new file mode 100644 index 000000000..dd55c6d76 --- /dev/null +++ b/include/boost/geometry/index/detail/rtree/node/auto_deallocator.hpp @@ -0,0 +1,38 @@ +// Boost.Geometry Index +// +// R-tree auto deallocator +// +// 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_RTREE_NODE_AUTO_DEALLOCATOR_HPP +#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_AUTO_DEALLOCATOR_HPP + +namespace boost { namespace geometry { namespace index { + +namespace detail { namespace rtree { + +template +class auto_deallocator +{ + auto_deallocator(auto_deallocator const&); + auto_deallocator & operator=(auto_deallocator const&); +public: + typedef typename Alloc::pointer pointer; + inline auto_deallocator(Alloc & a, pointer p) : m_alloc(a), m_ptr(p) {} + inline ~auto_deallocator() { if ( m_ptr ) boost::container::allocator_traits::deallocate(m_alloc, m_ptr, 1); } + inline void release() { m_ptr = 0; } + inline pointer ptr() { return m_ptr; } +private: + Alloc & m_alloc; + pointer m_ptr; +}; + +}} // namespace detail::rtree + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_AUTO_DEALLOCATOR_HPP 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 93bad4178..477d937db 100644 --- a/include/boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp +++ b/include/boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp @@ -72,13 +72,6 @@ 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); -//} - // apply visitor template diff --git a/include/boost/geometry/index/detail/rtree/node/node.hpp b/include/boost/geometry/index/detail/rtree/node/node.hpp index bc4c62d26..ad927dfdb 100644 --- a/include/boost/geometry/index/detail/rtree/node/node.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node.hpp @@ -148,14 +148,14 @@ struct clear_node }; template -void copy_from_back(Container & container, Iterator it) +void move_from_back(Container & container, Iterator it) { BOOST_GEOMETRY_INDEX_ASSERT(!container.empty(), "cannot copy from empty container"); Iterator back_it = container.end(); --back_it; if ( it != back_it ) { - *it = *back_it; // MAY THROW (copy) + *it = boost::move(*back_it); // MAY THROW (copy) } } 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 d0da104fc..48528dcf3 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 @@ -14,6 +14,7 @@ #include #include +#include namespace boost { namespace geometry { namespace index { @@ -252,25 +253,19 @@ struct create_dynamic_node template static inline BaseNodePtr apply(AllocNode & alloc_node) { - typedef typename AllocNode::pointer P; + typedef boost::container::allocator_traits Al; + typedef typename Al::pointer P; - P p = alloc_node.allocate(1); + P p = Al::allocate(alloc_node, 1); if ( 0 == p ) throw std::bad_alloc(); // TODO throw different exception - try - { - // NOTE/TODO - // Here the whole node may be copied - alloc_node.construct(p, Node(alloc_node)); - } - catch(...) - { - alloc_node.deallocate(p, 1); - throw; - } + auto_deallocator deallocator(alloc_node, p); + Al::construct(alloc_node, p, alloc_node); + + deallocator.release(); return p; } }; @@ -283,11 +278,12 @@ struct destroy_dynamic_node template static inline void apply(AllocNode & alloc_node, BaseNodePtr n) { - typedef typename AllocNode::pointer P; + typedef boost::container::allocator_traits Al; + typedef typename Al::pointer P; P p(&static_cast(rtree::get(*n))); - alloc_node.destroy(p); - alloc_node.deallocate(p, 1); + Al::destroy(alloc_node, p); + Al::deallocate(alloc_node, p, 1); } }; 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 b263c4c5b..8e35e8494 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 @@ -168,40 +168,6 @@ public: leaf_allocator_type const& leaf_allocator() const{ return *this; } }; -// create_node - -template -struct create_node< - Allocators, - dynamic_internal_node -> -{ - static inline typename Allocators::node_pointer - apply(Allocators & allocators) - { - return create_dynamic_node< - typename Allocators::node_pointer, - dynamic_internal_node - >::apply(allocators.internal_node_allocator()); - } -}; - -template -struct create_node< - Allocators, - dynamic_leaf -> -{ - static inline typename Allocators::node_pointer - apply(Allocators & allocators) - { - return create_dynamic_node< - typename Allocators::node_pointer, - dynamic_leaf - >::apply(allocators.leaf_allocator()); - } -}; - }} // namespace detail::rtree }}} // namespace boost::geometry::index 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 e3f66544f..bfba1a61e 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 @@ -150,23 +150,19 @@ struct create_static_node template static inline VariantPtr apply(AllocNode & alloc_node) { - VariantPtr p = alloc_node.allocate(1); + typedef boost::container::allocator_traits Al; + typedef typename Al::pointer P; + + P p = Al::allocate(alloc_node, 1); if ( 0 == p ) throw std::bad_alloc(); - try - { - // NOTE/TODO - // Here the whole node may be copied - alloc_node.construct(p, Node(alloc_node)); // implicit cast to Variant - } - catch(...) - { - alloc_node.deallocate(p, 1); - throw; - } + auto_deallocator deallocator(alloc_node, p); + Al::construct(alloc_node, p, Node(alloc_node)); // implicit cast to Variant + + deallocator.release(); return p; } }; @@ -179,8 +175,11 @@ struct destroy_static_node template static inline void apply(AllocNode & alloc_node, VariantPtr n) { - alloc_node.destroy(n); - alloc_node.deallocate(n, 1); + typedef boost::container::allocator_traits Al; + typedef typename Al::pointer P; + + Al::destroy(alloc_node, n); + Al::deallocate(alloc_node, n, 1); } }; diff --git a/include/boost/geometry/index/detail/rtree/quadratic/redistribute_elements.hpp b/include/boost/geometry/index/detail/rtree/quadratic/redistribute_elements.hpp index eeda1adec..2ce58335a 100644 --- a/include/boost/geometry/index/detail/rtree/quadratic/redistribute_elements.hpp +++ b/include/boost/geometry/index/detail/rtree/quadratic/redistribute_elements.hpp @@ -137,16 +137,16 @@ struct redistribute_elements template class insert : public rtree::visitor::type - , index::detail::nonassignable { typedef typename Options::parameters_type parameters_type; diff --git a/include/boost/geometry/index/detail/rtree/rstar/redistribute_elements.hpp b/include/boost/geometry/index/detail/rtree/rstar/redistribute_elements.hpp index 75c78f0b5..6e1b828ee 100644 --- a/include/boost/geometry/index/detail/rtree/rstar/redistribute_elements.hpp +++ b/include/boost/geometry/index/detail/rtree/rstar/redistribute_elements.hpp @@ -11,8 +11,6 @@ #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_RSTAR_REDISTRIBUTE_ELEMENTS_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_RSTAR_REDISTRIBUTE_ELEMENTS_HPP -#include - #include #include #include @@ -29,7 +27,6 @@ namespace rstar { template class element_axis_corner_less - : index::detail::nonassignable { public: element_axis_corner_less(Translator const& tr) diff --git a/include/boost/geometry/index/detail/rtree/visitors/children_box.hpp b/include/boost/geometry/index/detail/rtree/visitors/children_box.hpp index 4d5310b3a..90eba7c18 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/children_box.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/children_box.hpp @@ -20,7 +20,6 @@ namespace detail { namespace rtree { namespace visitors { template class children_box : public rtree::visitor::type - , index::detail::nonassignable { typedef typename rtree::internal_node::type internal_node; typedef typename rtree::leaf::type leaf; diff --git a/include/boost/geometry/index/detail/rtree/visitors/count.hpp b/include/boost/geometry/index/detail/rtree/visitors/count.hpp index 2c1d8717f..1c37dcf52 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/count.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/count.hpp @@ -20,7 +20,6 @@ namespace detail { namespace rtree { namespace visitors { template struct count : public rtree::visitor::type - , index::detail::nonassignable { typedef typename rtree::node::type node; typedef typename rtree::internal_node::type internal_node; @@ -69,7 +68,6 @@ struct count template struct count : public rtree::visitor::type - , index::detail::nonassignable { typedef typename rtree::node::type node; typedef typename rtree::internal_node::type internal_node; diff --git a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp index 16c6465a5..ff26419d9 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp @@ -223,7 +223,6 @@ struct insert_traverse_data template class insert : public rtree::visitor::type - , index::detail::nonassignable { protected: typedef typename Options::parameters_type parameters_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 18aee5404..fddb0e719 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp @@ -159,7 +159,6 @@ template < > class nearest_query : public rtree::visitor::type - , index::detail::nonassignable { public: typedef typename Options::parameters_type parameters_type; diff --git a/include/boost/geometry/index/detail/rtree/visitors/remove.hpp b/include/boost/geometry/index/detail/rtree/visitors/remove.hpp index 4786df510..33cca203c 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/remove.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/remove.hpp @@ -25,7 +25,6 @@ namespace detail { namespace rtree { namespace visitors { template class remove : public rtree::visitor::type - , index::detail::nonassignable { typedef typename Options::parameters_type parameters_type; @@ -138,7 +137,7 @@ public: { if ( m_translator.equals(*it, m_value) ) { - rtree::copy_from_back(elements, it); // MAY THROW (V: copy) + rtree::move_from_back(elements, it); // MAY THROW (V: copy) elements.pop_back(); m_is_value_removed = true; break; @@ -199,7 +198,7 @@ private: try { - rtree::copy_from_back(elements, underfl_el_it); // MAY THROW (E: copy) + rtree::move_from_back(elements, underfl_el_it); // MAY THROW (E: copy) elements.pop_back(); } catch(...) 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 87b0e4904..986aec547 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/spatial_query.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/spatial_query.hpp @@ -22,7 +22,6 @@ namespace detail { namespace rtree { namespace visitors { template struct spatial_query : public rtree::visitor::type - , index::detail::nonassignable { typedef typename rtree::node::type node; typedef typename rtree::internal_node::type internal_node; diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index 105dd1791..4d0b5c80c 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -20,7 +20,6 @@ #include #include -#include #include #include