#include #include #include #include namespace { namespace msm = boost::msm; namespace msmf = boost::msm::front; namespace mpl = boost::mpl; // Events struct Event1 {}; struct Event2 {}; // ----- State machine struct Sm1_:msm::front::state_machine_def { struct State1_:msm::front::state_machine_def { // Guards struct Guard1_1 { template bool operator()(Event const&, Fsm&, SourceState&, TargetState&) const { std::cout << "Guard1_1" << std::endl; return true; } }; // Actions struct Action1_1 { template void operator()(Event const&, Fsm&, SourceState&, TargetState&) const { std::cout << "Action1_1" << std::endl; } }; struct State1_1; // Set initial state typedef State1_1 initial_state; // States struct State1_1:msm::front::state<> { // Internal Transition table struct internal_transition_table : mpl::vector< // Event Action Guard msmf::Internal < Event1, Action1_1 ,Guard1_1 > > {}; }; struct State1_2:msm::front::state<> {}; #if 1 // Why is it needed? // Transition table struct transition_table:mpl::vector< // Start Event Next Action Guard msmf::Row < State1_1, Event1, State1_2, msmf::none, msmf::none > // OK // msmf::Row < State1_1, Event2, State1_2, msmf::none, msmf::none > // NG > {}; #endif // No handled event handler template void no_transition(Event const& e, Fsm& ,int state) { std::cout << "No handled event in State1_1 " << typeid(e).name() << " on State " << state << std::endl; } }; // back-end typedef msm::back::state_machine State1; // Set initial state typedef State1 initial_state; // No handled event handler template void no_transition(Event const& e, Fsm& ,int state) { std::cout << "No handled event in Sm1 " << typeid(e).name() << " on State " << state << std::endl; } }; // back-end typedef msm::back::state_machine Sm1; void test() { Sm1 sm1; sm1.start(); std::cout << "> Send Event1" << std::endl; sm1.process_event(Event1()); } } int main() { test(); return 0; }