row2_helper.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_HELPER_HPP
  11. #define BOOST_MSM_ROW2_HELPER_HPP
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/fusion/include/at_key.hpp>
  14. namespace boost { namespace msm { namespace front
  15. {
  16. namespace detail
  17. {
  18. template<
  19. typename CalledForAction
  20. , typename Event
  21. , void (CalledForAction::*action)(Event const&)
  22. >
  23. struct row2_action_helper
  24. {
  25. template <class FSM,class Evt,class SourceState,class TargetState, class AllStates>
  26. static void call_helper(FSM&,Evt const& evt,SourceState&,TargetState&,
  27. AllStates& all_states,::boost::mpl::false_ const &)
  28. {
  29. // in this front-end, we don't need to know source and target states
  30. ( ::boost::fusion::at_key<CalledForAction>(all_states).*action)(evt);
  31. }
  32. template <class FSM,class Evt,class SourceState,class TargetState, class AllStates>
  33. static void call_helper(FSM& fsm,Evt const& evt,SourceState&,TargetState&,AllStates&,
  34. ::boost::mpl::true_ const &)
  35. {
  36. // in this front-end, we don't need to know source and target states
  37. (fsm.*action)(evt);
  38. }
  39. };
  40. template<
  41. typename CalledForGuard
  42. , typename Event
  43. , bool (CalledForGuard::*guard)(Event const&)
  44. >
  45. struct row2_guard_helper
  46. {
  47. template <class FSM,class Evt,class SourceState,class TargetState,class AllStates>
  48. static bool call_helper(FSM&,Evt const& evt,SourceState&,TargetState&,
  49. AllStates& all_states, ::boost::mpl::false_ const &)
  50. {
  51. // in this front-end, we don't need to know source and target states
  52. return ( ::boost::fusion::at_key<CalledForGuard>(all_states).*guard)(evt);
  53. }
  54. template <class FSM,class Evt,class SourceState,class TargetState,class AllStates>
  55. static bool call_helper(FSM& fsm,Evt const& evt,SourceState&,TargetState&,
  56. AllStates&,::boost::mpl::true_ const &)
  57. {
  58. // in this front-end, we don't need to know source and target states
  59. return (fsm.*guard)(evt);
  60. }
  61. };
  62. }
  63. }}}
  64. #endif //BOOST_MSM_ROW2_HELPER_HPP