rtree: translator_wrapper removed,

detail::rtree::ptr_pair used in internal nodes instead of std::pair.

[SVN r83000]
This commit is contained in:
Adam Wulkiewicz
2013-02-19 14:20:06 +00:00
parent a3778c9097
commit b09c83883d
11 changed files with 123 additions and 137 deletions

View File

@@ -11,11 +11,18 @@
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_HPP
#include <boost/geometry/index/detail/rtree/node/concept.hpp>
#include <boost/container/vector.hpp>
#include <boost/geometry/index/detail/varray.hpp>
#include <boost/geometry/index/detail/rtree/node/concept.hpp>
#include <boost/geometry/index/detail/rtree/node/pairs.hpp>
#include <boost/geometry/index/detail/rtree/node/auto_deallocator.hpp>
#include <boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp>
#include <boost/geometry/index/detail/rtree/node/node_d_mem_dynamic.hpp>
#include <boost/geometry/index/detail/rtree/node/node_d_mem_static.hpp>
#include <boost/geometry/index/detail/rtree/node/static_visitor.hpp>
#include <boost/geometry/index/detail/rtree/node/node_s_mem_dynamic.hpp>
#include <boost/geometry/index/detail/rtree/node/node_s_mem_static.hpp>

View File

@@ -11,11 +11,6 @@
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_HPP
#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 {
namespace detail { namespace rtree {
@@ -25,11 +20,11 @@ struct dynamic_internal_node<Value, Parameters, Box, Allocators, node_d_mem_dyna
: public dynamic_node<Value, Parameters, Box, Allocators, node_d_mem_dynamic_tag>
{
typedef typename Allocators::leaf_allocator_type::template rebind<
std::pair<Box, typename Allocators::node_pointer>
rtree::ptr_pair<Box, typename Allocators::node_pointer>
>::other elements_allocator_type;
typedef boost::container::vector<
std::pair<Box, typename Allocators::node_pointer>,
rtree::ptr_pair<Box, typename Allocators::node_pointer>,
elements_allocator_type
> elements_type;
@@ -96,61 +91,37 @@ struct visitor<Value, Parameters, Box, Allocators, node_d_mem_dynamic_tag, IsVis
typedef dynamic_visitor<Value, Parameters, Box, Allocators, node_d_mem_dynamic_tag, IsVisitableConst> type;
};
template <typename Element, typename Value, typename Translator>
struct translator_wrapper_helper
{
typedef typename Element::first_type element_indexable_type;
typedef typename Element::first_type const& element_indexable_result;
};
template <typename Value, typename Translator>
struct translator_wrapper_helper<Value, Value, Translator>
{
typedef typename translator::indexable_type<Translator>::type element_indexable_type;
typedef typename Translator::result_type element_indexable_result;
};
template <typename Value, typename Translator, typename Tag>
struct translator_wrapper
: public Translator
{
translator_wrapper(Translator const& t = Translator()) : Translator(t) {}
template <typename Element>
struct element_indexable_type
{
typedef typename translator_wrapper_helper<Element, Value, Translator>::element_indexable_type type;
};
template <typename Element>
struct element_indexable_result
{
typedef typename translator_wrapper_helper<Element, Value, Translator>::element_indexable_result type;
};
typename element_indexable_result<Value>::type
element_indexable(Value const& v) const { return Translator::operator()(v); }
template <typename Element>
typename element_indexable_result<Element>::type
element_indexable(Element const& el) const { return el.first; }
};
// element's indexable type
template <typename Element, typename Translator>
struct element_indexable_type
{
typedef typename Translator::template element_indexable_type<Element>::type type;
typedef typename translator::indexable_type<Translator>::type type;
};
template <typename First, typename Pointer, typename Translator>
struct element_indexable_type<
rtree::ptr_pair<First, Pointer>,
Translator
>
{
typedef First type;
};
// element's indexable getter
template <typename Element, typename Translator>
typename Translator::template element_indexable_result<Element>::type
typename Translator::result_type
element_indexable(Element const& el, Translator const& tr)
{
return tr.element_indexable(el);
return tr(el);
}
template <typename First, typename Pointer, typename Translator>
First const&
element_indexable(rtree::ptr_pair<First, Pointer> const& el, Translator const& /*tr*/)
{
return el.first;
}
// nodes elements

View File

@@ -11,9 +11,6 @@
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_STATIC_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_STATIC_HPP
#include <boost/geometry/index/detail/rtree/node/dynamic_visitor.hpp>
#include <boost/geometry/index/detail/varray.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree {
@@ -23,11 +20,11 @@ struct dynamic_internal_node<Value, Parameters, Box, Allocators, node_d_mem_stat
: public dynamic_node<Value, Parameters, Box, Allocators, node_d_mem_static_tag>
{
typedef typename Allocators::leaf_allocator_type::template rebind<
std::pair<Box, typename Allocators::node_pointer>
rtree::ptr_pair<Box, typename Allocators::node_pointer>
>::other elements_allocator_type;
typedef detail::varray<
std::pair<Box, typename Allocators::node_pointer>,
rtree::ptr_pair<Box, typename Allocators::node_pointer>,
Parameters::max_elements + 1,
elements_allocator_type
> elements_type;

View File

@@ -11,10 +11,6 @@
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_VARIANT_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_VARIANT_HPP
#include <boost/container/vector.hpp>
#include <boost/geometry/index/detail/rtree/node/static_visitor.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree {
@@ -25,11 +21,11 @@ template <typename Value, typename Parameters, typename Box, typename Allocators
struct static_internal_node
{
typedef typename Allocators::node_allocator_type::template rebind<
std::pair<Box, typename Allocators::node_pointer>
rtree::ptr_pair<Box, typename Allocators::node_pointer>
>::other elements_allocator_type;
typedef boost::container::vector<
std::pair<Box, typename Allocators::node_pointer>,
rtree::ptr_pair<Box, typename Allocators::node_pointer>,
elements_allocator_type
> elements_type;

View File

@@ -11,10 +11,6 @@
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_STATIC_VARIANT_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_DEFAULT_STATIC_VARIANT_HPP
#include <boost/geometry/index/detail/varray.hpp>
#include <boost/geometry/index/detail/rtree/node/static_visitor.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree {
@@ -25,11 +21,11 @@ template <typename Value, typename Parameters, typename Box, typename Allocators
struct static_internal_node<Value, Parameters, Box, Allocators, node_s_mem_static_tag>
{
typedef typename Allocators::node_allocator_type::template rebind<
std::pair<Box, typename Allocators::node_pointer>
rtree::ptr_pair<Box, typename Allocators::node_pointer>
>::other elements_allocator_type;
typedef detail::varray<
std::pair<Box, typename Allocators::node_pointer>,
rtree::ptr_pair<Box, typename Allocators::node_pointer>,
Parameters::max_elements + 1,
elements_allocator_type
> elements_type;

View File

@@ -0,0 +1,69 @@
// Boost.Geometry Index
//
// Pairs intended to be used internally in nodes.
//
// 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_PAIRS_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_PAIRS_HPP
#include <boost/move/move.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree {
template <typename First, typename Pointer>
class ptr_pair
{
public:
typedef First first_type;
typedef Pointer second_type;
ptr_pair(First const& f, Pointer s) : first(f), second(s) {}
ptr_pair(ptr_pair const& p) : first(p.first), second(p.second) {}
ptr_pair & operator=(ptr_pair const& p) { first = p.first; second = p.second; return *this; }
first_type first;
second_type second;
};
template <typename First, typename Pointer> inline
ptr_pair<First, Pointer>
make_ptr_pair(First const& f, Pointer s)
{
return ptr_pair<First, Pointer>(f, s);
}
template <typename First, typename Pointer>
class exclusive_ptr_pair
{
BOOST_MOVABLE_BUT_NOT_COPYABLE(exclusive_ptr_pair)
public:
typedef First first_type;
typedef Pointer second_type;
exclusive_ptr_pair(First const& f, Pointer s) : first(f), second(s) {}
// INFO - members aren't really moved!
exclusive_ptr_pair(BOOST_RV_REF(exclusive_ptr_pair) p) : first(p.first), second(p.second) { p.second = 0; }
exclusive_ptr_pair & operator=(BOOST_RV_REF(exclusive_ptr_pair) p) { first = p.first; second = p.second; p.second = 0; return *this; }
first_type first;
second_type second;
};
template <typename First, typename Pointer> inline
exclusive_ptr_pair<First, Pointer>
make_exclusive_ptr_pair(First const& f, Pointer s)
{
return exclusive_ptr_pair<First, Pointer>(f, s);
}
}} // namespace detail::rtree
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_PAIRS_HPP

View File

@@ -1,49 +0,0 @@
// Boost.Geometry Index
//
// Movable-only pair intended to be used internally in nodes.
// It may be used to provide exclusive ownership of node pointers
//
// 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_PTR_PAIR_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_PTR_PAIR_HPP
#include <boost/move/move.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree {
template <typename First, typename Pointer>
class ptr_pair
{
BOOST_MOVABLE_BUT_NOT_COPYABLE(ptr_pair)
public:
typedef First first_type;
typedef Pointer second_type;
ptr_pair(First const& f, Pointer s) : first(f), second(s) {}
// INFO - members aren't really moved!
ptr_pair(BOOST_RV_REF(ptr_pair) p) : first(p.first), second(p.second) { p.second = 0; }
ptr_pair & operator=(BOOST_RV_REF(ptr_pair) p) { first = p.first; second = p.second; p.second = 0; return *this; }
first_type first;
second_type second;
};
template <typename First, typename Pointer> inline
ptr_pair<First, Pointer>
make_ptr_pair(First const& f, Pointer s)
{
return ptr_pair<First, Pointer>(f, s);
}
}} // namespace detail::rtree
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_PTR_PAIR_HPP

View File

@@ -52,7 +52,7 @@ public:
// for exception safety
node_auto_ptr auto_result(result, m_allocators);
elements_dst.push_back( std::make_pair(it->first, result) ); // MAY THROW, STRONG (E: alloc, copy)
elements_dst.push_back( rtree::make_ptr_pair(it->first, result) ); // MAY THROW, STRONG (E: alloc, copy)
auto_result.release();
}

