Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65415 - trunk/boost/msm/back
From: christophe.j.henry_at_[hidden]
Date: 2010-09-13 17:45:02


Author: chenry
Date: 2010-09-13 17:44:54 EDT (Mon, 13 Sep 2010)
New Revision: 65415
URL: http://svn.boost.org/trac/boost/changeset/65415

Log:
first try of serialization
Text files modified:
   trunk/boost/msm/back/history_policies.hpp | 16 ++++++++++++++++
   trunk/boost/msm/back/state_machine.hpp | 34 ++++++++++++++++++++++++++++++++++
   2 files changed, 50 insertions(+), 0 deletions(-)

Modified: trunk/boost/msm/back/history_policies.hpp
==============================================================================
--- trunk/boost/msm/back/history_policies.hpp (original)
+++ trunk/boost/msm/back/history_policies.hpp 2010-09-13 17:44:54 EDT (Mon, 13 Sep 2010)
@@ -49,6 +49,11 @@
          }
          return *this;
     }
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & m_initialStates;
+ }
 private:
     int m_initialStates[NumberOfRegions];
 };
@@ -85,6 +90,11 @@
          }
          return *this;
     }
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & m_initialStates;
+ }
 private:
     int m_initialStates[NumberOfRegions];
 };
@@ -129,6 +139,12 @@
          }
          return *this;
     }
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & m_initialStates;
+ ar & m_currentStates;
+ }
 private:
     int m_initialStates[NumberOfRegions];
     int m_currentStates[NumberOfRegions];

Modified: trunk/boost/msm/back/state_machine.hpp
==============================================================================
--- trunk/boost/msm/back/state_machine.hpp (original)
+++ trunk/boost/msm/back/state_machine.hpp 2010-09-13 17:44:54 EDT (Mon, 13 Sep 2010)
@@ -31,6 +31,7 @@
 #include <boost/fusion/include/at_key.hpp>
 #include <boost/fusion/algorithm/iteration/for_each.hpp>
 #include <boost/fusion/include/for_each.hpp>
+#include <boost/fusion/include/for_each.hpp>
 
 #include <boost/assert.hpp>
 #include <boost/ref.hpp>
@@ -58,6 +59,7 @@
 BOOST_MPL_HAS_XXX_TRAIT_DEF(non_forwarding_flag)
 BOOST_MPL_HAS_XXX_TRAIT_DEF(direct_entry)
 BOOST_MPL_HAS_XXX_TRAIT_DEF(initial_event)
+BOOST_MPL_HAS_XXX_TRAIT_DEF(do_serialize)
 
 #ifndef BOOST_MSM_CONSTRUCTOR_ARG_SIZE
 #define BOOST_MSM_CONSTRUCTOR_ARG_SIZE 5 // default max number of arguments for constructors
@@ -1013,6 +1015,38 @@
         return this->m_states;
     }
 
+ template <class Archive>
+ struct serialize_state
+ {
+ serialize_state(Archive& ar):ar_(ar){}
+
+ template<typename T>
+ typename ::boost::enable_if< typename has_do_serialize<T>::type,void >::type
+ operator()(T& t) const
+ {
+ ar_ & t;
+ }
+ template<typename T>
+ typename ::boost::disable_if< typename has_do_serialize<T>::type,void >::type
+ operator()(T& t) const
+ {
+ // no state to serialize
+ }
+ Archive& ar_;
+ };
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & m_states;
+ // queues cannot be serialized => skip
+ ar & m_history;
+ ar & m_event_processing;
+ ar & m_is_included;
+ // visitors cannot be serialized => skip
+ ::boost::fusion::for_each(m_substate_list, serialize_state<Archive>(ar));
+ }
+
     // linearly search for the state with the given id
     struct get_state_id_helper
     {


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