Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59936 - in sandbox/statistics/detail/serialization: boost/serialization/detail/inherit boost/serialization/detail/inherit/detail libs libs/serialization libs/serialization/detail libs/serialization/detail/example libs/serialization/detail/src
From: erwann.rogard_at_[hidden]
Date: 2010-02-25 21:08:26


Author: e_r
Date: 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
New Revision: 59936
URL: http://svn.boost.org/trac/boost/changeset/59936

Log:
m
Added:
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/detail/test_wrapper.hpp (contents, props changed)
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit_linearly.hpp (contents, props changed)
   sandbox/statistics/detail/serialization/libs/
   sandbox/statistics/detail/serialization/libs/serialization/
   sandbox/statistics/detail/serialization/libs/serialization/detail/
   sandbox/statistics/detail/serialization/libs/serialization/detail/example/
   sandbox/statistics/detail/serialization/libs/serialization/detail/example/inherit_linearly.cpp (contents, props changed)
   sandbox/statistics/detail/serialization/libs/serialization/detail/example/inherit_linearly.h (contents, props changed)
   sandbox/statistics/detail/serialization/libs/serialization/detail/src/
   sandbox/statistics/detail/serialization/libs/serialization/detail/src/main.cpp (contents, props changed)
Text files modified:
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit.hpp | 23 ++---------------------
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit2.hpp | 3 ++-
   2 files changed, 4 insertions(+), 22 deletions(-)

Added: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/detail/test_wrapper.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/detail/test_wrapper.hpp 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
@@ -0,0 +1,49 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::inherit::detail::test_wrapper.hpp //
+// //
+// //
+// (C) Copyright 2010 Erwann Rogard //
+// Use, modification and distribution are 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_SERIALIZATION_DETAIL_INHERIT_DETAIL_TEST_WRAPPER_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_INHERIT_DETAIL_TEST_WRAPPER_HPP_ER_2010
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
+namespace boost{
+namespace serialization{
+namespace detail{
+
+ template<typename T>
+ struct test_wrapper{
+ typedef boost::accumulators::dont_care dont_care_;
+
+ test_wrapper(){}
+ test_wrapper(dont_care_){}
+
+ T value;
+
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & value;
+ }
+
+ };
+
+ template<typename A,typename B,typename T>
+ std::basic_ostream<A,B>&
+ operator<<(std::basic_ostream<A,B>& os,const test_wrapper<T>& that){
+ return os << '(' << that.value << ')';
+ }
+
+
+}// detail
+}// serialization
+}// boost
+
+#endif
\ No newline at end of file

