|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68194 - trunk/boost/msm/back
From: christophe.j.henry_at_[hidden]
Date: 2011-01-16 16:10:11
Author: chenry
Date: 2011-01-16 16:10:07 EST (Sun, 16 Jan 2011)
New Revision: 68194
URL: http://svn.boost.org/trac/boost/changeset/68194
Log:
better implementation of the favor_compile_time policy, not based on boost::any
Added:
trunk/boost/msm/back/any_event.hpp (contents, props changed)
Text files modified:
trunk/boost/msm/back/favor_compile_time.hpp | 45 ++++++++++++++-------------------------
trunk/boost/msm/back/state_machine.hpp | 8 +-----
2 files changed, 18 insertions(+), 35 deletions(-)
Added: trunk/boost/msm/back/any_event.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/back/any_event.hpp 2011-01-16 16:10:07 EST (Sun, 16 Jan 2011)
@@ -0,0 +1,55 @@
+// Copyright 2008 Christophe Henry
+// henry UNDERSCORE christophe AT hotmail DOT com
+// This is an extended version of the state machine available in the boost::mpl library
+// Distributed under the same license as the original.
+// Copyright for the original version:
+// Copyright 2005 David Abrahams and Aleksey Gurtovoy. 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)
+
+#ifndef BOOST_MSM_BACK_ANY_EVENT_H
+#define BOOST_MSM_BACK_ANY_EVENT_H
+
+#include <boost/smart_ptr/scoped_ptr.hpp>
+#include <boost/msm/back/common_types.hpp>
+
+namespace boost { namespace msm { namespace back
+{
+class placeholder
+{
+public:
+ virtual ::boost::msm::back::HandledEnum process_event() const =0;
+};
+template<class EventType,class FsmType>
+class holder : public placeholder
+{
+public:
+ holder(EventType const& evt, FsmType& fsm): event_(evt),fsm_(fsm){}
+ virtual ::boost::msm::back::HandledEnum process_event() const
+ {
+ return fsm_.process_event(event_);
+ }
+private:
+ EventType const& event_;
+ FsmType& fsm_;
+};
+
+class any_event
+{
+public:
+ template <class EventType,class FsmType>
+ any_event(EventType const& evt,FsmType& fsm):content_(new holder<EventType,FsmType>(evt,fsm)){}
+ ::boost::msm::back::HandledEnum process_event() const
+ {
+ return content_->process_event();
+ }
+private:
+
+ ::boost::scoped_ptr<placeholder> content_;
+};
+
+}}}
+
+#endif //BOOST_MSM_BACK_ANY_EVENT_H
+
Modified: trunk/boost/msm/back/favor_compile_time.hpp
==============================================================================
--- trunk/boost/msm/back/favor_compile_time.hpp (original)
+++ trunk/boost/msm/back/favor_compile_time.hpp 2011-01-16 16:10:07 EST (Sun, 16 Jan 2011)
@@ -17,47 +17,33 @@
#include <boost/mpl/filter_view.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/bool.hpp>
-#include <boost/any.hpp>
#include <boost/msm/common.hpp>
#include <boost/msm/back/metafunctions.hpp>
#include <boost/msm/back/common_types.hpp>
#include <boost/msm/back/dispatch_table.hpp>
+#include <boost/msm/back/any_event.hpp>
namespace boost { namespace msm { namespace back
{
-template <class Fsm>
-struct process_any_event_helper
-{
- process_any_event_helper(msm::back::HandledEnum& res_,Fsm* self_,::boost::any any_event_):
- res(res_),self(self_),any_event(any_event_),finished(false){}
- template <class Event>
- void operator()(boost::msm::wrap<Event> const&)
- {
- if ( ! finished && ::boost::any_cast<Event>(&any_event)!=0)
- {
- finished = true;
- res = self->process_event(::boost::any_cast<Event>(any_event));
- }
- }
-private:
- msm::back::HandledEnum& res;
- Fsm* self;
- ::boost::any any_event;
- bool finished;
-};
#define BOOST_MSM_BACK_GENERATE_PROCESS_EVENT(fsmname) \
namespace boost { namespace msm { namespace back{ \
+ template<class EventType> \
+ class holder<EventType,fsmname> : public placeholder \
+ { \
+ public: \
+ holder(EventType const& evt, fsmname& fsm): event_(evt),fsm_(fsm){} \
+ virtual ::boost::msm::back::HandledEnum process_event() const \
+ {return fsm_.process_event(event_);} \
+ private: \
+ EventType const& event_; \
+ fsmname& fsm_; \
+ }; \
template<> \
- ::boost::msm::back::HandledEnum fsmname::process_any_event( ::boost::any const& any_event) \
+ ::boost::msm::back::HandledEnum fsmname::process_any_event( any_event const& evt)const \
{ \
- typedef ::boost::msm::back::recursive_get_transition_table<fsmname>::type stt; \
- typedef ::boost::msm::back::generate_event_set<stt>::type all_events; \
- ::boost::msm::back::HandledEnum res= ::boost::msm::back::HANDLED_FALSE; \
- ::boost::mpl::for_each<all_events, ::boost::msm::wrap< ::boost::mpl::placeholders::_1> > \
- (::boost::msm::back::process_any_event_helper<fsmname>(res,this,any_event)); \
- return res; \
+ return evt.process_event(); \
} \
}}}
@@ -106,7 +92,8 @@
template <class TransitionState>
static HandledEnum call_submachine(Fsm& fsm, int region, int state, Event const& evt)
{
- return (fsm.template get_state<TransitionState&>()).process_any_event( ::boost::any(evt));
+ return (fsm.template get_state<TransitionState&>()).process_any_event
+ ( any_event(evt,fsm.template get_state<TransitionState&>()) );
}
// A function object for use with mpl::for_each that stuffs
// transitions into cells.
Modified: trunk/boost/msm/back/state_machine.hpp
==============================================================================
--- trunk/boost/msm/back/state_machine.hpp (original)
+++ trunk/boost/msm/back/state_machine.hpp 2011-01-16 16:10:07 EST (Sun, 16 Jan 2011)
@@ -44,9 +44,6 @@
#include <boost/bind.hpp>
#include <boost/bind/apply.hpp>
#include <boost/function.hpp>
-#ifndef BOOST_NO_RTTI
-#include <boost/any.hpp>
-#endif
#include <boost/serialization/base_object.hpp>
@@ -63,6 +60,7 @@
#include <boost/msm/back/dispatch_table.hpp>
#include <boost/msm/back/no_fsm_check.hpp>
#include <boost/msm/back/queue_container_deque.hpp>
+#include <boost/msm/back/any_event.hpp>
BOOST_MPL_HAS_XXX_TRAIT_DEF(accept_sig)
BOOST_MPL_HAS_XXX_TRAIT_DEF(no_automatic_create)
@@ -1731,9 +1729,7 @@
template <class Event>
void no_action(Event const&){}
-#ifndef BOOST_NO_RTTI
- HandledEnum process_any_event( ::boost::any const& evt);
-#endif
+ HandledEnum process_any_event( any_event const& evt) const;
private:
// composite accept implementation. First calls accept on the composite, then accept on all its active states.
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