#include #include #include #include #include #include namespace msm = boost::msm; namespace euml = boost::msm::front::euml; namespace mpl = boost::mpl; typedef msm::front::none none; #define _CHECK(cond) std::cout << #cond << ": " << ((cond) ? "yes" : "no") << std::endl; struct EvStart1 {}; struct EvStop1 {}; struct EvStart2 {}; struct EvStop2 {}; struct FlagStarted {}; struct StateMachine_: public msm::front::state_machine_def { // --- states --- // region 1 struct Stopped1: public msm::front::state<> { template void on_entry(Event const&, FSM& fsm) { std::cout << "Entering Stopped1" << std::endl; } template void on_exit(Event const&, FSM& fsm) { std::cout << "Leaving Stopped1" << std::endl; } }; struct Started1: public msm::front::state<> { typedef mpl::vector1 flag_list; template void on_entry(Event const&, FSM& fsm) { std::cout << "Entering Started1" << std::endl; } template void on_exit(Event const&, FSM& fsm) { std::cout << "Leaving Started1" << std::endl; } }; // region 2 struct Stopped2: public msm::front::state<> { template void on_entry(Event const&, FSM& fsm) { std::cout << "Entering Stopped2" << std::endl; } template void on_exit(Event const&, FSM& fsm) { std::cout << "Leaving Stopped2" << std::endl; } }; struct Started2: public msm::front::state<> { typedef mpl::vector1 flag_list; template void on_entry(Event const&, FSM& fsm) { std::cout << "Entering Started2" << std::endl; } template void on_exit(Event const&, FSM& fsm) { std::cout << "Leaving Started2" << std::endl; } }; typedef mpl::vector initial_state; // --- transition table --- struct transition_table: mpl::vector< msm::front::Row, msm::front::Row, msm::front::Row, msm::front::Row > {}; }; typedef msm::back::state_machine StateMachine; int main() { StateMachine sm; sm.start(); _CHECK((sm.is_flag_active())); _CHECK((sm.is_flag_active())); sm.process_event(EvStart1()); _CHECK((sm.is_flag_active())); _CHECK((sm.is_flag_active())); sm.process_event(EvStart2()); _CHECK((sm.is_flag_active())); _CHECK((sm.is_flag_active())); return 0; }