MenuMode.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2010 Christophe Henry
  2. // henry UNDERSCORE christophe AT hotmail DOT com
  3. // This is an extended version of the state machine available in the boost::mpl library
  4. // Distributed under the same license as the original.
  5. // Copyright for the original version:
  6. // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
  7. // under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef MENU_MODE_HPP
  11. #define MENU_MODE_HPP
  12. #include <iostream>
  13. #include <boost/any.hpp>
  14. #include "Events.hpp"
  15. #include <boost/msm/back/favor_compile_time.hpp>
  16. #include <boost/msm/back/state_machine.hpp>
  17. #include <boost/msm/front/state_machine_def.hpp>
  18. using namespace std;
  19. namespace msm = boost::msm;
  20. struct MenuMode_ : public msm::front::state_machine_def<MenuMode_>
  21. {
  22. typedef mpl::vector1<MenuActive> flag_list;
  23. struct WaitingForSongChoice : public msm::front::state<>
  24. {
  25. template <class Event,class FSM>
  26. void on_entry(Event const&,FSM& ) {std::cout << "starting: MenuMode::WaitingForSongChoice" << std::endl;}
  27. template <class Event,class FSM>
  28. void on_exit(Event const&,FSM& ) {std::cout << "finishing: MenuMode::WaitingForSongChoice" << std::endl;}
  29. };
  30. struct StartCurrentSong : public msm::front::state<>
  31. {
  32. template <class Event,class FSM>
  33. void on_entry(Event const&,FSM& ) {std::cout << "starting: MenuMode::StartCurrentSong" << std::endl;}
  34. template <class Event,class FSM>
  35. void on_exit(Event const&,FSM& ) {std::cout << "finishing: MenuMode::StartCurrentSong" << std::endl;}
  36. };
  37. struct MenuExit : public msm::front::exit_pseudo_state<CloseMenu>
  38. {
  39. template <class Event,class FSM>
  40. void on_entry(Event const&,FSM& ) {std::cout << "starting: MenuMode::WaitingForSongChoice" << std::endl;}
  41. template <class Event,class FSM>
  42. void on_exit(Event const&,FSM& ) {std::cout << "finishing: MenuMode::WaitingForSongChoice" << std::endl;}
  43. };
  44. typedef WaitingForSongChoice initial_state;
  45. typedef MenuMode_ fsm; // makes transition table cleaner
  46. // Transition table for player
  47. struct transition_table : mpl::vector2<
  48. // Start Event Next Action Guard
  49. // +---------------------+------------------+-------------------+---------------------+----------------------+
  50. _row < WaitingForSongChoice , MenuMiddleButton , StartCurrentSong >,
  51. _row < StartCurrentSong , SelectSong , MenuExit >
  52. // +---------------------+------------------+-------------------+---------------------+----------------------+
  53. > {};
  54. };
  55. typedef msm::back::state_machine<MenuMode_> MenuMode;
  56. #endif