$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r59654 - in sandbox/statistics/detail/serialization: . boost boost/serialization boost/serialization/detail boost/serialization/detail/concept boost/serialization/detail/inherit boost/serialization/detail/inherit/detail
From: erwann.rogard_at_[hidden]
Date: 2010-02-11 18:50:49
Author: e_r
Date: 2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
New Revision: 59654
URL: http://svn.boost.org/trac/boost/changeset/59654
Log:
small serialization tool
Added:
   sandbox/statistics/detail/serialization/
   sandbox/statistics/detail/serialization/boost/
   sandbox/statistics/detail/serialization/boost/serialization/
   sandbox/statistics/detail/serialization/boost/serialization/detail/
   sandbox/statistics/detail/serialization/boost/serialization/detail/concept/
   sandbox/statistics/detail/serialization/boost/serialization/detail/concept/loadable.hpp   (contents, props changed)
   sandbox/statistics/detail/serialization/boost/serialization/detail/concept/saveable.hpp   (contents, props changed)
   sandbox/statistics/detail/serialization/boost/serialization/detail/concept/serializable.hpp   (contents, props changed)
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/detail/
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/detail/stream.hpp   (contents, props changed)
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/include.hpp   (contents, props changed)
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit.hpp   (contents, props changed)
   sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit2.hpp   (contents, props changed)
