states.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2008 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 BOOST_MSM_FRONT_STATES_H
  11. #define BOOST_MSM_FRONT_STATES_H
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/mpl/vector.hpp>
  14. #include <boost/msm/front/common_states.hpp>
  15. #include <boost/msm/row_tags.hpp>
  16. #include <boost/msm/back/metafunctions.hpp>
  17. namespace boost { namespace msm { namespace front
  18. {
  19. struct no_sm_ptr
  20. {
  21. // tags
  22. typedef ::boost::mpl::bool_<false> needs_sm;
  23. };
  24. struct sm_ptr
  25. {
  26. // tags
  27. typedef ::boost::mpl::bool_<true> needs_sm;
  28. };
  29. // kept for backward compatibility
  30. struct NoSMPtr
  31. {
  32. // tags
  33. typedef ::boost::mpl::bool_<false> needs_sm;
  34. };
  35. struct SMPtr
  36. {
  37. // tags
  38. typedef ::boost::mpl::bool_<true> needs_sm;
  39. };
  40. // provides the typedefs and interface. Concrete states derive from it.
  41. // template argument: pointer-to-fsm policy
  42. template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
  43. struct state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
  44. {
  45. // tags
  46. // default: no flag
  47. typedef ::boost::mpl::vector0<> flag_list;
  48. typedef ::boost::mpl::vector0<> internal_flag_list;
  49. //default: no deferred events
  50. typedef ::boost::mpl::vector0<> deferred_events;
  51. };
  52. // terminate state simply defines the TerminateFlag flag
  53. // template argument: pointer-to-fsm policy
  54. template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
  55. struct terminate_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
  56. {
  57. // tags
  58. typedef ::boost::mpl::vector0<> flag_list;
  59. typedef ::boost::mpl::vector< boost::msm::TerminateFlag> internal_flag_list;
  60. //default: no deferred events
  61. typedef ::boost::mpl::vector0<> deferred_events;
  62. };
  63. // terminate state simply defines the InterruptedFlag and EndInterruptFlag<EndInterruptEvent> flags
  64. // template argument: event which ends the interrupt
  65. // template argument: pointer-to-fsm policy
  66. template <class EndInterruptEvent,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
  67. struct interrupt_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
  68. {
  69. // tags
  70. typedef ::boost::mpl::vector0<> flag_list;
  71. typedef typename boost::msm::back::build_interrupt_state_flag_list<
  72. typename boost::msm::back::get_interrupt_events<EndInterruptEvent>::type
  73. >::type internal_flag_list;
  74. //default: no deferred events
  75. typedef ::boost::mpl::vector0<> deferred_events;
  76. };
  77. // not a state but a bunch of extra typedefs to handle direct entry into a composite state. To be derived from
  78. // template argument: zone index of this state
  79. template <int ZoneIndex=-1>
  80. struct explicit_entry
  81. {
  82. typedef int explicit_entry_state;
  83. enum {zone_index=ZoneIndex};
  84. };
  85. // to be derived from. Makes a type an entry (pseudo) state. Actually an almost full-fledged state
  86. // template argument: containing composite
  87. // template argument: zone index of this state
  88. // template argument: pointer-to-fsm policy
  89. template<int ZoneIndex=-1,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
  90. struct entry_pseudo_state
  91. : public boost::msm::front::detail::state_base<BASE>,SMPtrPolicy
  92. {
  93. // tags
  94. typedef int pseudo_entry;
  95. enum {zone_index=ZoneIndex};
  96. typedef int explicit_entry_state;
  97. // default: no flag
  98. typedef ::boost::mpl::vector0<> flag_list;
  99. typedef ::boost::mpl::vector0<> internal_flag_list;
  100. //default: no deferred events
  101. typedef ::boost::mpl::vector0<> deferred_events;
  102. };
  103. // to be derived from. Makes a state an exit (pseudo) state. Actually an almost full-fledged state
  104. // template argument: event to forward
  105. // template argument: pointer-to-fsm policy
  106. template<class Event,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
  107. struct exit_pseudo_state : public boost::msm::front::detail::state_base<BASE> , SMPtrPolicy
  108. {
  109. typedef Event event;
  110. typedef BASE Base;
  111. typedef SMPtrPolicy PtrPolicy;
  112. typedef int pseudo_exit;
  113. // default: no flag
  114. typedef ::boost::mpl::vector0<> flag_list;
  115. typedef ::boost::mpl::vector0<> internal_flag_list;
  116. //default: no deferred events
  117. typedef ::boost::mpl::vector0<> deferred_events;
  118. };
  119. }}}
  120. #endif //BOOST_MSM_FRONT_STATES_H