. 내가 fsm.process_event(some_event())
를 호출 할 때 반응은 그것이 내가 시도 - 캐치와 예외를 처리 한 후 fsm
이 종료 내 상태 기 인스턴스를 차단하는 것이 밝혀 예외를 던질 것으로 예상된다. 즉 fsm.terminated()
반환 true
이다. 어떤 경우에는 해지되기를 원하지 않습니다. 나는 상태 기 비 처리 이벤트에 대한 fsm.process_event(irrelevant_event())
의 호출을 통보하고 현재 이전 이벤트 상태를 유지하기 위해 예외를 throw 할 때처럼. 나는 그것이 예외가 발생 전에 예외 상태의 유지 후 종료에서 boost::statechart
을 방지 할 수있는 방법 -던져
?
예제 코드 :
namespace sc = boost::statechart;
class State;
struct some_event : public sc::event<some_event> { };
class FSM
: public sc::state_machine< FSM, State, std::allocator<void>, sc::exception_translator<> >
{
public:
FSM()
{
cout<<"FSM::FSM()"<<endl;
}
virtual ~FSM()
{
cout<<"FSM::~FSM()"<<endl;
}
};
class State : public sc::simple_state< State, FSM >
{
public:
State()
{
cout<<"State::State()"<<endl;
}
virtual ~State()
{
cout<<"State::~State()"<<endl;
}
typedef boost::mpl::list<
sc::custom_reaction<some_event>,
sc::custom_reaction<sc::exception_thrown>
> reactions;
sc::result react(const some_event & e)
{
cout<<"State::react(const some_event &)"<<endl;
throw std::exception();
return this->discard_event();
}
sc::result react(const sc::exception_thrown & e)
{
cout<<"State::react(const sc::exception_thrown &)"<<endl;
throw;
return this->discard_event();
}
};
int main()
{
FSM fsm;
fsm.initiate();
try
{
fsm.process_event(some_event());
}
catch(...)
{
cout<<"Exception caught"<<endl;
}
if(fsm.terminated())
{
cout<<"fsm2 is TERMINATED"<<endl;
}
else
{
cout<<"fsm2 is RUNNING"<<endl;
}
return 0;
}
코드 출력 :
FSM::FSM()
State::State()
State::react(const some_event &)
State::react(const sc::exception_thrown &)
State::~State()
Exception caught
fsm2 is TERMINATED
나는 출력을 원하는 :
FSM::FSM()
State::State()
State::react(const some_event &)
State::react(const sc::exception_thrown &)
State::~State()
Exception caught
fsm2 is RUNNING