// Composite_Sate_explicit_entry.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "boost/msm/back/state_machine.hpp" #include "boost/msm/front/state_machine_def.hpp" namespace msm = boost::msm; namespace mpl = boost::mpl; #include namespace test_fsm // Concrete FSM implementation { // events struct event1 {}; struct event2 {}; struct event3 {}; struct event4 {}; // Concrete FSM implementation struct SM1_ : public msm::front::state_machine_def { // no need for exception handling typedef int no_exception_thrown; // The list of FSM states struct Idle : public msm::front::state<> { // optional entry/exit methods template void on_entry(Event const&,FSM& ms_) {std::cout << "entering: Idle " << ms_.m_SmName << std::endl;} template void on_exit(Event const&,FSM& ) {std::cout << "leaving: Idle" << std::endl;} }; struct RunningStateMachine_ : public msm::front::state_machine_def { // no need for exception handling typedef int no_exception_thrown; // optional entry/exit methods template void on_entry(Event const&,FSM& ms_) {std::cout << "entering: RunningStateMachine " << ms_.m_SmName << std::endl;} template void on_exit(Event const&,FSM& ) {std::cout << "leaving: RunningStateMachine" << std::endl;} // The list of FSM states struct InitialState : public msm::front::state<> { // optional entry/exit methods template void on_entry(Event const&,FSM& ) {std::cout << "entering: InitialState" << std::endl;} template void on_exit(Event const&,FSM& ) {std::cout << "leaving: InitialState" << std::endl;} }; // The list of FSM states struct State2 : public msm::front::state<> { //// optional entry/exit methods //template //void on_entry(Event const&,FSM& ) {std::cout << "entering: State2" << std::endl;} template void on_entry(event3 const&,FSM& ) {std::cout << "entering: State2:Event3" << std::endl;} template void on_entry(event1 const&,FSM& ) {std::cout << "entering: State2:Event1" << std::endl;} template void on_exit(Event const&,FSM& ) {std::cout << "leaving: State2" << std::endl;} }; // the initial state of the player SM. Must be defined typedef Idle initial_state; void onEvent3(event3 const&) { std::cout << "Action: RunningStateMachine::onEvent3" << std::endl; } void onEvent4(event4 const&) { std::cout << "Action: RunningStateMachine::onEvent4" << std::endl; } struct transition_table : mpl::vector< // Start Event Next Action Guard // +--------------+-------------+--------------+-----------------------------------+----------------------+ a_row < InitialState , event3 , State2 , &RunningStateMachine_::onEvent3 > , a_irow < InitialState , event4 , &RunningStateMachine_::onEvent4 > // +--------------+-------------+--------------+-----------------------------------+----------------------+ > {}; static const char m_SmName[]; }; typedef msm::back::state_machine RunningStateMachine; // the initial state of the player SM. Must be defined typedef Idle initial_state; // transition actions void onEvent1(event1 const&) { std::cout << "Action: MS1::onEvent1" << std::endl; } // transition actions void onEvent2(event2 const&) { std::cout << "Action: MS1::onEvent1" << std::endl; } // Transition table for SubFsm2 struct transition_table : mpl::vector< // Start Event Next Action Guard // +------+--------+---------------------+-------------------+----------------------+ a_row < Idle , event1 , RunningStateMachine , &SM1_::onEvent1 > , a_row < Idle , event2 , Idle , &SM1_::onEvent2 > // +------+--------+---------------------+-------------------+----------------------+ > {}; static const char m_SmName[]; }; typedef msm::back::state_machine SM1; } const char test_fsm::SM1_::m_SmName[] = "MS1_"; const char test_fsm::SM1_::RunningStateMachine_::m_SmName[] = "RunningStateMachine_"; int _tmain(int argc, _TCHAR* argv[]) { test_fsm::SM1 sm; sm.start(); sm.process_event(test_fsm::event1()); sm.process_event(test_fsm::event2()); sm.process_event(test_fsm::event3()); sm.process_event(test_fsm::event4()); return 0; }