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 
11 #ifndef MENU_MODE_HPP
12 #define MENU_MODE_HPP
13 
14 #include <iostream>
15 #include <boost/any.hpp>
16 
17 #include "Events.hpp"
18 #include <boost/msm/back/favor_compile_time.hpp>
19 #include <boost/msm/back/state_machine.hpp>
20 #include <boost/msm/front/state_machine_def.hpp>
21 
22 using namespace std;
23 namespace msm = boost::msm;
24 
25 struct MenuMode_ : public msm::front::state_machine_def<MenuMode_>
26 {
27     typedef mpl::vector1<MenuActive>        flag_list;
28     struct WaitingForSongChoice : public msm::front::state<>
29     {
30         template <class Event,class FSM>
on_entryMenuMode_::WaitingForSongChoice31         void on_entry(Event const&,FSM& ) {std::cout << "starting: MenuMode::WaitingForSongChoice" << std::endl;}
32         template <class Event,class FSM>
on_exitMenuMode_::WaitingForSongChoice33         void on_exit(Event const&,FSM& ) {std::cout << "finishing: MenuMode::WaitingForSongChoice" << std::endl;}
34     };
35     struct StartCurrentSong : public msm::front::state<>
36     {
37         template <class Event,class FSM>
on_entryMenuMode_::StartCurrentSong38         void on_entry(Event const&,FSM& ) {std::cout << "starting: MenuMode::StartCurrentSong" << std::endl;}
39         template <class Event,class FSM>
on_exitMenuMode_::StartCurrentSong40         void on_exit(Event const&,FSM& ) {std::cout << "finishing: MenuMode::StartCurrentSong" << std::endl;}
41     };
42     struct MenuExit : public msm::front::exit_pseudo_state<CloseMenu>
43     {
44         template <class Event,class FSM>
on_entryMenuMode_::MenuExit45         void on_entry(Event const&,FSM& ) {std::cout << "starting: MenuMode::WaitingForSongChoice" << std::endl;}
46         template <class Event,class FSM>
on_exitMenuMode_::MenuExit47         void on_exit(Event const&,FSM& ) {std::cout << "finishing: MenuMode::WaitingForSongChoice" << std::endl;}
48     };
49     typedef WaitingForSongChoice initial_state;
50     typedef MenuMode_ fsm; // makes transition table cleaner
51     // Transition table for player
52     struct transition_table : mpl::vector2<
53         //     Start                 Event           Next                Action                   Guard
54         //    +---------------------+------------------+-------------------+---------------------+----------------------+
55         _row < WaitingForSongChoice , MenuMiddleButton , StartCurrentSong                                               >,
56         _row < StartCurrentSong     , SelectSong       , MenuExit                                                       >
57         //    +---------------------+------------------+-------------------+---------------------+----------------------+
58     > {};
59 };
60 typedef msm::back::state_machine<MenuMode_> MenuMode;
61 
62 #endif
63