有什么解决办法吗?
在Ubuntu 8.10 w/g++4.3.2上使用1.39_0
在下面的状态图中,短语“Buggy”打印为3
时代。人们会期望事件只会触发一个“错误”。在
我正在做的这个项目,我不能回去了
丢弃_Event(),因为我需要事件达到多个状态(通常
在一组正交状态中)。如果有解决办法的话
我想知道,可以应用而不是修改状态图。
$BT Bug
#include <boost/intrusive_ptr.hpp>
#include <boost/mpl/list.hpp> #include <boost/statechart/custom_reaction.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state.hpp>
#include <boost/statechart/state_machine.hpp>
#include <iostream>
using namespace std;
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
struct evSay : sc::event<evSay>{ };
struct top;
struct c1;
struct c2;
struct c3;
struct sm : public sc::state_machine<sm,top> { };
struct top : sc::simple_state<top,sm,mpl::list<c1,c2,c3> > {
typedef sc::custom_reaction<evSay> reactions;
sc::result react(const evSay &) {
cout<<"BUGGY"<<endl;
return forward_event();
}
};
struct c1 : sc::simple_state <c1, top::orthogonal<0> > { };
struct c2 : sc::simple_state <c2, top::orthogonal<1> > { };
struct c3 : sc::state <c3, top::orthogonal<2> > {
c3( my_context ctx) : my_base(ctx) {
post_event( boost::intrusive_ptr< evSay > (
new evSay() ) );
}
};
int main() {
sm* fsm = new sm();
fsm->initiate();
delete fsm;
return 0;
}
$G++错误.cpp&&/A.out
婴儿车
婴儿车
婴儿车
编辑:
这是一个示例状态机,它显示了我在实际工作中遇到的更大的问题。我知道Top会转发Evsay。注意,c1、c2、c3对evsay没有反应。这里有一个例子,我需要转发,以便两个状态可以对evsay作出反应。
#include <boost/intrusive_ptr.hpp>
#include <boost/mpl/list.hpp>
#include <boost/statechart/custom_reaction.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state.hpp>
#include <boost/statechart/state_machine.hpp>
#include <iostream>
using namespace std;
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
namespace BUG {
struct evSay : sc::event<evSay>{ };
struct top;struct c1;struct c2;struct c3;struct c2_1;
struct sm : public sc::state_machine<sm,top> { };
struct top : sc::simple_state<top,sm,mpl::list<c1,c2,c3> > {
typedef sc::simple_state<top,sm,mpl::list<c1,c2,c3> > my_type;
typedef sc::custom_reaction<evSay> reactions;
sc::result react(const evSay &) {
cout<<"BUGGY"<<endl;
return forward_event();
}
};
struct c1 : sc::simple_state <c1, top::orthogonal<0> > { };
struct c2 : sc::simple_state <c2, top::orthogonal<1>, c2_1 > { };
struct c3 : sc::state <c3, top::orthogonal<2> > {
c3( my_context ctx) : my_base(ctx) {
post_event( boost::intrusive_ptr< evSay > (
new evSay() ) );
}
};
struct c2_1 : sc::simple_state<c2_1, c2 > {
typedef sc::custom_reaction<evSay> reactions;
sc::result react(const evSay &) {
cout<<"CHILD REACTION"<<endl;
return forward_event();
}
};
}
int main()
{
BUG::sm* fsm = new BUG::sm();
fsm->initiate();
delete fsm;
return 0;
}
输出:
婴儿车
子反应
婴儿车
婴儿车