加强与事件和状态再利用MSM问题 [英] Boost msm problems with events and state reuse

查看:187
本文介绍了加强与事件和状态再利用MSM问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的转换表和事件问题。
让我解释一下假设计,说明了这个问题:

I am having problems with my transition table and events. Let me explain the fake design that illustrates the problem:

我有一个包含2个状态(S0和S1)和1 substatemachine(subm1)。

I have a state machine (myStateMachine) containing 2 states (s0 and s1) and 1 substatemachine (subm1).

substatemachine subm1包含的初始状态'sub0'和还S1(在相同的状态中myStateMachine)

the substatemachine subm1 contains an initial state 'sub0' and also s1 (the same state as in myStateMachine).

这是主要的转换表:

S0-> S1事件ES1

s0->s1 on event 'ES1'

S0-> S2事件ES2

s0->s2 on event 'ES2'

S0-> subm1事件ESUB

s0->subm1 on event 'ESUB'

这是冲锋枪转换表:

sub0-> S1事件ES1

sub0->s1 on event 'ES1'

现在,假设状态S1使用触发它来提取一些信息的事件,即

now, assume that state s1 is using the event that triggered it to extract some information i.e.

struct s1 : public msm::front::state<>
{
   template <class Event,class FSM>
   void on_entry(Event const& evt,FSM& fsm)
   { 
      evt.getEventData();
   }
}

所以每一个可能过渡到S1事件需要实现getEventData()方法。

so every event that could transition to s1 needs to implement getEventData() method.

! - >这是正常的。

->this is normal!

我现在的问题是,ESUB没有实现getEventData(),但显然它应该(编译器提供了错误)。我不知道为什么。

now my problem is that ESUB does NOT implement getEventData() but apparently it should (compiler gives errors). And I don't get why.

我不使用ESUB过渡到S1,但我使用ESUB过渡到subm1和subm1包含S1,但我没有在这一点上访问它。

I am not using ESUB to transition to s1 but I am using ESUB to transition to subm1 and subm1 contains s1 but I don't access it at that point.

我希望这是显而易见的。

I hope this is clear.

推荐答案

我收到的答案从BOOST MSM克里斯托夫·亨利设计师:

I HAVE RECEIVED AN ANSWER FROM THE DESIGNER OF BOOST MSM Christophe Henry:

你好,

这是MSM的一个不幸的限制(复合材料),我有
我的东西名单尽快解决。的问题是,虽然该事件esub是
不用于过渡到S1,编译器它可以。无论如何,这是我的
故障,再加上我忘了在doc :(

this is an unfortunate limitation of msm (for composites), which I have on my list of stuff to solve asap. The problem is that though the event esub is not used to transition to s1, for the compiler it could. Whatever, it's my fault, plus I forgot it in the doc :(

解决方案是帮助编译器有点通过使on_entry与
evt.getEventData()仅适用于有一个特殊的属性,就像你ES1事件。
例如:

The solution is to help the compiler a bit by enabling on_entry with evt.getEventData() only for events having a special property, like your es1. For example:

BOOST_MPL_HAS_XXX_TRAIT_DEF(get_event_data) 

// this event supports getEventData 
struct es1 
{ 
   typedef int get_event_data; 
   void getEventData(){...} 
 }; 

然后在你的状态下使用:

Then use this in your state:

 struct s1 : public msm::front::state<> 
 { 
   template <class Event,class FSM> 
   typename boost::enable_if<typename 
   has_get_event_data<Event>::type,void>::type 
   on_entry(Event const& evt,FSM& fsm) 
   { 
      evt.getEventData(); 
   } 
   // for events not supporting getEventData like esub 
   template <class Event,class FSM> 
   typename boost::disable_if<typename 
   has_get_event_data<Event>::type,void>::type 
   on_entry(Event const& ,FSM& ) 
   {    } 
   }; 

这篇关于加强与事件和状态再利用MSM问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