in_state_reaction.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED
  2. #define BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED
  3. //////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2005-2008 Andreas Huber Doenni
  5. // Distributed under the Boost Software License, Version 1.0. (See accompany-
  6. // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //////////////////////////////////////////////////////////////////////////////
  8. #include <boost/statechart/result.hpp>
  9. #include <boost/statechart/detail/reaction_dispatcher.hpp>
  10. namespace boost
  11. {
  12. namespace statechart
  13. {
  14. class event_base;
  15. //////////////////////////////////////////////////////////////////////////////
  16. template< class Event,
  17. class ReactionContext = detail::no_context< Event >,
  18. void ( ReactionContext::*pAction )( const Event & ) =
  19. &detail::no_context< Event >::no_function >
  20. class in_state_reaction
  21. {
  22. private:
  23. //////////////////////////////////////////////////////////////////////////
  24. template< class State >
  25. struct reactions
  26. {
  27. static result react_without_action( State & stt )
  28. {
  29. return stt.discard_event();
  30. }
  31. static result react_with_action( State & stt, const Event & evt )
  32. {
  33. ( stt.template context< ReactionContext >().*pAction )( evt );
  34. return react_without_action( stt );
  35. }
  36. };
  37. public:
  38. //////////////////////////////////////////////////////////////////////////
  39. // The following declarations should be private.
  40. // They are only public because many compilers lack template friends.
  41. //////////////////////////////////////////////////////////////////////////
  42. template< class State, class EventBase, class IdType >
  43. static detail::reaction_result react(
  44. State & stt, const EventBase & evt, const IdType & eventType )
  45. {
  46. typedef detail::reaction_dispatcher<
  47. reactions< State >, State, EventBase, Event, ReactionContext, IdType
  48. > dispatcher;
  49. return dispatcher::react( stt, evt, eventType );
  50. }
  51. };
  52. } // namespace statechart
  53. } // namespace boost
  54. #endif