Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74646 - in sandbox-branches/geometry/index/boost/geometry/extensions/index: . algorithms rtree rtree/visitors
From: adam.wulkiewicz_at_[hidden]
Date: 2011-10-02 06:49:56


Author: awulkiew
Date: 2011-10-02 06:49:54 EDT (Sun, 02 Oct 2011)
New Revision: 74646
URL: http://svn.boost.org/trac/boost/changeset/74646

Log:
destroy visitor moddified, some asserts added.
Added:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/algorithms/is_valid.hpp (contents, props changed)
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/distance_predicates.hpp | 24 ++++++++++++++++--------
   sandbox-branches/geometry/index/boost/geometry/extensions/index/predicates.hpp | 6 ------
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp | 31 ++++++++++++++++++-------------
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/destroy.hpp | 7 ++++---
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp | 1 +
   5 files changed, 39 insertions(+), 30 deletions(-)

Added: sandbox-branches/geometry/index/boost/geometry/extensions/index/algorithms/is_valid.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/algorithms/is_valid.hpp 2011-10-02 06:49:54 EDT (Sun, 02 Oct 2011)
@@ -0,0 +1,82 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - n-dimensional box's / point validity check
+//
+// 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_ALGORITHMS_IS_VALID_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_IS_VALID_HPP
+
+namespace boost { namespace geometry { namespace index {
+
+namespace detail {
+
+template <typename Box, size_t Dimension>
+struct is_valid_box
+{
+ BOOST_MPL_ASSERT_MSG(
+ (0 < Dimension && Dimension <= index::traits::dimension<Box>::value),
+ INVALID_DIMENSION_PARAMETER,
+ (is_valid_box));
+
+ static inline bool apply(Box const& b)
+ {
+ return is_valid_box<Box, Dimension - 1>::apply(b) &&
+ ( index::get<min_corner, Dimension - 1>(b) <= index::get<max_corner, Dimension - 1>(b) );
+ }
+};
+
+template <typename Box>
+struct is_valid_box<Box, 1>
+{
+ static inline bool apply(Box const& b)
+ {
+ return index::get<min_corner, 0>(b) <= index::get<max_corner, 0>(b);
+ }
+};
+
+} // namespace detail
+
+namespace dispatch {
+
+template <typename Indexable, typename Tag>
+struct is_valid
+{
+ BOOST_MPL_ASSERT_MSG(
+ (false),
+ NOT_IMPLEMENTED_FOR_THIS_INDEXABLE,
+ (is_valid));
+};
+
+template <typename Indexable>
+struct is_valid<Indexable, point_tag>
+{
+ static inline bool apply(Indexable const&)
+ {
+ return true;
+ }
+};
+
+template <typename Indexable>
+struct is_valid<Indexable, box_tag>
+{
+ static inline bool apply(Indexable const& b)
+ {
+ return detail::is_valid_box<Indexable, index::traits::dimension<Indexable>::value>::apply(b);
+ }
+};
+
+} // namespace dispatch
+
+template <typename Indexable>
+inline bool is_valid(Indexable const& b)
+{
+ return dispatch::is_valid<Indexable, typename index::traits::tag<Indexable>::type>::apply(b);
+}
+
+}}} // namespace boost::geometry::index
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_IS_VALID_HPP

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/distance_predicates.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/distance_predicates.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/distance_predicates.hpp 2011-10-02 06:49:54 EDT (Sun, 02 Oct 2011)
@@ -347,14 +347,22 @@
     template <typename Tag2>
     static inline type & get(cdist<T, Tag> & cd)
     {
- // TODO MPL_ASSERT tuples::equal<CDist, cdist<T, Tag>>::value
+ BOOST_MPL_ASSERT_MSG(
+ (tuples::equal< cdist<T, Tag2>, cdist<T, Tag> >::value),
+ TAGS_DO_NOT_MATCH,
+ (cdist_value));
+
         return cd.value;
     }
 
     template <typename Tag2>
     static inline type const& get(cdist<T, Tag> const& cd)
     {
- // TODO MPL_ASSERT tuples::equal<CDist, cdist<T, Tag>>::value
+ BOOST_MPL_ASSERT_MSG(
+ (tuples::equal< cdist<T, Tag2>, cdist<T, Tag> >::value),
+ TAGS_DO_NOT_MATCH,
+ (cdist_value));
+
         return cd.value;
     }
 };
@@ -368,7 +376,10 @@
 template <typename RelDist>
 struct distances_calc_impl_rel
 {
- // TODO MPL_ASSERT not implemented for this RelDist
+ BOOST_MPL_ASSERT_MSG(
+ (false),
+ NOT_IMPLEMENTED_FOR_THIS_RELATION,
+ (distances_calc_impl_rel));
 };
 
 template <typename T>
@@ -603,11 +614,8 @@
 
 // distances_predicates_check
 