View File

@@ -169,7 +169,7 @@ public:
"unexpected number of elements");
// return the list of newly created nodes (this algorithm returns one)
additional_nodes.push_back(std::make_pair(box2, second_node.get())); // MAY THROW, STRONG (alloc, copy)
additional_nodes.push_back(rtree::make_ptr_pair(box2, second_node.get())); // MAY THROW, STRONG (alloc, copy)
// release the ptr
second_node.release();
@@ -352,7 +352,7 @@ protected:
node_auto_ptr new_root(rtree::create_node<Allocators, internal_node>::apply(m_allocators), m_allocators); // MAY THROW, STRONG (N:alloc)
try {
rtree::elements(rtree::get<internal_node>(*new_root)).push_back(std::make_pair(n_box, m_root_node)); // MAY THROW, STRONG (E:alloc, copy)
rtree::elements(rtree::get<internal_node>(*new_root)).push_back(rtree::make_ptr_pair(n_box, m_root_node)); // MAY THROW, STRONG (E:alloc, copy)
rtree::elements(rtree::get<internal_node>(*new_root)).push_back(additional_nodes[0]); // MAY THROW, STRONG (E:alloc, copy)
} catch (...) {
// clear new root to not delete in the ~node_auto_ptr() potentially stored old root node

View File

@@ -132,7 +132,6 @@ private:
typedef typename detail::rtree::internal_node<value_type, typename options_type::parameters_type, box_type, allocators_type, node_tag>::type internal_node;
typedef typename detail::rtree::leaf<value_type, typename options_type::parameters_type, box_type, allocators_type, node_tag>::type leaf;
typedef detail::rtree::translator_wrapper<Value, Translator, node_tag> translator_wrapper;
typedef typename allocators_type::node_pointer node_pointer;
public:
@@ -713,7 +712,7 @@ public:
return result;
}
detail::rtree::visitors::children_box<value_type, options_type, translator_wrapper, box_type, allocators_type>
detail::rtree::visitors::children_box<value_type, options_type, translator_type, box_type, allocators_type>
box_v(result, m_members.translator());
detail::rtree::apply_visitor(box_v, *m_members.root);
@@ -739,7 +738,7 @@ public:
if ( !m_members.root )
return 0;
detail::rtree::visitors::count<ValueOrIndexable, value_type, options_type, translator_wrapper, box_type, allocators_type>
detail::rtree::visitors::count<ValueOrIndexable, value_type, options_type, translator_type, box_type, allocators_type>
count_v(vori, m_members.translator());
detail::rtree::apply_visitor(count_v, *m_members.root);
@@ -855,7 +854,7 @@ private:
detail::rtree::visitors::insert<
value_type,
value_type, options_type, translator_wrapper, box_type, allocators_type,
value_type, options_type, translator_type, box_type, allocators_type,
typename options_type::insert_tag
> insert_v(m_members.root, m_members.leafs_level, value,
m_members.parameters(), m_members.translator(), m_members.allocators());
@@ -885,7 +884,7 @@ private:
BOOST_GEOMETRY_INDEX_ASSERT(m_members.root, "The root must exist");
detail::rtree::visitors::remove<
value_type, options_type, translator_wrapper, box_type, allocators_type
value_type, options_type, translator_type, box_type, allocators_type
> remove_v(m_members.root, m_members.leafs_level, value,
m_members.parameters(), m_members.translator(), m_members.allocators());
@@ -932,7 +931,7 @@ private:
{
if ( t.m_members.root )
{
detail::rtree::visitors::destroy<value_type, options_type, translator_wrapper, box_type, allocators_type>
detail::rtree::visitors::destroy<value_type, options_type, translator_type, box_type, allocators_type>
del_v(t.m_members.root, t.m_members.allocators());
detail::rtree::apply_visitor(del_v, *t.m_members.root);
@@ -955,7 +954,7 @@ private:
*/
inline void raw_copy(rtree const& src, rtree & dst, bool copy_all_internals) const
{
detail::rtree::visitors::copy<value_type, options_type, translator_wrapper, box_type, allocators_type>
detail::rtree::visitors::copy<value_type, options_type, translator_type, box_type, allocators_type>
copy_v(dst.m_members.allocators());
if ( src.m_members.root )
@@ -969,7 +968,7 @@ private:
if ( dst.m_members.root )
{
detail::rtree::visitors::destroy<value_type, options_type, translator_wrapper, box_type, allocators_type>
detail::rtree::visitors::destroy<value_type, options_type, translator_type, box_type, allocators_type>
del_v(dst.m_members.root, dst.m_members.allocators());
detail::rtree::apply_visitor(del_v, *dst.m_members.root);
dst.m_members.root = 0;
@@ -989,7 +988,7 @@ private:
template <typename Predicates, typename OutIter>
size_type query_dispatch(Predicates const& predicates, OutIter out_it, boost::mpl::bool_<false> const& /*is_nearest*/) const
{
detail::rtree::visitors::spatial_query<value_type, options_type, translator_wrapper, box_type, allocators_type, Predicates, OutIter>
detail::rtree::visitors::spatial_query<value_type, options_type, translator_type, box_type, allocators_type, Predicates, OutIter>
find_v(m_members.translator(), predicates, out_it);
detail::rtree::apply_visitor(find_v, *m_members.root);
@@ -1027,7 +1026,7 @@ private:
typedef detail::rtree::visitors::nearest_query_result_k<
value_type,
translator_wrapper,
translator_type,
point_type,
OutIter
> result_type;
@@ -1037,7 +1036,7 @@ private:
detail::rtree::visitors::nearest_query<
value_type,
options_type,
translator_wrapper,
translator_type,
box_type,
allocators_type,
DistancesPredicates,
@@ -1051,7 +1050,7 @@ private:
}
struct members_holder
: public translator_wrapper
: public translator_type
, public Parameters
, public allocators_type
{
@@ -1063,7 +1062,7 @@ private:
members_holder(Transl const& transl,
Parameters const& parameters,
BOOST_FWD_REF(Alloc) alloc)
: translator_wrapper(transl)
: translator_type(transl)
, Parameters(parameters)
, allocators_type(boost::forward<Alloc>(alloc))
, values_count(0)
@@ -1074,7 +1073,7 @@ private:
template <typename Transl>
members_holder(Transl const& transl = Translator(),
Parameters const& parameters = Parameters())
: translator_wrapper(transl)
: translator_type(transl)
, Parameters(parameters)
, allocators_type()
, values_count(0)
@@ -1082,8 +1081,8 @@ private:
, root(0)
{}
translator_wrapper const& translator() const { return *this; }
translator_wrapper & translator() { return *this; }
translator_type const& translator() const { return *this; }
translator_type & translator() { return *this; }
Parameters const& parameters() const { return *this; }
Parameters & parameters() { return *this; }
allocators_type const& allocators() const { return *this; }

View File

@@ -76,7 +76,7 @@ struct dynamic_internal_node<Value, Parameters, Box, Allocators, node_throwing_d
: public dynamic_node<Value, Parameters, Box, Allocators, node_throwing_d_mem_static_tag>
{
typedef throwing_varray<
std::pair<Box, typename Allocators::node_pointer>,
rtree::ptr_pair<Box, typename Allocators::node_pointer>,
Parameters::max_elements + 1
> elements_type;