A simple finite state machine:
This state machine has two, State1 states, and an end state.
The following code can describe this state machine:
#include <iostream>#include <boost/msm/back/state_machine.hpp>#include <boost/msm/front/state_machine_def.hpp>#include <boost/msm/front/functor_row.hpp>namespace{namespaceMSM = BOOST::MSM;namespaceMSMF = Boost::msm::front;namespaceMPL = Boost::mpl;//-----Events structEvent1 {};//----- State Machine structsm1_:msmf::state_machine_def<sm1_> {//States structstate1:msmf::state<> {//Entry action Template<classEvent,classFsm>voidOn_entry (EventConst&, fsm&)Const{STD::cout<<"State1::on_entry ()"<<STD:: Endl; }//Exit action Template<classEvent,classFsm>voidOn_exit (EventConst&, fsm&)Const{STD::cout<<"State1::on_exit ()"<<STD:: Endl; } };structend:msmf::terminate_state<> {};//Set initial state typedefState1 initial_state;//Transition table structTransition_table:mpl:: Vector<//Start Event Next Action Guard Msmf::row < State1, Event1, End, Msmf::none, Msmf::none >> {}; };//Pick a back-end typedefMsm::back::state_machine<sm1_> Sm1;voidTest () {Sm1 sm1; Sm1.start ();STD::cout<<"> Send Event1"<<STD:: Endl; Sm1.process_event (Event1 ()); }}intMain () {test ();return 0;}
// Output://// State1::on_entry()// > Send Event1// State1::on_exit()// Set initial statetypedef State1 initial_state;
typedef XXX INITIAL_STATE Represents the state machine sm1_ starting from the state State1.
Respect original, original link, Mark Spare
Finite state machine, BOOST::MSM