-// TODO explicitly define DistanceType ?
-// Indexable/Box is used in distances_predicates_check only for purpose of
-// this explicit DistanceType definition
-
-// move distance_calc and distance_comp into geometry::index ?
+// TODO explicitly define Distances type ?
+// TODO move distance_calc and distance_comp into geometry::index ?
 
 template <typename PointRelation, typename Indexable, typename Tag>
 struct distances_predicates_check

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/predicates.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/predicates.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/predicates.hpp 2011-10-02 06:49:54 EDT (Sun, 02 Oct 2011)
@@ -182,12 +182,6 @@
 
 // predicate check
 
-// TODO: use empty definitions here + MPL_ASSERT ?
-// implement default values predicates applied to values in leafs, as a function/functor as simple as possible
-// bool fun(Value const& v);
-// distinguish between geometries and other types by use of geometry::tag
-// in predicate_check_default<..., GeomTag> -> predicate_check_default<..., void>
-
 // TODO: awulkiew - consider passing Value/Node and Translator instead of
 // Value and Indexable
 

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp 2011-10-02 06:49:54 EDT (Sun, 02 Oct 2011)
@@ -27,6 +27,8 @@
 
 #include <boost/geometry/extensions/index/rtree/node/node.hpp>
 
+#include <boost/geometry/extensions/index/algorithms/is_valid.hpp>
+
 #include <boost/geometry/extensions/index/rtree/visitors/insert.hpp>
 #include <boost/geometry/extensions/index/rtree/visitors/remove.hpp>
 #include <boost/geometry/extensions/index/rtree/visitors/copy.hpp>
@@ -123,10 +125,16 @@
 
     inline void insert(value_type const& value)
     {
- // TODO: awulkiew - assert for correct value
+ BOOST_GEOMETRY_INDEX_ASSERT(index::is_valid(m_translator(value)), "Indexable is invalid");
 
- detail::rtree::visitors::insert<value_type, value_type, options_type, translator_type, box_type, typename options_type::insert_tag>
- insert_v(m_root, m_leafs_level, value, m_translator);
+ detail::rtree::visitors::insert<
+ value_type,
+ value_type,
+ options_type,
+ translator_type,
+ box_type,
+ typename options_type::insert_tag
+ > insert_v(m_root, m_leafs_level, value, m_translator);
 
         detail::rtree::apply_visitor(insert_v, *m_root);
 
@@ -142,12 +150,16 @@
 
     inline void remove(value_type const& value)
     {
- // TODO: awulkiew - assert for correct value
+ // TODO: awulkiew - assert for correct value (indexable) ?
 
         BOOST_GEOMETRY_INDEX_ASSERT(0 < m_values_count, "can't remove, there is no elements in the rtree");
 
- detail::rtree::visitors::remove<value_type, options_type, translator_type, box_type>
- remove_v(m_root, m_leafs_level, value, m_translator);
+ detail::rtree::visitors::remove<
+ value_type,
+ options_type,
+ translator_type,
+ box_type
+ > remove_v(m_root, m_leafs_level, value, m_translator);
 
         detail::rtree::apply_visitor(remove_v, *m_root);
 
@@ -253,8 +265,6 @@
 private:
     inline void create()
     {
- // TODO: awulkiew - consider moving create_node into the insert visitor
- // and here setting m_root to 0
         m_root = detail::rtree::create_node(leaf());
         m_values_count = 0;
         m_leafs_level = 0;
@@ -265,11 +275,6 @@
         detail::rtree::visitors::destroy<value_type, options_type, translator_type, box_type> del_v;
         detail::rtree::apply_visitor(del_v, *t.m_root);
 
- // TODO: awulkiew - consider moving this into the destroy visitor
- // but have in mind that visitors works on references
- // and address from reference would be passed here
- detail::rtree::delete_node(t.m_root);
-
         t.m_root = 0;
         t.m_values_count = 0;
         t.m_leafs_level = 0;

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/destroy.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/destroy.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/destroy.hpp 2011-10-02 06:49:54 EDT (Sun, 02 Oct 2011)
@@ -31,13 +31,14 @@
             it != elements.end(); ++it)
         {
             rtree::apply_visitor(*this, *it->second);
-
- rtree::delete_node(it->second);
         }
+
+ rtree::delete_node(&n);
     }
 
- inline void operator()(leaf &)
+ inline void operator()(leaf &n)
     {
+ rtree::delete_node(&n);
     }
 };
 

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/insert.hpp 2011-10-02 06:49:54 EDT (Sun, 02 Oct 2011)
@@ -184,6 +184,7 @@
     {
         BOOST_GEOMETRY_INDEX_ASSERT(m_relative_level <= leafs_level, "unexpected level value");
         BOOST_GEOMETRY_INDEX_ASSERT(m_level <= m_leafs_level, "unexpected level value");
+ BOOST_GEOMETRY_INDEX_ASSERT(0 != m_root_node, "there is no root node");
         // TODO
         // assert - check if Box is correct
     }


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