#include #include #include #include #include #include #include #include "PlayingMode.hpp" using namespace std; namespace msm = boost::msm; namespace mpl = boost::mpl; using namespace msm::front; namespace // Concrete FSM implementation { struct PlayPause {}; // Concrete FSM implementation struct iPod_ : public msm::front::state_machine_def { // The list of FSM states struct NotPlaying : public msm::front::state<> { template void on_entry(Event const&,FSM& ) {std::cout << "starting: NotPlaying" << std::endl;} template void on_exit(Event const&,FSM& ) {std::cout << "finishing: NotPlaying" << std::endl;} }; // the initial state of the player SM. Must be defined typedef mpl::vector1 initial_state; typedef iPod_ fsm; // makes transition table cleaner // Transition table for player struct transition_table : mpl::vector< // Start Event Next Action Guard // +-------------------+---------------+-------------------+------------------- -------------+----------------------+ _row < NotPlaying , PlayPause , PlayingMode >, Row < PlayingMode::exit_pt , msm::front::none , NotPlaying > > {}; // Replaces the default no-transition response. template void no_transition(Event const& e, FSM&,int state) { std::cout << "no transition from state " << state << " on event " << typeid(e).name() << std::endl; } }; } typedef msm::back::state_machine iPod; void test() { iPod sm; sm.start(); std::cout << "send PlayPause" << std::endl; sm.process_event(PlayPause()); //2nd version, comment out the next 2 lines std::cout << "send EndPlay" << std::endl; sm.process_event(EndPlay()); } int main() { test(); return 0; }