|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72573 - in sandbox-branches/geometry/index_080_new: boost/geometry/extensions/index/rtree boost/geometry/extensions/index/rtree/rstar boost/geometry/extensions/index/rtree/visitors boost/geometry/extensions/index/translator tests
From: adam.wulkiewicz_at_[hidden]
Date: 2011-06-13 17:04:56
Author: awulkiew
Date: 2011-06-13 17:04:55 EDT (Mon, 13 Jun 2011)
New Revision: 72573
URL: http://svn.boost.org/trac/boost/changeset/72573
Log:
translator::getter added + some cleanup e.g. in /rstar/insert.hpp visitors::insert replaced by detail::rstar::insert.
Added:
sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/translator/getter.hpp (contents, props changed)
sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/translator/translator.hpp (contents, props changed)
Text files modified:
sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rstar/insert.hpp | 186 +++++++++++++++------------------------
sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rtree.hpp | 2
sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/visitors/insert.hpp | 3
sandbox-branches/geometry/index_080_new/tests/translators.hpp | 18 +++
4 files changed, 91 insertions(+), 118 deletions(-)
Modified: sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rstar/insert.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rstar/insert.hpp (original)
+++ sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rstar/insert.hpp 2011-06-13 17:04:55 EDT (Mon, 13 Jun 2011)
@@ -364,133 +364,91 @@
}
};
+} // namespace rstar
+
+} // namespace detail
+
// R*-tree insert visitor
template <typename Element, typename Value, typename Options, typename Translator, typename Box>
-class insert : public rtree::visitor<Value, Box, typename Options::node_tag, false>::type
+class insert<Element, Value, Options, Translator, Box, reinsert_tag>
+ : public rtree::visitor<Value, Box, typename Options::node_tag, false>::type
{
-protected:
- typedef typename rtree::node<Value, Box, typename Options::node_tag>::type node;
- typedef typename rtree::internal_node<Value, Box, typename Options::node_tag>::type internal_node;
- typedef typename rtree::leaf<Value, Box, typename Options::node_tag>::type leaf;
+private:
+ typedef typename rtree::node<Value, Box, typename Options::node_tag>::type node;
+ typedef typename rtree::internal_node<Value, Box, typename Options::node_tag>::type internal_node;
+ typedef typename rtree::leaf<Value, Box, typename Options::node_tag>::type leaf;
public:
- inline insert(node* & root,
- size_t & leafs_level,
- Element const& element,
- size_t min_elements,
- size_t max_elements,
- Translator const& tr,
- size_t relative_level = 0
- )
- : m_root(root), m_leafs_level(leafs_level), m_element(element)
- , m_min_elements(min_elements), m_max_elements(max_elements)
- , m_tr(tr), m_relative_level(relative_level)
- {}
-
- inline void operator()(internal_node & n)
- {
- typedef typename elements_type<internal_node>::type elements_type;
-
- rstar::level_insert<0, Element, Value, Options, Translator, Box> lins_v(
- m_root, m_leafs_level, m_element, m_min_elements, m_max_elements, m_tr, m_relative_level);
-
- rtree::apply_visitor(lins_v, n);
-
- if ( !lins_v.result_elements.empty() )
- {
- recursive_reinsert(lins_v.result_elements, lins_v.result_relative_level);
- }
- }
-
- inline void operator()(leaf & n)
- {
- rstar::level_insert<0, Element, Value, Options, Translator, Box> lins_v(
- m_root, m_leafs_level, m_element, m_min_elements, m_max_elements, m_tr, m_relative_level);
+ inline insert(node* & root,
+ size_t & leafs_level,
+ Element const& element,
+ size_t min_elements,
+ size_t max_elements,
+ Translator const& tr,
+ size_t relative_level = 0)
+ : m_root(root), m_leafs_level(leafs_level), m_element(element)
+ , m_min_elements(min_elements), m_max_elements(max_elements)
+ , m_tr(tr), m_relative_level(relative_level)
+ {}
+
+ inline void operator()(internal_node & n)
+ {
+ typedef typename elements_type<internal_node>::type elements_type;
+
+ detail::rstar::level_insert<0, Element, Value, Options, Translator, Box> lins_v(
+ m_root, m_leafs_level, m_element, m_min_elements, m_max_elements, m_tr, m_relative_level);
+
+ rtree::apply_visitor(lins_v, n);
+
+ if ( !lins_v.result_elements.empty() )
+ {
+ recursive_reinsert(lins_v.result_elements, lins_v.result_relative_level);
+ }
+ }
+
+ inline void operator()(leaf & n)
+ {
+ detail::rstar::level_insert<0, Element, Value, Options, Translator, Box> lins_v(
+ m_root, m_leafs_level, m_element, m_min_elements, m_max_elements, m_tr, m_relative_level);
- rtree::apply_visitor(lins_v, n);
+ rtree::apply_visitor(lins_v, n);
// we're in the root, so root should be split and there should be no elements to reinsert
- assert(lins_v.result_elements.empty());
- }
+ assert(lins_v.result_elements.empty());
+ }
-protected:
- template <typename Elements>
- inline void recursive_reinsert(Elements const& elements, size_t relative_level)
- {
- typedef typename Elements::value_type element_type;
-
- // reinsert children starting from the minimum distance
- for ( typename Elements::const_reverse_iterator it = elements.rbegin();
- it != elements.rend(); ++it)
- {
- rstar::level_insert<1, element_type, Value, Options, Translator, Box> lins_v(
- m_root, m_leafs_level, *it, m_min_elements, m_max_elements, m_tr, relative_level);
+private:
+ template <typename Elements>
+ inline void recursive_reinsert(Elements const& elements, size_t relative_level)
+ {
+ typedef typename Elements::value_type element_type;
+
+ // reinsert children starting from the minimum distance
+ for ( typename Elements::const_reverse_iterator it = elements.rbegin();
+ it != elements.rend(); ++it)
+ {
+ detail::rstar::level_insert<1, element_type, Value, Options, Translator, Box> lins_v(
+ m_root, m_leafs_level, *it, m_min_elements, m_max_elements, m_tr, relative_level);
- rtree::apply_visitor(lins_v, *m_root);
+ rtree::apply_visitor(lins_v, *m_root);
- assert(relative_level + 1 == lins_v.result_relative_level);
+ assert(relative_level + 1 == lins_v.result_relative_level);
// non-root relative level
- if ( lins_v.result_relative_level < m_leafs_level && !lins_v.result_elements.empty())
- {
- recursive_reinsert(lins_v.result_elements, lins_v.result_relative_level);
- }
- }
- }
-
- node* & m_root;
- size_t & m_leafs_level;
- Element const& m_element;
- size_t m_min_elements;
- size_t m_max_elements;
- Translator const& m_tr;
- size_t m_relative_level;
-};
-
-} // namespace rstar
-
-} // namespace detail
-
-// R*-tree insert visitor
-template <typename Element, typename Value, typename Options, typename Translator, typename Box>
-class insert<Element, Value, Options, Translator, Box, reinsert_tag>
- : public detail::rstar::insert<Element, Value, Options, Translator, Box>
-{
- typedef detail::rstar::insert<Element, Value, Options, Translator, Box> base;
- typedef typename base::node node;
-
-public:
- inline insert(node* & root,
- size_t & leafs_level,
- Element const& element,
- size_t min_elements,
- size_t max_elements,
- Translator const& tr,
- size_t relative_level = 0
- )
- : base(root, leafs_level, element, min_elements, max_elements, tr, relative_level)
- {}
-};
-
-// R*-tree insert visitor
-template <typename Value, typename Options, typename Translator, typename Box>
-class insert<Value, Value, Options, Translator, Box, reinsert_tag>
- : public detail::rstar::insert<Value, Value, Options, Translator, Box>
-{
- typedef detail::rstar::insert<Value, Value, Options, Translator, Box> base;
- typedef typename base::node node;
-
-public:
- inline insert(node* & root,
- size_t & leafs_level,
- Value const& element,
- size_t min_elements,
- size_t max_elements,
- Translator const& tr,
- size_t relative_level = 0
- )
- : base(root, leafs_level, element, min_elements, max_elements, tr, relative_level)
- {}
+ if ( lins_v.result_relative_level < m_leafs_level && !lins_v.result_elements.empty())
+ {
+ recursive_reinsert(lins_v.result_elements, lins_v.result_relative_level);
+ }
+ }
+ }
+
+ node* & m_root;
+ size_t & m_leafs_level;
+ Element const& m_element;
+ size_t m_min_elements;
+ size_t m_max_elements;
+ Translator const& m_tr;
+ size_t m_relative_level;
};
}}} // namespace detail::rtree::visitors
Modified: sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rtree.hpp (original)
+++ sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/rtree.hpp 2011-06-13 17:04:55 EDT (Mon, 13 Jun 2011)
@@ -14,7 +14,7 @@
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
-#include <boost/geometry/extensions/index/translator/def.hpp>
+#include <boost/geometry/extensions/index/translator/translator.hpp>
#include <boost/geometry/extensions/index/rtree/options.hpp>
#include <boost/geometry/extensions/index/rtree/filters.hpp>
Modified: sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/visitors/insert.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/visitors/insert.hpp (original)
+++ sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/rtree/visitors/insert.hpp 2011-06-13 17:04:55 EDT (Mon, 13 Jun 2011)
@@ -227,10 +227,11 @@
} // namespace detail
+// Insert visitor forward declaration
template <typename Element, typename Value, typename Options, typename Translator, typename Box, typename InsertTag>
struct insert;
-// Default insert visitor
+// Default insert visitor used for nodes elements
template <typename Element, typename Value, typename Options, typename Translator, typename Box>
struct insert<Element, Value, Options, Translator, Box, insert_tag>
: public detail::insert<Element, Value, Options, Translator, Box>
Added: sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/translator/getter.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/translator/getter.hpp 2011-06-13 17:04:55 EDT (Mon, 13 Jun 2011)
@@ -0,0 +1,33 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - value to bounding object translation as a getter (object's member function)
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_TRANSLATOR_GETTER_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_GETTER_HPP
+
+namespace boost { namespace geometry { namespace index { namespace translator {
+
+template <typename Value, typename Indexable, Indexable const& (Value::*Getter)() const>
+struct getter
+{
+ typedef Indexable indexable_type;
+
+ indexable_type const& operator()(Value const& v) const
+ {
+ return (v.*Getter)();
+ }
+
+ bool equals(Value const& v1, Value const& v2) const
+ {
+ return geometry::equals(operator()(v1), operator()(v2));
+ }
+};
+
+}}}} // namespace boost::geometry::index::translator
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_GETTER_HPP
Added: sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/translator/translator.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080_new/boost/geometry/extensions/index/translator/translator.hpp 2011-06-13 17:04:55 EDT (Mon, 13 Jun 2011)
@@ -0,0 +1,17 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - translators
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_TRANSLATOR_TRANSLATOR_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_TRANSLATOR_HPP
+
+#include <boost/geometry/extensions/index/translator/def.hpp>
+#include <boost/geometry/extensions/index/translator/index.hpp>
+#include <boost/geometry/extensions/index/translator/getter.hpp>
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_TRANSLATOR_HPP
Modified: sandbox-branches/geometry/index_080_new/tests/translators.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_new/tests/translators.hpp (original)
+++ sandbox-branches/geometry/index_080_new/tests/translators.hpp 2011-06-13 17:04:55 EDT (Mon, 13 Jun 2011)
@@ -5,8 +5,7 @@
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/extensions/index/rtree/rtree.hpp>
-#include <boost/geometry/extensions/index/translator/def.hpp>
-#include <boost/geometry/extensions/index/translator/index.hpp>
+#include <boost/geometry/extensions/index/translator/translator.hpp>
#include <vector>
#include <map>
@@ -14,6 +13,17 @@
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
+template <typename Indexable>
+struct tests_translators_val
+{
+ Indexable const& get_box() const
+ {
+ return i;
+ }
+
+ Indexable i;
+};
+
void tests_translators_hpp()
{
std::cout << "tests/translators.hpp\n";
@@ -68,6 +78,10 @@
B tmp_b;
tmp_b = d( std::pair<model::polygon<P>, B>() );
tmp_b = dd( std::pair<B, model::polygon<P> >() );
+
+ tests_translators_val<P> val_p;
+ index::translator::getter<tests_translators_val<P>, P, &tests_translators_val<P>::get_box> tr_get_p;
+ tmp_p = tr_get_p(val_p);
}
#endif // TESTS_TRANSLATORS_HPP
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk