Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59443 - in trunk: boost boost/multi_index/detail libs/multi_index/doc libs/multi_index/test
From: joaquin_at_[hidden]
Date: 2010-02-03 09:29:56


Author: joaquin
Date: 2010-02-03 09:29:55 EST (Wed, 03 Feb 2010)
New Revision: 59443
URL: http://svn.boost.org/trac/boost/changeset/59443

Log:
completed fix in [58485] with proper handling of value_type serialization class versioning
Added:
   trunk/boost/multi_index/detail/serialization_version.hpp (contents, props changed)
Text files modified:
   trunk/boost/multi_index_container.hpp | 33 +++++++++++++++++++++++----------
   trunk/libs/multi_index/doc/release_notes.html | 17 ++++++++++++++---
   trunk/libs/multi_index/test/test_serialization3.cpp | 26 ++++++++++++++++++++++----
   3 files changed, 59 insertions(+), 17 deletions(-)

Added: trunk/boost/multi_index/detail/serialization_version.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/multi_index/detail/serialization_version.hpp 2010-02-03 09:29:55 EST (Wed, 03 Feb 2010)
@@ -0,0 +1,75 @@
+/* Copyright 2003-2010 Joaquin M Lopez Munoz.
+ * Distributed under 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)
+ *
+ * See http://www.boost.org/libs/multi_index for library home page.
+ */
+
+#ifndef BOOST_MULTI_INDEX_DETAIL_SERIALIZATION_VERSION_HPP
+#define BOOST_MULTI_INDEX_DETAIL_SERIALIZATION_VERSION_HPP
+
+#if defined(_MSC_VER)&&(_MSC_VER>=1200)
+#pragma once
+#endif
+
+#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
+#include <boost/serialization/split_member.hpp>
+#include <boost/serialization/version.hpp>
+
+namespace boost{
+
+namespace multi_index{
+
+namespace detail{
+
+/* Helper class for storing and retrieving a given type serialization class
+ * version while avoiding saving the number multiple times in the same
+ * archive.
+ * Behavior undefined if template partial specialization is not supported.
+ */
+
+template<typename T>
+struct serialization_version
+{
+ serialization_version():
+ value(boost::serialization::version<serialization_version>::value){}
+
+ serialization_version& operator=(unsigned int x){value=x;return *this;};
+
+ operator unsigned int()const{return value;}
+
+private:
+ friend class boost::serialization::access;
+
+ BOOST_SERIALIZATION_SPLIT_MEMBER()
+
+ template<class Archive>
+ void save(Archive&,const unsigned int)const{}
+
+ template<class Archive>
+ void load(Archive&,const unsigned int version)
+ {
+ this->value=version;
+ }
+
+ unsigned int value;
+};
+
+} /* namespace multi_index::detail */
+
+} /* namespace multi_index */
+
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+namespace serialization {
+template<typename T>
+struct version<boost::multi_index::detail::serialization_version<T> >
+{
+ BOOST_STATIC_CONSTANT(unsigned int,value=version<T>::value);
+};
+} /* namespace serialization */
+#endif
+
+} /* namespace boost */
+
+#endif

Modified: trunk/boost/multi_index_container.hpp
==============================================================================
--- trunk/boost/multi_index_container.hpp (original)
+++ trunk/boost/multi_index_container.hpp 2010-02-03 09:29:55 EST (Wed, 03 Feb 2010)
@@ -1,6 +1,6 @@
 /* Multiply indexed container.
  *
- * Copyright 2003-2009 Joaquin M Lopez Munoz.
+ * Copyright 2003-2010 Joaquin M Lopez Munoz.
  * Distributed under 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)
@@ -44,6 +44,7 @@
 
 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
 #include <boost/multi_index/detail/archive_constructed.hpp>
+#include <boost/multi_index/detail/serialization_version.hpp>
 #include <boost/serialization/collection_size_type.hpp>
 #include <boost/serialization/nvp.hpp>
 #include <boost/serialization/split_member.hpp>
@@ -634,17 +635,20 @@
   {
 
 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
- const serialization::collection_size_type s(size_());
+ const serialization::collection_size_type s(size_());
+ const detail::serialization_version<value_type> value_version;
     ar<<serialization::make_nvp("count",s);
+ ar<<serialization::make_nvp("value_version",value_version);
 #else
- const std::size_t s=size_();
+ const std::size_t s=size_();
+ const unsigned int value_version=0;
     ar<<serialization::make_nvp("count",s);
 #endif
 
     index_saver_type sm(bfm_allocator::member,s);
 
     for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
- serialization::save_construct_data_adl(ar,&*it,version);
+ serialization::save_construct_data_adl(ar,&*it,value_version);
       ar<<serialization::make_nvp("item",*it);
       sm.add(it.get_node(),ar,version);
     }
@@ -661,7 +665,8 @@
     clear_();
 
 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
- serialization::collection_size_type s;
+ serialization::collection_size_type s;
+ detail::serialization_version<value_type> value_version;
     if(version<1){
       std::size_t sz;
       ar>>serialization::make_nvp("count",sz);
@@ -670,15 +675,22 @@
     else{
       ar>>serialization::make_nvp("count",s);
     }
+ if(version<2){
+ value_version=0;
+ }
+ else{
+ ar>>serialization::make_nvp("value_version",value_version);
+ }
 #else
- std::size_t s;
+ std::size_t s;
+ unsigned int value_version=0;
     ar>>serialization::make_nvp("count",s);
 #endif
 
     index_loader_type lm(bfm_allocator::member,s);
 
     for(std::size_t n=0;n<s;++n){
- detail::archive_constructed<Value> value("item",ar,version);
+ detail::archive_constructed<Value> value("item",ar,value_version);
       std::pair<node_type*,bool> p=insert_(
         value.get(),super::end().get_node());
       if(!p.second)throw_exception(
@@ -1101,8 +1113,9 @@
 
 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)&&\
     !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
-/* Serialization class version bump as we now serialize the size
- * through boost::serialization::collection_size_type.
+/* class version = 1 : we now serialize the size through
+ * boost::serialization::collection_size_type.
+ * class version = 2 : proper use of {save|load}_construct_data.
  */
 
 namespace serialization {
@@ -1111,7 +1124,7 @@
   boost::multi_index_container<Value,IndexSpecifierList,Allocator>
>
 {
- BOOST_STATIC_CONSTANT(unsigned int,value=1);
+ BOOST_STATIC_CONSTANT(unsigned int,value=2);
 };
 } /* namespace serialization */
 #endif

