row2.hpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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_ROW2_HPP
  11. #define BOOST_MSM_ROW2_HPP
  12. #include <boost/type_traits/is_base_of.hpp>
  13. #include <boost/mpl/bool.hpp>
  14. #include <boost/fusion/include/at_key.hpp>
  15. #include <boost/msm/back/common_types.hpp>
  16. #include <boost/msm/row_tags.hpp>
  17. #include <boost/msm/front/detail/row2_helper.hpp>
  18. namespace boost { namespace msm { namespace front
  19. {
  20. template<
  21. typename T1
  22. , class Event
  23. , typename T2
  24. >
  25. struct _row2
  26. {
  27. typedef _row_tag row_type_tag;
  28. typedef T1 Source;
  29. typedef T2 Target;
  30. typedef Event Evt;
  31. };
  32. template<
  33. typename T1
  34. , class Event
  35. , typename T2
  36. , typename CalledForAction
  37. , void (CalledForAction::*action)(Event const&)
  38. >
  39. struct a_row2
  40. {
  41. typedef a_row_tag row_type_tag;
  42. typedef T1 Source;
  43. typedef T2 Target;
  44. typedef Event Evt;
  45. template <class FSM,class SourceState,class TargetState,class AllStates>
  46. static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  47. AllStates& all_states)
  48. {
  49. // in this front-end, we don't need to know source and target states
  50. ::boost::msm::front::detail::row2_action_helper<CalledForAction,Event,action>::template call_helper
  51. (fsm,evt,src,tgt,all_states,
  52. ::boost::mpl::bool_< ::boost::is_base_of<CalledForAction,FSM>::type::value>());
  53. return ::boost::msm::back::HANDLED_TRUE;
  54. }
  55. };
  56. template<
  57. typename T1
  58. , class Event
  59. , typename T2
  60. , typename CalledForAction
  61. , void (CalledForAction::*action)(Event const&)
  62. , typename CalledForGuard
  63. , bool (CalledForGuard::*guard)(Event const&)
  64. >
  65. struct row2
  66. {
  67. typedef row_tag row_type_tag;
  68. typedef T1 Source;
  69. typedef T2 Target;
  70. typedef Event Evt;
  71. template <class FSM,class SourceState,class TargetState, class AllStates>
  72. static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  73. AllStates& all_states)
  74. {
  75. // in this front-end, we don't need to know source and target states
  76. ::boost::msm::front::detail::row2_action_helper<CalledForAction,Event,action>::call_helper
  77. (fsm,evt,src,tgt,all_states,
  78. ::boost::mpl::bool_< ::boost::is_base_of<CalledForAction,FSM>::type::value>());
  79. return ::boost::msm::back::HANDLED_TRUE;
  80. }
  81. template <class FSM,class SourceState,class TargetState,class AllStates>
  82. static bool guard_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  83. AllStates& all_states)
  84. {
  85. // in this front-end, we don't need to know source and target states
  86. return ::boost::msm::front::detail::row2_guard_helper<CalledForGuard,Event,guard>::call_helper
  87. (fsm,evt,src,tgt,all_states,
  88. ::boost::mpl::bool_< ::boost::is_base_of<CalledForGuard,FSM>::type::value>());
  89. }
  90. };
  91. template<
  92. typename T1
  93. , class Event
  94. , typename T2
  95. , typename CalledForGuard
  96. , bool (CalledForGuard::*guard)(Event const&)
  97. >
  98. struct g_row2
  99. {
  100. typedef g_row_tag row_type_tag;
  101. typedef T1 Source;
  102. typedef T2 Target;
  103. typedef Event Evt;
  104. template <class FSM,class SourceState,class TargetState,class AllStates>
  105. static bool guard_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  106. AllStates& all_states)
  107. {
  108. // in this front-end, we don't need to know source and target states
  109. return ::boost::msm::front::detail::row2_guard_helper<CalledForGuard,Event,guard>::call_helper
  110. (fsm,evt,src,tgt,all_states,
  111. ::boost::mpl::bool_< ::boost::is_base_of<CalledForGuard,FSM>::type::value>());
  112. }
  113. };
  114. // internal transitions
  115. template<
  116. typename T1
  117. , class Event
  118. , typename CalledForAction
  119. , void (CalledForAction::*action)(Event const&)
  120. >
  121. struct a_irow2
  122. {
  123. typedef a_irow_tag row_type_tag;
  124. typedef T1 Source;
  125. typedef T1 Target;
  126. typedef Event Evt;
  127. template <class FSM,class SourceState,class TargetState,class AllStates>
  128. static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  129. AllStates& all_states)
  130. {
  131. // in this front-end, we don't need to know source and target states
  132. ::boost::msm::front::detail::row2_action_helper<CalledForAction,Event,action>::call_helper
  133. (fsm,evt,src,tgt,all_states,
  134. ::boost::mpl::bool_< ::boost::is_base_of<CalledForAction,FSM>::type::value>());
  135. return ::boost::msm::back::HANDLED_TRUE;
  136. }
  137. };
  138. template<
  139. typename T1
  140. , class Event
  141. , typename CalledForAction
  142. , void (CalledForAction::*action)(Event const&)
  143. , typename CalledForGuard
  144. , bool (CalledForGuard::*guard)(Event const&)
  145. >
  146. struct irow2
  147. {
  148. typedef irow_tag row_type_tag;
  149. typedef T1 Source;
  150. typedef T1 Target;
  151. typedef Event Evt;
  152. template <class FSM,class SourceState,class TargetState,class AllStates>
  153. static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  154. AllStates& all_states)
  155. {
  156. // in this front-end, we don't need to know source and target states
  157. ::boost::msm::front::detail::row2_action_helper<CalledForAction,Event,action>::call_helper
  158. (fsm,evt,src,tgt,all_states,
  159. ::boost::mpl::bool_< ::boost::is_base_of<CalledForAction,FSM>::type::value>());
  160. return ::boost::msm::back::HANDLED_TRUE;
  161. }
  162. template <class FSM,class SourceState,class TargetState,class AllStates>
  163. static bool guard_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  164. AllStates& all_states)
  165. {
  166. // in this front-end, we don't need to know source and target states
  167. return ::boost::msm::front::detail::row2_guard_helper<CalledForGuard,Event,guard>::call_helper
  168. (fsm,evt,src,tgt,all_states,
  169. ::boost::mpl::bool_< ::boost::is_base_of<CalledForGuard,FSM>::type::value>());
  170. }
  171. };
  172. template<
  173. typename T1
  174. , class Event
  175. , typename CalledForGuard
  176. , bool (CalledForGuard::*guard)(Event const&)
  177. >
  178. struct g_irow2
  179. {
  180. typedef g_irow_tag row_type_tag;
  181. typedef T1 Source;
  182. typedef T1 Target;
  183. typedef Event Evt;
  184. template <class FSM,class SourceState,class TargetState,class AllStates>
  185. static bool guard_call(FSM& fsm,Event const& evt,SourceState& src,TargetState& tgt,
  186. AllStates& all_states)
  187. {
  188. // in this front-end, we don't need to know source and target states
  189. return ::boost::msm::front::detail::row2_guard_helper<CalledForGuard,Event,guard>::call_helper
  190. (fsm,evt,src,tgt,all_states,
  191. ::boost::mpl::bool_< ::boost::is_base_of<CalledForGuard,FSM>::type::value>());
  192. }
  193. };
  194. }}}
  195. #endif //BOOST_MSM_ROW2_HPP