1 #ifndef BOOST_STATECHART_REACTION_DISPATCHER_HPP_INCLUDED
2 #define BOOST_STATECHART_REACTION_DISPATCHER_HPP_INCLUDED
3 //////////////////////////////////////////////////////////////////////////////
4 // Copyright 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 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/statechart/result.hpp>
13 #include <boost/mpl/if.hpp>
15 #include <boost/polymorphic_cast.hpp> // boost::polymorphic_downcast
16 #include <boost/type_traits/is_same.hpp>
29 //////////////////////////////////////////////////////////////////////////////
30 template< class Event >
33 void no_function( const Event & );
36 //////////////////////////////////////////////////////////////////////////////
38 class Reactions, class State, class EventBase, class Event,
39 class ActionContext, class IdType >
40 class reaction_dispatcher
45 static result react( State & stt, const EventBase & )
47 return Reactions::react_without_action( stt );
51 struct base_with_action
53 static result react( State & stt, const EventBase & evt )
55 return Reactions::react_with_action( stt, evt );
62 State & stt, const EventBase & evt, const IdType & )
64 typedef typename mpl::if_<
65 is_same< ActionContext, detail::no_context< Event > >,
66 without_action, base_with_action
68 return reaction::react( stt, evt );
72 struct derived_with_action
74 static result react( State & stt, const EventBase & evt )
76 return Reactions::react_with_action(
77 stt, *polymorphic_downcast< const Event * >( &evt ) );
84 State & stt, const EventBase & evt, const IdType & eventType )
86 if ( eventType == Event::static_type() )
88 typedef typename mpl::if_<
89 is_same< ActionContext, detail::no_context< Event > >,
90 without_action, derived_with_action
92 return reaction::react( stt, evt );
96 return detail::result_utility::make_result( detail::no_reaction );
102 static reaction_result react(
103 State & stt, const EventBase & evt, const IdType & eventType )
105 typedef typename mpl::if_<
106 is_same< Event, EventBase >, base, derived
108 return result_utility::get_result(
109 reaction::react( stt, evt, eventType ) );
115 } // namespace detail
116 } // namespace statechart