diff --git a/include/boost/geometry/index/detail/rtree/node/node.hpp b/include/boost/geometry/index/detail/rtree/node/node.hpp index ad927dfdb..d35dcbb6f 100644 --- a/include/boost/geometry/index/detail/rtree/node/node.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node.hpp @@ -11,11 +11,18 @@ #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_HPP -#include +#include +#include +#include +#include +#include + +#include #include #include +#include #include #include 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 c282e91f0..0c3e89a11 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 @@ -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 - -#include -#include - namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { @@ -25,11 +20,11 @@ struct dynamic_internal_node { typedef typename Allocators::leaf_allocator_type::template rebind< - std::pair + rtree::ptr_pair >::other elements_allocator_type; typedef boost::container::vector< - std::pair, + rtree::ptr_pair, elements_allocator_type > elements_type; @@ -96,61 +91,37 @@ struct visitor type; }; -template -struct translator_wrapper_helper -{ - typedef typename Element::first_type element_indexable_type; - typedef typename Element::first_type const& element_indexable_result; -}; - -template -struct translator_wrapper_helper -{ - 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; + typedef typename translator::indexable_type::type type; +}; + +template +struct element_indexable_type< + rtree::ptr_pair, + Translator +> +{ + typedef First type; }; // element's indexable getter template -typename Translator::template element_indexable_result::type +typename Translator::result_type element_indexable(Element const& el, Translator const& tr) { - return tr.element_indexable(el); + return tr(el); +} + +template +First const& +element_indexable(rtree::ptr_pair const& el, Translator const& /*tr*/) +{ + return el.first; } // nodes elements 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 8e35e8494..a73437045 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 @@ -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 -#include - namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { @@ -23,11 +20,11 @@ struct dynamic_internal_node { typedef typename Allocators::leaf_allocator_type::template rebind< - std::pair + rtree::ptr_pair >::other elements_allocator_type; typedef detail::varray< - std::pair, + rtree::ptr_pair, Parameters::max_elements + 1, elements_allocator_type > elements_type; 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 2090aabb3..b3331e9c8 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 @@ -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 - -#include - namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { @@ -25,11 +21,11 @@ template + rtree::ptr_pair >::other elements_allocator_type; typedef boost::container::vector< - std::pair, + rtree::ptr_pair, elements_allocator_type > elements_type; 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 a480034ef..252db0c82 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 @@ -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 - -#include - namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { @@ -25,11 +21,11 @@ template { typedef typename Allocators::node_allocator_type::template rebind< - std::pair + rtree::ptr_pair >::other elements_allocator_type; typedef detail::varray< - std::pair, + rtree::ptr_pair, Parameters::max_elements + 1, elements_allocator_type > elements_type; diff --git a/include/boost/geometry/index/detail/rtree/node/pairs.hpp b/include/boost/geometry/index/detail/rtree/node/pairs.hpp new file mode 100644 index 000000000..8cdbdd131 --- /dev/null +++ b/include/boost/geometry/index/detail/rtree/node/pairs.hpp @@ -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 + +namespace boost { namespace geometry { namespace index { + +namespace detail { namespace rtree { + +template +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 inline +ptr_pair +make_ptr_pair(First const& f, Pointer s) +{ + return ptr_pair(f, s); +} + +template +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 inline +exclusive_ptr_pair +make_exclusive_ptr_pair(First const& f, Pointer s) +{ + return exclusive_ptr_pair(f, s); +} + +}} // namespace detail::rtree + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_PAIRS_HPP diff --git a/include/boost/geometry/index/detail/rtree/node/ptr_pair.hpp b/include/boost/geometry/index/detail/rtree/node/ptr_pair.hpp deleted file mode 100644 index 716d2145a..000000000 --- a/include/boost/geometry/index/detail/rtree/node/ptr_pair.hpp +++ /dev/null @@ -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 - -namespace boost { namespace geometry { namespace index { - -namespace detail { namespace rtree { - -template -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 inline -ptr_pair -make_ptr_pair(First const& f, Pointer s) -{ - return ptr_pair(f, s); -} - -}} // namespace detail::rtree - -}}} // namespace boost::geometry::index - -#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_PTR_PAIR_HPP diff --git a/include/boost/geometry/index/detail/rtree/visitors/copy.hpp b/include/boost/geometry/index/detail/rtree/visitors/copy.hpp index c832cb892..8a084d479 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/copy.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/copy.hpp @@ -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(); } diff --git a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp index ff26419d9..d872a14da 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp @@ -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::apply(m_allocators), m_allocators); // MAY THROW, STRONG (N:alloc) try { - rtree::elements(rtree::get(*new_root)).push_back(std::make_pair(n_box, m_root_node)); // MAY THROW, STRONG (E:alloc, copy) + rtree::elements(rtree::get(*new_root)).push_back(rtree::make_ptr_pair(n_box, m_root_node)); // MAY THROW, STRONG (E:alloc, copy) rtree::elements(rtree::get(*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 diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index bb6df47da..35a114eab 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -132,7 +132,6 @@ 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: @@ -713,7 +712,7 @@ public: return result; } - detail::rtree::visitors::children_box + detail::rtree::visitors::children_box 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 + detail::rtree::visitors::count 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 + detail::rtree::visitors::destroy 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 + detail::rtree::visitors::copy 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 + detail::rtree::visitors::destroy 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 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_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)) , values_count(0) @@ -1074,7 +1073,7 @@ private: template 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; } diff --git a/test/rtree/exceptions/test_rtree_exceptions.hpp b/test/rtree/exceptions/test_rtree_exceptions.hpp index db1520bcf..eea2ac6f8 100644 --- a/test/rtree/exceptions/test_rtree_exceptions.hpp +++ b/test/rtree/exceptions/test_rtree_exceptions.hpp @@ -76,7 +76,7 @@ struct dynamic_internal_node { typedef throwing_varray< - std::pair, + rtree::ptr_pair, Parameters::max_elements + 1 > elements_type;