使用boost::statechart模块自定义反应进行测试的程序
在使用boost::statechart模块开发状态机时,会经常使用自定义反应,来实现对状态转换时的额外处理。本文将介绍如何编写一个简单的测试程序,来测试我们开发的自定义反应。
首先,我们需要定义一些状态和事件。下面是一个简单的示例:
#include <boost/statechart/event.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/mpl/list.hpp>
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
struct Event1 : sc::event<Event1> {};
struct Event2 : sc::event<Event2> {};
struct Event3 : sc::event<Event3> {};
struct State1;
struct State2;
struct State3;
struct MyStateMachine : sc::state_machine<MyStateMachine, State1> {};
struct State1 : sc::simple_state<State1, MyStateMachine>
{