TestErrorOrthogonality.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #include <iostream>
  11. // back-end
  12. #include <boost/msm/back/state_machine.hpp>
  13. #include <boost/msm/back/mpl_graph_fsm_check.hpp>
  14. //front-end
  15. #include <boost/msm/front/state_machine_def.hpp>
  16. namespace msm = boost::msm;
  17. namespace mpl = boost::mpl;
  18. using namespace msm::back;
  19. namespace
  20. {
  21. // events
  22. struct play {};
  23. struct end_pause {};
  24. struct stop {};
  25. struct pause {};
  26. struct open_close {};
  27. struct cd_detected{};
  28. struct error_found {};
  29. // front-end: define the FSM structure
  30. struct player_ : public msm::front::state_machine_def<player_>
  31. {
  32. // The list of FSM states
  33. struct Empty : public msm::front::state<>
  34. {
  35. };
  36. struct Open : public msm::front::state<>
  37. {
  38. };
  39. // sm_ptr still supported but deprecated as functors are a much better way to do the same thing
  40. struct Stopped : public msm::front::state<>
  41. {
  42. };
  43. struct Playing : public msm::front::state<>
  44. {
  45. };
  46. // state not defining any entry or exit
  47. struct Paused : public msm::front::state<>
  48. {
  49. };
  50. struct AllOk : public msm::front::state<>
  51. {
  52. };
  53. struct ErrorMode : public msm::front::state<>
  54. {
  55. };
  56. struct State1 : public msm::front::state<>
  57. {
  58. };
  59. struct State2 : public msm::front::state<>
  60. {
  61. };
  62. // the initial state of the player SM. Must be defined
  63. typedef mpl::vector<Empty,AllOk> initial_state;
  64. // Transition table for player
  65. struct transition_table : mpl::vector<
  66. // Start Event Next Action Guard
  67. // +---------+-------------+---------+---------------------+----------------------+
  68. // adding this line makes non-reachable states and should cause a static assert
  69. //_row < State1 , open_close , State2 >,
  70. // adding this line makes non-orthogonal regions and should cause a static assert
  71. //_row < Paused , error_found , ErrorMode >,
  72. _row < Stopped , play , Playing >,
  73. _row < Stopped , open_close , Open >,
  74. _row < Stopped , stop , Stopped >,
  75. // +---------+-------------+---------+---------------------+----------------------+
  76. _row < Open , open_close , Empty >,
  77. // +---------+-------------+---------+---------------------+----------------------+
  78. _row < Empty , open_close , Open >,
  79. _row < Empty , cd_detected , Stopped >,
  80. _row < Empty , cd_detected , Playing >,
  81. // +---------+-------------+---------+---------------------+----------------------+
  82. _row < Playing , stop , Stopped >,
  83. _row < Playing , pause , Paused >,
  84. _row < Playing , open_close , Open >,
  85. // +---------+-------------+---------+---------------------+----------------------+
  86. _row < Paused , end_pause , Playing >,
  87. _row < Paused , stop , Stopped >,
  88. _row < Paused , open_close , Open >,
  89. _row < AllOk , error_found , ErrorMode >
  90. // +---------+-------------+---------+---------------------+----------------------+
  91. > {};
  92. // Replaces the default no-transition response.
  93. template <class FSM,class Event>
  94. void no_transition(Event const& e, FSM&,int state)
  95. {
  96. }
  97. };
  98. // Pick a back-end
  99. typedef msm::back::state_machine<player_,msm::back::mpl_graph_fsm_check> player;
  100. void test()
  101. {
  102. player p;
  103. }
  104. }
  105. int main()
  106. {
  107. test();
  108. return 0;
  109. }