Modified: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit.hpp
==============================================================================
--- sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit.hpp (original)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit.hpp 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
@@ -16,27 +16,8 @@
 namespace boost{
 namespace serialization{
 namespace detail{
-
- // Merges up to 5 serializable classes together into one that is also
- // serializable.
- //
- // Requirements :
- // Each non-empty base is serializable and the default constructor or one
- // that takes an argument pack must be defined.
- //
- // Usage : let arg denote an argument pack :
- // inherit<T1,T2,T3> obj(args);
- // oa << obj;
- // ia >> obj;
- //
- // See Boost.Parameter regarding argument pack.
- // See sandbox/statistics/data for a small application
- //
- // Note that class inherit<> will not inherit from any empty_base passed
- // as a template argument. This selective inheritance principle was found
- // in the class by the same name in Boost.MPL
- //
- // TODO : define a macro to extend this to arbitrary n.
+
+ // THIS CLASS IS PROBABLY SUPERSEDED BY inherit_linearly
     template<
             typename T1 = boost::mpl::empty_base,
         typename T2 = boost::mpl::empty_base,

Modified: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit2.hpp
==============================================================================
--- sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit2.hpp (original)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit2.hpp 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
@@ -26,7 +26,7 @@
         struct inherit2 : T1, T2
         {
             typedef inherit2 type;
-
+
                 inherit2(){}
 
             template<typename Args>
@@ -44,6 +44,7 @@
             ar & boost::serialization::base_object<T2>(*this);
         }
         };
+
 
         template<typename T1>
         struct inherit2<T1,boost::mpl::empty_base> : T1

Added: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit_linearly.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit_linearly.hpp 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
@@ -0,0 +1,83 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::inherit::inherit_linearly.hpp //
+// //
+// //
+// (C) Copyright 2010 Erwann Rogard //
+// Use, modification and distribution are 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_SERIALIZATION_DETAIL_INHERIT_INHERIT_LINEARLY_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_INHERIT_INHERIT_LINEARLY_HPP_ER_2010
+#include <boost/mpl/empty_base.hpp>
+#include <boost/mpl/reverse_fold.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/serialization/base_object.hpp>
+
+#include <boost/concept/assert.hpp>
+#include <boost/serialization/detail/inherit/inherit2.hpp>
+
+namespace boost{
+namespace serialization{
+namespace detail{
+
+ // Merges serializable classes together into one that is also serializable.
+ // In addition to a default constructor, one that takes an argument pack
+ // forwards the latter to each of its components.
+ //
+ // Requirements :
+ // S is a sequence of non-empy-base serializable class types, optionally
+ // with an argument pack constructor, and operator<< as needed.
+ //
+ // Usage : let arg denote an argument pack and T one element of S
+ // inherit_linearly<S> obj(args);
+ // static_cast<const S&>(obj);
+ // oa << obj;
+ // ia >> obj;
+ //
+ // See Boost.Parameter regarding argument pack.
+ // See sandbox/statistics/data for a small application
+ //
+ // Background : See class by the same name in the MPL framework.
+
+ template<typename S,typename R = boost::mpl::empty_base>
+ struct inherit_linearly : boost::mpl::reverse_fold<
+ S,R,inherit2<boost::mpl::_2,boost::mpl::_1>
+ >::type{
+ typedef typename boost::mpl::reverse_fold<
+ S,R,inherit2<boost::mpl::_2,boost::mpl::_1>
+ >::type super_;
+
+ inherit_linearly(){}
+
+ template<typename Args>
+ inherit_linearly(const Args& args):super_(args){}
+
+ private:
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ // serialize base class information
+ ar & boost::serialization::base_object<super_>(*this);
+ }
+
+ };
+
+ // If a, b, c are instances of the subset of non-empty bases in S,
+ // writes "(a,b,c)" to os
+ template<typename A,typename B,typename S,typename R>
+ std::basic_ostream<A,B>&
+ operator<<(std::basic_ostream<A,B>& os,const inherit_linearly<S,R>& that){
+ typedef typename inherit_linearly<S,R>::super_ super_;
+ return os << '(' << static_cast<const super_&>(that) << ')';
+ }
+
+}// detail
+}// serialization
+}// boost
+
+#endif
+
+
+

Added: sandbox/statistics/detail/serialization/libs/serialization/detail/example/inherit_linearly.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/libs/serialization/detail/example/inherit_linearly.cpp 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
@@ -0,0 +1,106 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::example::inherit_linearly.cpp //
+// //
+// //
+// (C) Copyright 2010 Erwann Rogard //
+// Use, modification and distribution are 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) //
+//////////////////////////////////////////////////////////////////////////////
+#include <fstream>
+#include <string>
+#include <boost/serialization/detail/inherit/inherit_linearly.hpp>
+#include <boost/serialization/detail/inherit/detail/test_wrapper.hpp>
+#include <boost/serialization/string.hpp>
+#include <boost/mpl/vector.hpp>
+#include <libs/serialization/detail/example/inherit_linearly.h>
+
+struct foo{
+
+ foo():value(0){}
+ foo(int v):value(v){}
+
+ int value;
+
+ bool operator==(const foo& other)const{
+ return value == other.value;
+ }
+
+ private:
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & value;
+ }
+
+};
+
+ template<typename A,typename B>
+ std::basic_ostream<A,B>&
+ operator<<(std::basic_ostream<A,B>& os,const foo& that){
+ return os << '(' << that.value << ')';
+ }
+
+
+void example_inherit_linearly(std::ostream& os){
+
+ os << "->example_inherit_linearly" << std::endl;
+
+ namespace ser = boost::serialization::detail;
+ const char* path = "./test_wrappers";
+ typedef std::ofstream ofs_;
+ typedef std::ifstream ifs_;
+ typedef boost::archive::text_oarchive oa_;
+ typedef boost::archive::text_iarchive ia_;
+
+ // BUG : std::string causes runtime error.
+
+ typedef int data1_;
+ typedef bool data2_;
+ typedef double data3_;
+ // typedef std::string data3_; // BUG
+ typedef foo data4_;
+ typedef ser::test_wrapper<data1_> wrap1_;
+ typedef ser::test_wrapper<data2_> wrap2_;
+ typedef ser::test_wrapper<data3_> wrap3_;
+ typedef ser::test_wrapper<data4_> wrap4_;
+ typedef boost::mpl::vector<wrap1_,wrap2_,wrap3_,wrap4_> types_;
+ typedef ser::inherit_linearly<types_> inlin_;
+
+ data1_ v1 = -1;
+ data2_ v2 = true;
+ data3_ v3 = -0.999;
+ //data3_ v3 = "minus one"; // BUG
+ data4_ v4(-1);
+ inlin_ inlin;
+
+ static_cast<wrap1_&>(inlin).value = v1;
+ static_cast<wrap2_&>(inlin).value = v2;
+ static_cast<wrap3_&>(inlin).value = v3;
+ static_cast<wrap4_&>(inlin).value = v4;
+
+ os << "description : ";
+ {
+ os << inlin << std::endl;
+ }
+ os << "save" << std::endl;
+ {
+ ofs_ ofs(path);
+ oa_ oa(ofs);
+ oa << inlin;
+ }
+ os << "load" << std::endl;
+ {
+ inlin_ inlin;
+ ifs_ ifs(path);
+ ia_ ia(ifs);
+ ia >> inlin;
+ BOOST_ASSERT(static_cast<const wrap1_&>(inlin).value == v1);
+ BOOST_ASSERT(static_cast<const wrap2_&>(inlin).value == v2);
+ BOOST_ASSERT(static_cast<const wrap3_&>(inlin).value == v3);
+ BOOST_ASSERT(static_cast<const wrap4_&>(inlin).value == v4);
+ }
+ os << "<-" << std::endl;
+
+}

Added: sandbox/statistics/detail/serialization/libs/serialization/detail/example/inherit_linearly.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/libs/serialization/detail/example/inherit_linearly.h 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::example::inherit_linearly.h //
+// //
+// //
+// (C) Copyright 2010 Erwann Rogard //
+// Use, modification and distribution are 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 LIBS_SERIALIZATION_DETAIL_EXAMPLE_INHERIT_LINEARLY_HPP_ER_2010
+#define LIBS_SERIALIZATION_DETAIL_EXAMPLE_INHERIT_LINEARLY_HPP_ER_2010
+#include <ostream>
+
+void example_inherit_linearly(std::ostream&);
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/detail/serialization/libs/serialization/detail/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/libs/serialization/detail/src/main.cpp 2010-02-25 21:08:25 EST (Thu, 25 Feb 2010)
@@ -0,0 +1,10 @@
+#include <iostream>
+#include <libs/serialization/detail/example/inherit_linearly.h>
+
+int main(){
+
+ example_inherit_linearly(std::cout);
+
+ return 0;
+
+}


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