transition.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef BOOST_STATECHART_TRANSITION_HPP_INCLUDED
  2. #define BOOST_STATECHART_TRANSITION_HPP_INCLUDED
  3. //////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2002-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. //////////////////////////////////////////////////////////////////////////////
  15. template< class Event, class Destination,
  16. class TransitionContext = detail::no_context< Event >,
  17. void ( TransitionContext::*pTransitionAction )( const Event & ) =
  18. &detail::no_context< Event >::no_function >
  19. class transition
  20. {
  21. private:
  22. //////////////////////////////////////////////////////////////////////////
  23. template< class State >
  24. struct reactions
  25. {
  26. static result react_without_action( State & stt )
  27. {
  28. return stt.template transit< Destination >();
  29. }
  30. static result react_with_action( State & stt, const Event & evt )
  31. {
  32. return stt.template transit< Destination >( pTransitionAction, evt );
  33. }
  34. };
  35. public:
  36. //////////////////////////////////////////////////////////////////////////
  37. // The following declarations should be private.
  38. // They are only public because many compilers lack template friends.
  39. //////////////////////////////////////////////////////////////////////////
  40. template< class State, class EventBase, class IdType >
  41. static detail::reaction_result react(
  42. State & stt, const EventBase & evt, const IdType & eventType )
  43. {
  44. typedef detail::reaction_dispatcher<
  45. reactions< State >, State, EventBase, Event, TransitionContext, IdType
  46. > dispatcher;
  47. return dispatcher::react( stt, evt, eventType );
  48. }
  49. };
  50. } // namespace statechart
  51. } // namespace boost
  52. #endif