mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-13 12:32:09 +00:00
rtree: copy_from_back() replaced by move_from_back(), auto_deallocator used instead of try-catch block in create_node, nonassignable removed, container::allocator_traits used in create_node
[SVN r82964]
This commit is contained in:
@@ -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
|
||||
@@ -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 <typename Alloc>
|
||||
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<Alloc>::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
|
||||
@@ -72,13 +72,6 @@ inline Derived & get(dynamic_node<Value, Parameters, Box, Allocators, Tag> & n)
|
||||
return static_cast<Derived&>(n);
|
||||
}
|
||||
|
||||
//template <typename Derived, typename Parameters, typename Value, typename Box, typename Allocators, typename Tag>
|
||||
//inline Derived * get(dynamic_node<Value, Parameters, Box, Allocators, Tag> * n)
|
||||
//{
|
||||
// BOOST_GEOMETRY_INDEX_ASSERT(dynamic_cast<Derived*>(n), "can't cast to a Derived type");
|
||||
// return static_cast<Derived*>(n);
|
||||
//}
|
||||
|
||||
// apply visitor
|
||||
|
||||
template <typename Visitor, typename Visitable>
|
||||
|
||||
@@ -148,14 +148,14 @@ struct clear_node
|
||||
};
|
||||
|
||||
template <typename Container, typename Iterator>
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <boost/container/vector.hpp>
|
||||
|
||||
#include <boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp>
|
||||
#include <boost/geometry/index/detail/rtree/node/auto_deallocator.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index {
|
||||
|
||||
@@ -252,25 +253,19 @@ struct create_dynamic_node
|
||||
template <typename AllocNode>
|
||||
static inline BaseNodePtr apply(AllocNode & alloc_node)
|
||||
{
|
||||
typedef typename AllocNode::pointer P;
|
||||
typedef boost::container::allocator_traits<AllocNode> 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<AllocNode> deallocator(alloc_node, p);
|
||||
|
||||
Al::construct(alloc_node, p, alloc_node);
|
||||
|
||||
deallocator.release();
|
||||
return p;
|
||||
}
|
||||
};
|
||||
@@ -283,11 +278,12 @@ struct destroy_dynamic_node
|
||||
template <typename AllocNode, typename BaseNodePtr>
|
||||
static inline void apply(AllocNode & alloc_node, BaseNodePtr n)
|
||||
{
|
||||
typedef typename AllocNode::pointer P;
|
||||
typedef boost::container::allocator_traits<AllocNode> Al;
|
||||
typedef typename Al::pointer P;
|
||||
|
||||
P p(&static_cast<Node&>(rtree::get<Node>(*n)));
|
||||
alloc_node.destroy(p);
|
||||
alloc_node.deallocate(p, 1);
|
||||
Al::destroy(alloc_node, p);
|
||||
Al::deallocate(alloc_node, p, 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -168,40 +168,6 @@ public:
|
||||
leaf_allocator_type const& leaf_allocator() const{ return *this; }
|
||||
};
|
||||
|
||||
// create_node
|
||||
|
||||
template <typename Allocators, typename Value, typename Parameters, typename Box>
|
||||
struct create_node<
|
||||
Allocators,
|
||||
dynamic_internal_node<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
|
||||
>
|
||||
{
|
||||
static inline typename Allocators::node_pointer
|
||||
apply(Allocators & allocators)
|
||||
{
|
||||
return create_dynamic_node<
|
||||
typename Allocators::node_pointer,
|
||||
dynamic_internal_node<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
|
||||
>::apply(allocators.internal_node_allocator());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Allocators, typename Value, typename Parameters, typename Box>
|
||||
struct create_node<
|
||||
Allocators,
|
||||
dynamic_leaf<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
|
||||
>
|
||||
{
|
||||
static inline typename Allocators::node_pointer
|
||||
apply(Allocators & allocators)
|
||||
{
|
||||
return create_dynamic_node<
|
||||
typename Allocators::node_pointer,
|
||||
dynamic_leaf<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
|
||||
>::apply(allocators.leaf_allocator());
|
||||
}
|
||||
};
|
||||
|
||||
}} // namespace detail::rtree
|
||||
|
||||
}}} // namespace boost::geometry::index
|
||||
|
||||
@@ -150,23 +150,19 @@ struct create_static_node
|
||||
template <typename AllocNode>
|
||||
static inline VariantPtr apply(AllocNode & alloc_node)
|
||||
{
|
||||
VariantPtr p = alloc_node.allocate(1);
|
||||
typedef boost::container::allocator_traits<AllocNode> 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<AllocNode> 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 <typename AllocNode, typename VariantPtr>
|
||||
static inline void apply(AllocNode & alloc_node, VariantPtr n)
|
||||
{
|
||||
alloc_node.destroy(n);
|
||||
alloc_node.deallocate(n, 1);
|
||||
typedef boost::container::allocator_traits<AllocNode> Al;
|
||||
typedef typename Al::pointer P;
|
||||
|
||||
Al::destroy(alloc_node, n);
|
||||
Al::deallocate(alloc_node, n, 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -137,16 +137,16 @@ struct redistribute_elements<Value, Options, Translator, Box, Allocators, quadra
|
||||
// remove seeds
|
||||
if (seed1 < seed2)
|
||||
{
|
||||
rtree::copy_from_back(elements_copy, elements_copy.begin() + seed2); // MAY THROW, STRONG (copy)
|
||||
rtree::move_from_back(elements_copy, elements_copy.begin() + seed2); // MAY THROW, STRONG (copy)
|
||||
elements_copy.pop_back();
|
||||
rtree::copy_from_back(elements_copy, elements_copy.begin() + seed1); // MAY THROW, STRONG (copy)
|
||||
rtree::move_from_back(elements_copy, elements_copy.begin() + seed1); // MAY THROW, STRONG (copy)
|
||||
elements_copy.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
rtree::copy_from_back(elements_copy, elements_copy.begin() + seed1); // MAY THROW, STRONG (copy)
|
||||
rtree::move_from_back(elements_copy, elements_copy.begin() + seed1); // MAY THROW, STRONG (copy)
|
||||
elements_copy.pop_back();
|
||||
rtree::copy_from_back(elements_copy, elements_copy.begin() + seed2); // MAY THROW, STRONG (copy)
|
||||
rtree::move_from_back(elements_copy, elements_copy.begin() + seed2); // MAY THROW, STRONG (copy)
|
||||
elements_copy.pop_back();
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ struct redistribute_elements<Value, Options, Translator, Box, Allocators, quadra
|
||||
|
||||
BOOST_GEOMETRY_INDEX_ASSERT(!elements_copy.empty(), "expected more elements");
|
||||
typename elements_type::iterator el_it_base = el_it.base();
|
||||
rtree::copy_from_back(elements_copy, --el_it_base); // MAY THROW, STRONG (copy)
|
||||
rtree::move_from_back(elements_copy, --el_it_base); // MAY THROW, STRONG (copy)
|
||||
elements_copy.pop_back();
|
||||
|
||||
BOOST_GEOMETRY_INDEX_ASSERT(0 < remaining, "expected more remaining elements");
|
||||
|
||||
@@ -436,7 +436,6 @@ struct level_insert<0, Value, Value, Options, Translator, Box, Allocators>
|
||||
template <typename Element, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
|
||||
class insert<Element, Value, Options, Translator, Box, Allocators, insert_reinsert_tag>
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, false>::type
|
||||
, index::detail::nonassignable
|
||||
{
|
||||
typedef typename Options::parameters_type parameters_type;
|
||||
|
||||
|
||||
@@ -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 <boost/geometry/index/detail/nonassignable.hpp>
|
||||
|
||||
#include <boost/geometry/index/detail/algorithms/intersection_content.hpp>
|
||||
#include <boost/geometry/index/detail/algorithms/union_content.hpp>
|
||||
#include <boost/geometry/index/detail/algorithms/margin.hpp>
|
||||
@@ -29,7 +27,6 @@ namespace rstar {
|
||||
|
||||
template <typename Element, typename Translator, size_t Corner, size_t AxisIndex>
|
||||
class element_axis_corner_less
|
||||
: index::detail::nonassignable
|
||||
{
|
||||
public:
|
||||
element_axis_corner_less(Translator const& tr)
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace detail { namespace rtree { namespace visitors {
|
||||
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
|
||||
class children_box
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
|
||||
, index::detail::nonassignable
|
||||
{
|
||||
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
|
||||
typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace detail { namespace rtree { namespace visitors {
|
||||
template <typename Indexable, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
|
||||
struct count
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
|
||||
, index::detail::nonassignable
|
||||
{
|
||||
typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
|
||||
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
|
||||
@@ -69,7 +68,6 @@ struct count
|
||||
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
|
||||
struct count<Value, Value, Options, Translator, Box, Allocators>
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
|
||||
, index::detail::nonassignable
|
||||
{
|
||||
typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
|
||||
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
|
||||
|
||||
@@ -223,7 +223,6 @@ struct insert_traverse_data
|
||||
template <typename Element, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
|
||||
class insert
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, false>::type
|
||||
, index::detail::nonassignable
|
||||
{
|
||||
protected:
|
||||
typedef typename Options::parameters_type parameters_type;
|
||||
|
||||
@@ -159,7 +159,6 @@ template <
|
||||
>
|
||||
class nearest_query
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
|
||||
, index::detail::nonassignable
|
||||
{
|
||||
public:
|
||||
typedef typename Options::parameters_type parameters_type;
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace detail { namespace rtree { namespace visitors {
|
||||
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
|
||||
class remove
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, false>::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(...)
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace detail { namespace rtree { namespace visitors {
|
||||
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators, typename Predicates, typename OutIter>
|
||||
struct spatial_query
|
||||
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
|
||||
, index::detail::nonassignable
|
||||
{
|
||||
typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
|
||||
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <boost/geometry/geometry.hpp>
|
||||
|
||||
#include <boost/geometry/index/detail/assert.hpp>
|
||||
#include <boost/geometry/index/detail/nonassignable.hpp>
|
||||
|
||||
#include <boost/geometry/index/translator/translator.hpp>
|
||||
#include <boost/geometry/index/detail/rtree/options.hpp>
|
||||
|
||||
Reference in New Issue
Block a user