Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58735 - sandbox/msm/boost/msm/back
From: christophe.j.henry_at_[hidden]
Date: 2010-01-05 17:39:17


Author: chenry
Date: 2010-01-05 17:39:16 EST (Tue, 05 Jan 2010)
New Revision: 58735
URL: http://svn.boost.org/trac/boost/changeset/58735

Log:
added support for event hierarchy
Text files modified:
   sandbox/msm/boost/msm/back/dispatch_table.hpp | 35 ++++++++++++++++++++++++++---------
   1 files changed, 26 insertions(+), 9 deletions(-)

Modified: sandbox/msm/boost/msm/back/dispatch_table.hpp
==============================================================================
--- sandbox/msm/boost/msm/back/dispatch_table.hpp (original)
+++ sandbox/msm/boost/msm/back/dispatch_table.hpp 2010-01-05 17:39:16 EST (Tue, 05 Jan 2010)
@@ -18,6 +18,7 @@
 #include <boost/mpl/filter_view.hpp>
 #include <boost/mpl/pop_front.hpp>
 #include <boost/mpl/for_each.hpp>
+#include <boost/type_traits/is_base_of.hpp>
 
 #include <boost/msm/back/metafunctions.hpp>
 #include <boost/msm/back/common_types.hpp>
@@ -108,7 +109,24 @@
         init_cell(dispatch_table* self_)
           : self(self_)
         {}
-
+ // version for transition event not base of our event
+ template <class Transition>
+ void init_event_base_case(Transition const&, ::boost::mpl::true_ const &) const
+ {
+ typedef typename create_stt<Fsm>::type stt;
+ BOOST_STATIC_CONSTANT(int, state_id =
+ (get_state_id<stt,typename Transition::current_state_type>::value));
+ self->entries[state_id] = reinterpret_cast<cell>(&Transition::execute);
+ }
+ // version for transition event base of our event
+ template <class Transition>
+ void init_event_base_case(Transition const&, ::boost::mpl::false_ const &) const
+ {
+ typedef typename create_stt<Fsm>::type stt;
+ BOOST_STATIC_CONSTANT(int, state_id =
+ (get_state_id<stt,typename Transition::current_state_type>::value));
+ self->entries[state_id] = &Transition::execute;
+ }
         // Cell initializer function object, used with mpl::for_each
         template <class Transition>
         typename ::boost::enable_if<typename has_not_real_row_tag<Transition>::type,void >::type
@@ -118,12 +136,11 @@
         }
         template <class Transition>
         typename ::boost::disable_if<typename has_not_real_row_tag<Transition>::type,void >::type
- operator()(Transition const&,boost::msm::back::dummy<1> = 0) const
+ operator()(Transition const& tr,boost::msm::back::dummy<1> = 0) const
         {
- typedef typename create_stt<Fsm>::type stt;
- BOOST_STATIC_CONSTANT(int, state_id =
- (get_state_id<stt,typename Transition::current_state_type>::value));
- self->entries[state_id] = &Transition::execute;
+ //only if the transition event is a base of our event is the reinterpret_case safe
+ init_event_base_case(tr,
+ ::boost::mpl::bool_< ::boost::is_base_of<typename Transition::Event,Event>::type::value>() );
         }
     
         dispatch_table* self;
@@ -149,7 +166,7 @@
             }
         template <class State>
         typename ::boost::disable_if<typename has_state_delayed_event<State,Event>::type,void >::type
- operator()(boost::msm::wrap<State> const&,boost::msm::back::dummy<0> = 0)
+ operator()(boost::msm::wrap<State> const&,boost::msm::back::dummy<1> = 0)
         {
             typedef typename create_stt<Fsm>::type stt;
             BOOST_STATIC_CONSTANT(int, state_id = (get_state_id<stt,State>::value));
@@ -171,7 +188,7 @@
                     : self(self_),tofill_entries(tofill_entries_)
             {}
 
- // this event is an automatic one (not a real one, just one for use in event-less transitions)
+ // this event is a compound one (not a real one, just one for use in event-less transitions)
         // Note this event cannot be used as deferred!
             template <class State>
         void operator()(boost::msm::wrap<State> const&)
@@ -201,7 +218,7 @@
         typedef typename ::boost::mpl::reverse_fold<
                         // filter on event
                         ::boost::mpl::filter_view
- <Stt, ::boost::is_same<transition_event< ::boost::mpl::placeholders::_>, Event> >,
+ <Stt, ::boost::is_base_of<transition_event< ::boost::mpl::placeholders::_>, Event> >,
                         // build a map
                         ::boost::mpl::map<>,
                         ::boost::mpl::if_<


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