Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85037 - in trunk/boost/geometry/index: . detail
From: adam.wulkiewicz_at_[hidden]
Date: 2013-07-14 14:18:26


Author: awulkiew
Date: 2013-07-14 14:18:26 EDT (Sun, 14 Jul 2013)
New Revision: 85037
URL: http://svn.boost.org/trac/boost/changeset/85037

Log:
[geometry][index]: serialization of node type removed - currently there are only 2 types which may be deduced from leafs_level, check of the number of loaded values added.

Text files modified:
   trunk/boost/geometry/index/detail/serialization.hpp | 38 +++++++++++++++++++++++---------------
   trunk/boost/geometry/index/rtree.hpp | 32 ++++++++++++++++++++------------
   2 files changed, 43 insertions(+), 27 deletions(-)

Modified: trunk/boost/geometry/index/detail/serialization.hpp
==============================================================================
--- trunk/boost/geometry/index/detail/serialization.hpp Sun Jul 14 13:26:02 2013 (r85036)
+++ trunk/boost/geometry/index/detail/serialization.hpp 2013-07-14 14:18:26 EDT (Sun, 14 Jul 2013) (r85037)
@@ -275,9 +275,9 @@
         typedef typename rtree::elements_type<internal_node>::type elements_type;
         elements_type const& elements = rtree::elements(n);
 
- char t = 'i';
+ // change to elements_type::size_type or size_type?
         size_t s = elements.size();
- m_archive << t << s;
+ m_archive << s;
 
         for (typename elements_type::const_iterator it = elements.begin() ; it != elements.end() ; ++it)
         {
@@ -290,11 +290,12 @@
     inline void operator()(leaf const& l)
     {
         typedef typename rtree::elements_type<leaf>::type elements_type;
+ typedef typename elements_type::size_type elements_size;
         elements_type const& elements = rtree::elements(l);
 
- char t = 'l';
+ // change to elements_type::size_type or size_type?
         size_t s = elements.size();
- m_archive << t << s;
+ m_archive << s;
 
         for (typename elements_type::const_iterator it = elements.begin() ; it != elements.end() ; ++it)
         {
@@ -327,21 +328,26 @@
 
 public:
     template <typename Archive> inline static
- node_pointer apply(Archive & ar, unsigned int version, parameters_type const& parameters, Translator const& translator, Allocators & allocators)
+ node_pointer apply(Archive & ar, unsigned int version, size_type leafs_level, size_type & values_count, parameters_type const& parameters, Translator const& translator, Allocators & allocators)
     {
- char t;
- ar >> t;
+ values_count = 0;
+ return raw_apply(ar, version, leafs_level, values_count, parameters, translator, allocators);
+ }
 
- if ( t == 'n' )
- return node_pointer(0);
+private:
+ template <typename Archive> inline static
+ node_pointer raw_apply(Archive & ar, unsigned int version, size_type leafs_level, size_type & values_count, parameters_type const& parameters, Translator const& translator, Allocators & allocators, size_type current_level = 0)
+ {
+ //BOOST_GEOMETRY_INDEX_ASSERT(current_level <= leafs_level, "invalid parameter");
 
+ // change to elements_type::size_type or size_type?
         size_t elements_count;
         ar >> elements_count;
 
         if ( elements_count < parameters.get_min_elements() || parameters.get_max_elements() < elements_count )
             BOOST_THROW_EXCEPTION(std::runtime_error("rtree loading error"));
 
- if ( t == 'i' )
+ if ( current_level < leafs_level )
         {
             node_pointer n = rtree::create_node<Allocators, internal_node>::apply(allocators); // MAY THROW (A)
             node_auto_ptr auto_remover(n, allocators);
@@ -349,6 +355,7 @@
 
             typedef typename rtree::elements_type<internal_node>::type elements_type;
             typedef typename elements_type::value_type element_type;
+ typedef typename elements_type::size_type elements_size;
             elements_type & elements = rtree::elements(in);
 
             elements.reserve(elements_count); // MAY THROW (A)
@@ -357,15 +364,17 @@
             {
                 typedef typename elements_type::value_type::first_type box_type;
                 box_type b = serialization_load<box_type>(ar);
- node_pointer n = apply(ar, version, parameters, translator, allocators); // recursive call
+ node_pointer n = raw_apply(ar, version, leafs_level, values_count, parameters, translator, allocators, current_level+1); // recursive call
                 elements.push_back(element_type(b, n));
             }
 
             auto_remover.release();
             return n;
         }
- else if ( t == 'l' )
+ else
         {
+ BOOST_GEOMETRY_INDEX_ASSERT(current_level == leafs_level, "unexpected value");
+
             node_pointer n = rtree::create_node<Allocators, leaf>::apply(allocators); // MAY THROW (A)
             node_auto_ptr auto_remover(n, allocators);
             leaf & l = rtree::get<leaf>(*n);
@@ -374,6 +383,8 @@
             typedef typename elements_type::value_type element_type;
             elements_type & elements = rtree::elements(l);
 
+ values_count += elements_count;
+
             elements.reserve(elements_count); // MAY THROW (A)
 
             for ( size_t i = 0 ; i < elements_count ; ++i )
@@ -385,9 +396,6 @@
             auto_remover.release();
             return n;
         }
-
- BOOST_THROW_EXCEPTION(std::runtime_error("rtree loading error"));
- //return node_pointer(0);
     }
 };
 

Modified: trunk/boost/geometry/index/rtree.hpp
==============================================================================
--- trunk/boost/geometry/index/rtree.hpp Sun Jul 14 13:26:02 2013 (r85036)
+++ trunk/boost/geometry/index/rtree.hpp 2013-07-14 14:18:26 EDT (Sun, 14 Jul 2013) (r85037)
@@ -1226,18 +1226,16 @@
     {
         detail::serialization_save(m_members.parameters(), ar);
 
- ar << m_members.values_count; // might be removed
- ar << m_members.leafs_level; // might be removed
- if ( m_members.root )
+ ar << m_members.values_count;
+ ar << m_members.leafs_level;
+
+ if ( m_members.values_count )
         {
+ BOOST_GEOMETRY_INDEX_ASSERT(m_members.root, "root shouldn't be null_ptr");
+
             detail::rtree::visitors::save<Archive, Value, options_type, translator_type, box_type, allocators_type> save_v(ar, version);
             detail::rtree::apply_visitor(save_v, *m_members.root);
         }
- else
- {
- char t = 'n';
- ar << t;
- }
     }
 
     template<class Archive>
@@ -1246,11 +1244,21 @@
         parameters_type params = detail::serialization_load<parameters_type>(ar);
         
         size_type values_count, leafs_level;
- ar >> values_count; // might be removed
- ar >> leafs_level; // might be removed
+ ar >> values_count;
+ ar >> leafs_level;
 
- node_pointer n = detail::rtree::load<value_type, options_type, translator_type, box_type, allocators_type>
- ::apply(ar, version, params, m_members.translator(), m_members.allocators()); // MAY THROW
+ node_pointer n(0);
+ if ( 0 < values_count )
+ {
+ size_type loaded_values_count = 0;
+ n = detail::rtree::load<value_type, options_type, translator_type, box_type, allocators_type>
+ ::apply(ar, version, leafs_level, loaded_values_count, params, m_members.translator(), m_members.allocators()); // MAY THROW
+
+ node_auto_ptr remover(n, m_members.allocators());
+ if ( loaded_values_count != values_count )
+ BOOST_THROW_EXCEPTION(std::runtime_error("unexpected number of values")); // TODO change exception type
+ remover.release();
+ }
 
         m_members.parameters() = params;
         m_members.values_count = values_count;


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