Modified: trunk/libs/multi_index/doc/release_notes.html
==============================================================================
--- trunk/libs/multi_index/doc/release_notes.html (original)
+++ trunk/libs/multi_index/doc/release_notes.html 2010-02-03 09:29:55 EST (Wed, 03 Feb 2010)
@@ -31,6 +31,7 @@
 <h2>Contents</h2>
 
 <ul>
+ <li>Boost 1.43 release</li>
   <li>Boost 1.42 release</li>
   <li>Boost 1.41 release</li>
   <li>Boost 1.38 release</li>
@@ -42,7 +43,7 @@
   <li>Boost 1.33 release</li>
 </ul>
 
-<h2><a name="boost_1_42">Boost 1.42 release</a></h2>
+<h2><a name="boost_1_43">Boost 1.43 release</a></h2>
 
 <p>
 <ul>
@@ -51,7 +52,17 @@
     of non default constructible values</a> is now properly supported
     through user-provided facilities <code>save_construct_data</code> and
     <code>load_construct_data</code>.
+ <code>multi_index_container</code> serialization
+ class version has been
+ bumped from 1 to 2.
   </li>
+</ul>
+</p>
+
+<h2><a name="boost_1_42">Boost 1.42 release</a></h2>
+
+<p>
+<ul>
   <li>Maintenance fixes.</li>
 </ul>
 </p>
@@ -297,9 +308,9 @@
 
 <br>
 
-<p>Revised December 22nd 2009</p>
+<p>Revised February 3rd 2010</p>
 
-<p>&copy; Copyright 2003-2009 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
+<p>&copy; Copyright 2003-2010 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
 Distributed under the Boost Software
 License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt">
 LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">

Modified: trunk/libs/multi_index/test/test_serialization3.cpp
==============================================================================
--- trunk/libs/multi_index/test/test_serialization3.cpp (original)
+++ trunk/libs/multi_index/test/test_serialization3.cpp 2010-02-03 09:29:55 EST (Wed, 03 Feb 2010)
@@ -1,6 +1,6 @@
 /* Boost.MultiIndex test for serialization, part 3.
  *
- * Copyright 2003-2009 Joaquin M Lopez Munoz.
+ * Copyright 2003-2010 Joaquin M Lopez Munoz.
  * Distributed under 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)
@@ -33,21 +33,30 @@
 
 template<class Archive>
 void save_construct_data(
- Archive& ar,const non_default_ctble* p,const unsigned int)
+ Archive& ar,const non_default_ctble* p,const unsigned int version)
 {
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+ if(version<3)return;
+#endif
+
   ar<<boost::serialization::make_nvp("n",p->n);
 }
 
 template<class Archive>
-void load_construct_data(Archive& ar,non_default_ctble* p,const unsigned int)
+void load_construct_data(
+ Archive& ar,non_default_ctble* p,const unsigned int version)
 {
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+ if(version<3)return;
+#endif
+
   int n=0;
   ar>>boost::serialization::make_nvp("n",n);
   ::new(p)non_default_ctble(n);
 }
 
 template<class Archive>
-void serialize(Archive& ar,non_default_ctble& x,const unsigned int)
+void serialize(Archive&,non_default_ctble&,const unsigned int)
 {
 }
 
@@ -56,6 +65,15 @@
 } /* namespace boost*/
 #endif
 
+namespace boost{
+namespace serialization{
+template<> struct version<non_default_ctble>
+{
+ BOOST_STATIC_CONSTANT(unsigned int,value=3);
+};
+} /* namespace serialization */
+} /* namespace boost*/
+
 using namespace boost::multi_index;
 
 void test_serialization3()


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