Added: sandbox/statistics/detail/serialization/boost/serialization/detail/concept/loadable.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/concept/loadable.hpp	2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,41 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::concept::loadable.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_CONCEPT_LOADABLE_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_CONCEPT_LOADABLE_HPP_ER_2010
+#include <boost/concept_check.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
+namespace boost{
+namespace serialization{
+namespace detail{
+namespace concept{
+
+    template<typename T>
+    class Loadable{
+    	typedef boost::archive::text_iarchive ia_;
+
+        public:
+    
+        BOOST_CONCEPT_USAGE(Loadable){ 
+            ia >> t;		
+        }
+
+        private:
+		T t;
+        ia_ ia;
+    };
+        
+}// concept
+}// detail
+}// serialization
+}// boost
+
+#endif
+
Added: sandbox/statistics/detail/serialization/boost/serialization/detail/concept/saveable.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/concept/saveable.hpp	2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,41 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::concept::saveable.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_CONCEPT_SAVEABLE_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_CONCEPT_SAVEABLE_HPP_ER_2010
+#include <boost/concept_check.hpp>
+#include <boost/archive/text_oarchive.hpp>
+
+namespace boost{
+namespace serialization{
+namespace detail{
+namespace concept{
+
+    template<typename T>
+    class Saveable{
+    	typedef boost::archive::text_oarchive oa_;
+
+        public:
+    
+        BOOST_CONCEPT_USAGE(Saveable){ 
+            oa << t;		
+        }
+
+        private:
+		T t;
+        oa_ oa;
+    };
+    
+}// concept
+}// detail
+}// serialization
+}// boost
+
+#endif
+
Added: sandbox/statistics/detail/serialization/boost/serialization/detail/concept/serializable.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/concept/serializable.hpp	2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::concept::serializable.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_CONCEPT_SERIALIZABLE_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_CONCEPT_SERIALIZABLE_HPP_ER_2010
+#include <boost/concept_check.hpp>
+#include <boost/serialization/detail/concept/saveable.hpp>
+#include <boost/serialization/detail/concept/loadable.hpp>
+
+namespace boost{
+namespace serialization{
+namespace detail{
+namespace concept{
+
+    template<typename T>
+    class Serializable : 
+    	Saveable<T>,
+        Loadable<T>
+    {};
+    
+}// concept
+}// detail
+}// serialization
+}// boost
+
+#endif
+
Added: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/detail/stream.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/detail/stream.hpp	2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,140 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::inherit::detail::stream.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_STREAM_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_INHERIT_DETAIL_STREAM_HPP_ER_2010
+#include <ostream>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/plus.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/count_if.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/empty_base.hpp>
+
+namespace boost{
+namespace serialization{
+namespace detail{
+namespace impl_inherit2_stream{
+	template<int K> struct os_caller;
+	template<typename T,int K> struct count;
+}
+
+	template<typename T1,typename T2>
+    struct inherit2;
+
+	// Writes a comma separated list of a succession of casts of the non-empty
+	// "terminal types" within the nested structure inherit2<T1,T2>. A terminal 
+    // type is one that is not an instance of inherit2.
+    // For example, if these type are A,B,C, with descriptions 'a, 'b' and 'c',
+    // "a,b,c" is written to os.
+    template<typename A,typename B,typename T1,typename T2>
+	std::basic_ostream<A,B>&
+    operator<<(std::basic_ostream<A,B>& os,const inherit2<T1,T2>& that){
+		typedef inherit2<T1,T2> in_;
+        static const int k = impl_inherit2_stream::count<in_,0>::result;
+    	typedef impl_inherit2_stream::os_caller<k> caller_;
+        return caller_::top_call(os,that);
+    }
+
+namespace impl_inherit2_stream{
+
+	typedef boost::mpl::empty_base ignore_;
+
+	// Terminal node
+	template<typename T,int K>
+    struct count{
+		BOOST_STATIC_CONSTANT(int,result = K+1);
+    };
+
+	template<int K>
+    struct count<ignore_,K>{
+		BOOST_STATIC_CONSTANT(int,result = K);
+    };
+
+	// Non-terminal node
+	template<typename T1,typename T2,int K>
+    struct count<inherit2<T1,T2>,K>{
+    	typedef count<T2,K+1> next_;
+		BOOST_STATIC_CONSTANT(int,result = next_::result);
+    };
+
+	template<typename T2,int K>
+    struct count<inherit2<ignore_,T2>,K>{
+    	typedef count<T2,K> next_;
+		BOOST_STATIC_CONSTANT(int,result = next_::result);
+    };
+
+	// os caller ensures that the output for say 3 items, a, b, and c is
+    // "a,b,c", rather than "a,b,c,"
+	template<int K>
+	struct os_caller{
+        struct silent{
+			template<typename T>
+            static const T& call(const T& t){
+            	return t;
+            }
+        };
+		
+        static int count;
+        
+		template<typename S,typename I>
+    	static S& top_call(S& os,const I& t){
+        	count = 0;
+    		return call(os,t);
+        }
+
+		template<typename S>
+    	static S& call(S& os,const ignore_& t){
+    		return os;
+        }
+
+		template<typename S,typename T>
+    	static S& call(S& os,const T& t){
+        	if(K == count+1){
+				os << t;            
+            }else{
+            	os << t << ',';            
+            	++count;
+            }
+            return os;
+        }
+
+		template<typename S,typename T1,typename T2>
+    	static S& call(S& os,const inherit2<T1,T2>& t){
+    		call(os,silent::template call<T1>(t));
+            return call(os,silent::template call<T2>(t));
+        }
+
+		template<typename S,typename T2>
+    	static S& call(S& os,const inherit2<ignore_,T2>& t){
+    		return call(os,silent::template call<T2>(t));
+        }
+
+		template<typename S,typename T1>
+    	static S& call(S& os,const inherit2<T1,ignore_>& t){
+    		return call(os,silent::template call<T1>(t));
+        }
+
+		template<typename S>
+    	static S& call(S& os,const inherit2<ignore_,ignore_>& t){
+    		return os;
+        }
+
+    };
+	template<int K>
+    int os_caller<K>::count = 0;
+
+}// impl_inherit2_stream
+
+}// detail
+}// serialization
+}// boost
+
+#endif
Added: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/include.hpp	2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::inherit::include.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_INCLUDE_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_INHERIT_INCLUDE_HPP_ER_2010
+
+#include <boost/serialization/detail/inherit.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit.hpp	2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,101 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::inherit::inherit.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_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_INHERIT_INHERIT_HPP_ER_2010
+#include <boost/mpl/empty_base.hpp>
+#include <boost/serialization/base_object.hpp>
+#include <boost/serialization/detail/inherit/inherit2.hpp>
+
+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.
+    template<
+    	typename T1 = boost::mpl::empty_base,
+        typename T2 = boost::mpl::empty_base,
+        typename T3 = boost::mpl::empty_base,
+        typename T4 = boost::mpl::empty_base,
+        typename T5 = boost::mpl::empty_base
+    >
+    struct inherit : 	
+    	inherit2<
+        	T1,
+            inherit2<
+            	T2,
+                inherit2<
+                	T3,
+                    inherit2<T4,T5>
+                >
+            >
+        >
+    {
+    	typedef inherit2<
+        	T1,
+            inherit2<
+                T2,
+                inherit2<
+                    T3,
+                    inherit2<T4,T5>
+                >
+            >
+        > super_;
+        
+        typedef inherit<super_> type;
+            
+        inherit(){}
+            
+        template<typename Args>
+        inherit(const Args& args):super_(args){}
+
+        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 {T1,...,T5},
+    // writes "(a,b,c)" to os
+    template<typename A,typename B,
+    	typename T1,typename T2,typename T3,typename T4,typename T5>
+	std::basic_ostream<A,B>&
+    operator<<(std::basic_ostream<A,B>& os,const inherit<T1,T2,T3,T4,T5>& that){
+		typedef typename inherit<T1,T2,T3,T4,T5>::super_ super_;
+        return os << '(' << static_cast<const super_&>(that) << ')';
+    }
+
+}// detail
+}// serialization
+}// boost
+
+#endif
Added: sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit2.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/serialization/boost/serialization/detail/inherit/inherit2.hpp	2010-02-11 18:50:48 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,122 @@
+//////////////////////////////////////////////////////////////////////////////
+// serialization::detail::inherit::inherit2.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_INHERIT2_HPP_ER_2010
+#define BOOST_SERIALIZATION_DETAIL_INHERIT_INHERIT2_HPP_ER_2010
+#include <boost/mpl/empty_base.hpp>
+#include <boost/concept/assert.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/serialization/base_object.hpp>
+#include <boost/serialization/detail/inherit/detail/stream.hpp>
+#include <boost/serialization/detail/concept/serializable.hpp>
+
+namespace boost{
+namespace serialization{
+namespace detail{
+
+	// Inherits from the non-empty base subset of {T1,T2} and implements 
+    // serialization and operator<<(ostream,)
+	template<typename T1,typename T2>
+	struct inherit2 : T1, T2
+	{
+    	typedef inherit2 type;
+    
+		inherit2(){}
+
+    	template<typename Args>
+    	inherit2(const Args& args):T1(args),T2(args){}
+
+		private:
+        
+        friend class boost::serialization::access;
+        template<class Archive>
+        void serialize(Archive & ar, const unsigned int version)
+        {
+			BOOST_CONCEPT_ASSERT((concept::Serializable<T1>));
+			BOOST_CONCEPT_ASSERT((concept::Serializable<T2>));
+            ar & boost::serialization::base_object<T1>(*this);
+            ar & boost::serialization::base_object<T2>(*this);
+        }
+	};
+
+	template<typename T1>
+	struct inherit2<T1,boost::mpl::empty_base> : T1
+	{
+    	typedef inherit2 type;
+
+		inherit2(){}
+
+    	template<typename Args>
+    	inherit2(const Args& args):T1(args){}
+
+		private:
+		typedef boost::mpl::empty_base empty_;
+
+        friend class boost::serialization::access;
+        template<class Archive>
+        void serialize(Archive & ar, const unsigned int version)
+        {
+			BOOST_CONCEPT_ASSERT((concept::Serializable<T1>));
+            ar & boost::serialization::base_object<T1>(*this);
+        }
+        
+	};
+
+	template<typename T2>
+	struct inherit2<boost::mpl::empty_base,T2> : T2
+	{
+    	typedef inherit2 type;
+
+		inherit2(){}
+
+    	template<typename Args>
+    	inherit2(const Args& args):T2(args){}
+
+		private:
+
+		typedef boost::mpl::empty_base empty_;
+
+        friend class boost::serialization::access;
+        template<class Archive>
+        void serialize(Archive & ar, const unsigned int version)
+        {
+			BOOST_CONCEPT_ASSERT((concept::Serializable<T2>));
+            ar & boost::serialization::base_object<T2>(*this);
+        }
+	};
+
+	template<>
+	struct inherit2<boost::mpl::empty_base,boost::mpl::empty_base>
+	{
+		private:
+    	typedef boost::accumulators::dont_care dont_care_;
+		public:
+
+    	typedef inherit2 type;
+    
+		inherit2(){}
+
+    	inherit2(dont_care_){}
+
+		private:
+		typedef boost::mpl::empty_base empty_;
+
+        friend class boost::serialization::access;
+        template<class Archive>
+        void serialize(Archive & ar, const unsigned int version)
+        {
+        }
+        
+	};
+    
+}// detail
+}// serialization
+}// boost
+
+#endif