Advertisement
Guest User

Boost MSM compile time error

a guest
May 23rd, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <boost/msm/back/state_machine.hpp>
  3. #include <boost/msm/front/state_machine_def.hpp>
  4. #include <boost/msm/front/functor_row.hpp>
  5. #include <boost/msm/front/euml/common.hpp>
  6. #include <boost/msm/front/euml/operator.hpp>
  7.  
  8. using namespace std;
  9. namespace msm = boost::msm;
  10. namespace mpl = boost::mpl;
  11. using namespace msm::front;
  12. using namespace msm::front::euml;
  13.  
  14. //----------------------------------------------------------------
  15. // Events
  16. //----------------------------------------------------------------
  17. struct next_animation {};
  18. struct start_game {};
  19. struct host_user {};
  20.  
  21. struct character_selected
  22. {
  23.     character_selected( int element )
  24.         : element_(element)
  25.     {}
  26.  
  27.     const int element() const
  28.     {
  29.         return element_;
  30.     }
  31.  
  32.     int element_;
  33. };
  34.  
  35. struct play_again {};
  36. struct back_to_menu {};
  37. struct exit_introduction {};
  38.  
  39.  
  40. //----------------------------------------------------------------
  41. // Events (END)
  42. //----------------------------------------------------------------
  43.  
  44.  
  45. struct Holder
  46. {
  47.     struct state_machine_ : public msm::front::state_machine_def<state_machine_>
  48.     {
  49.         Holder& holder_;
  50.  
  51.         state_machine_( Holder& holder )
  52.             : holder_(holder)
  53.         {}
  54.  
  55.         Holder& holder()
  56.         {
  57.             return holder_;
  58.         }
  59.  
  60.         struct intro_state_machine_ : public msm::front::state_machine_def<intro_state_machine_>
  61.         {
  62.             Holder* holder_;
  63.  
  64.             intro_state_machine_()
  65.                 : holder_( nullptr )
  66.             {
  67.             }
  68.  
  69.             intro_state_machine_( Holder& holder )
  70.                 : holder_( boost::addressof(holder) )
  71.             {}
  72.  
  73.             Holder& holder()
  74.             {
  75.                 return *holder_;
  76.             }
  77.  
  78.             struct LogoAnimation : public msm::front::state<>
  79.             {
  80.                 template <typename Event, typename FSM>
  81.                 void on_entry(Event const&, FSM& fsm )
  82.                 {
  83.                     std::cout << "entering: LogoAnimation" << std::endl;
  84.                 }
  85.             };
  86.  
  87.             struct WaitingAnimation : public msm::front::state<>
  88.             {
  89.                 template <typename Event, typename FSM>
  90.                 void on_entry(Event const&, FSM& fsm )
  91.                 {
  92.                     std::cout << "entering: WaitingAnimation" << std::endl;
  93.                 }
  94.             };
  95.  
  96.             struct SelectBackgroundCheckUser : public msm::front::state<>, public msm::front::explicit_entry<0>
  97.             {
  98.                 template <typename Event, typename FSM>
  99.                 void on_entry(Event const&, FSM& fsm )
  100.                 {
  101.                     std::cout << "entering: SelectBackgroundCheckUser" << std::endl;
  102.                 }
  103.             };
  104.  
  105.             struct EndIntroduction : public msm::front::state<>
  106.             {
  107.                 template <typename Event, typename FSM>
  108.                 void on_entry(Event const& ,FSM& fsm)
  109.                 {
  110.                     std::cout << "entering: EndIntroduction" << std::endl;
  111.                     fsm.holder().sm().process_event( exit_introduction() );
  112.                 }
  113.             };
  114.  
  115.             typedef LogoAnimation initial_state;
  116.  
  117.             struct transition_table : mpl::vector<
  118.                   Row < LogoAnimation,             next_animation, WaitingAnimation,          none, none >
  119.                 , Row < WaitingAnimation,          next_animation, SelectBackgroundCheckUser, none, none >
  120.                 , Row < SelectBackgroundCheckUser, host_user,      EndIntroduction,           none, none >
  121.             > {};
  122.         }; // Introduction StateMachine END
  123.  
  124.  
  125.  
  126.         struct game_state_machine_ : public msm::front::state_machine_def<game_state_machine_>
  127.         {
  128.             struct Initial : public msm::front::state<>
  129.             {
  130.                 template <typename Event, typename FSM>
  131.                 void on_entry(Event const&, FSM& fsm )
  132.                 {
  133.                     std::cout << "entering: Initial" << std::endl;
  134.                 }
  135.             };
  136.  
  137.             struct StaringGame : public msm::front::state<>
  138.             {
  139.                 template <typename Event, typename FSM>
  140.                 void on_entry(Event const& event, FSM& fsm )
  141.                 {
  142.                     std::cout << "entering: StaringGame" << std::endl;
  143.                     std::cout << "event.element(): " << event.element() << std::endl;
  144.                     std::cout << "event typeid: " << typeid(event).name()  << std::endl;
  145.                 }
  146.             };
  147.  
  148.             struct StartTurn: public msm::front::state<>
  149.             {
  150.                 template <typename Event, typename FSM>
  151.                 void on_entry(Event const& event, FSM& fsm )
  152.                 {
  153.                     std::cout << "entering: StartTurn" << std::endl;
  154.                     std::cout << "event.element(): " << event.element() << std::endl;
  155.                     std::cout << "event typeid: " << typeid(event).name()  << std::endl;
  156.                 }
  157.             };
  158.  
  159.             typedef Initial initial_state;
  160.  
  161.             struct transition_table : mpl::vector<
  162.                   Row < Initial,      character_selected,  StaringGame,  none, none >
  163.                 , Row < StaringGame,  character_selected,  StartTurn,    none, none >
  164.             > {};
  165.         };
  166.  
  167.         typedef msm::back::state_machine<intro_state_machine_> IntroSM;
  168.         typedef msm::back::state_machine<game_state_machine_> GameSM;
  169.  
  170.         struct Initial : public msm::front::state<>
  171.         {
  172.             template <typename Event, typename FSM>
  173.             void on_entry(Event const&, FSM& fsm )
  174.             {
  175.                 std::cout << "entering: Initial" << std::endl;
  176.             }
  177.         };
  178.  
  179.         struct End : public msm::front::state<>
  180.         {
  181.             template <typename Event, typename FSM>
  182.             void on_entry(Event const& ,FSM&)
  183.             {
  184.                 std::cout << "entering: End" << std::endl;
  185.             }
  186.         };
  187.  
  188.         typedef Initial initial_state;
  189.         struct transition_table : mpl::vector<
  190.               Row < Initial,  next_animation,    IntroSM,                                    none, none >
  191.             , Row < IntroSM,  exit_introduction, GameSM,                                     none, none >
  192. //            , Row < GameSM,   back_to_menu,      IntroSM::direct<intro_state_machine_::SelectBackgroundCheckUser>, none, none >
  193.         > {};
  194.     };
  195.  
  196.     typedef msm::back::state_machine<state_machine_> StateMachine;
  197.  
  198.     Holder()
  199.         : sm_( boost::msm::back::states_ << state_machine_::IntroSM(boost::ref(*this))
  200.               , boost::ref(*this) )
  201.     {}
  202.  
  203.     StateMachine sm_;
  204.  
  205.     StateMachine& sm()
  206.     {
  207.         return sm_;
  208.     }
  209. };
  210.  
  211.  
  212. void test()
  213. {
  214.     Holder holder;
  215.     typename Holder::StateMachine& p = holder.sm();
  216.  
  217.     p.start();
  218.  
  219.     p.process_event( next_animation() );
  220.     p.process_event( next_animation() );
  221.     p.process_event( next_animation() );
  222.     p.process_event( host_user() );
  223. //    p.process_event( exit_introduction() );       // is called inside EndIntroduction state
  224.  
  225.     p.process_event( character_selected(97) );
  226.     p.process_event( character_selected(98) );
  227.  
  228.     p.stop();
  229. }
  230.  
  231.  
  232.  
  233. int main( /*int argc, char *argv[] */ )
  234. {
  235.     test();
  236.     return 0;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement