custom_reaction.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef BOOST_STATECHART_CUSTOM_REACTION_HPP_INCLUDED
  2. #define BOOST_STATECHART_CUSTOM_REACTION_HPP_INCLUDED
  3. //////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2002-2006 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/polymorphic_cast.hpp> // boost::polymorphic_downcast
  10. namespace boost
  11. {
  12. namespace statechart
  13. {
  14. class event_base;
  15. //////////////////////////////////////////////////////////////////////////////
  16. template< class Event >
  17. class custom_reaction
  18. {
  19. public:
  20. //////////////////////////////////////////////////////////////////////////
  21. // The following declarations should be private.
  22. // They are only public because many compilers lack template friends.
  23. //////////////////////////////////////////////////////////////////////////
  24. template< class State, class EventBase, class IdType >
  25. static detail::reaction_result react(
  26. State & stt, const EventBase & evt, const IdType & eventType )
  27. {
  28. if ( eventType == Event::static_type() )
  29. {
  30. return detail::result_utility::get_result(
  31. stt.react( *polymorphic_downcast< const Event * >( &evt ) ) );
  32. }
  33. else
  34. {
  35. return detail::no_reaction;
  36. }
  37. }
  38. };
  39. template<>
  40. class custom_reaction< event_base >
  41. {
  42. public:
  43. //////////////////////////////////////////////////////////////////////////
  44. // The following declarations should be private.
  45. // They are only public because many compilers lack template friends.
  46. //////////////////////////////////////////////////////////////////////////
  47. template< class State, class EventBase, class IdType >
  48. static detail::reaction_result react(
  49. State & stt, const EventBase & evt, const IdType & )
  50. {
  51. return detail::result_utility::get_result( stt.react( evt ) );
  52. }
  53. };
  54. } // namespace statechart
  55. } // namespace boost
  56. #endif