Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:31

0001 #ifndef BOOST_STATECHART_REACTION_DISPATCHER_HPP_INCLUDED
0002 #define BOOST_STATECHART_REACTION_DISPATCHER_HPP_INCLUDED
0003 //////////////////////////////////////////////////////////////////////////////
0004 // Copyright 2008 Andreas Huber Doenni
0005 // Distributed under the Boost Software License, Version 1.0. (See accompany-
0006 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 //////////////////////////////////////////////////////////////////////////////
0008 
0009 
0010 
0011 #include <boost/statechart/result.hpp>
0012 
0013 #include <boost/mpl/if.hpp>
0014 
0015 #include <boost/polymorphic_cast.hpp> // boost::polymorphic_downcast
0016 #include <boost/type_traits/is_same.hpp>
0017 
0018 
0019 
0020 namespace boost
0021 {
0022 namespace statechart
0023 {
0024 namespace detail
0025 {
0026 
0027 
0028 
0029 //////////////////////////////////////////////////////////////////////////////
0030 template< class Event >
0031 struct no_context
0032 {
0033   void no_function( const Event & );
0034 };
0035 
0036 //////////////////////////////////////////////////////////////////////////////
0037 template<
0038   class Reactions, class State, class EventBase, class Event,
0039   class ActionContext, class IdType >
0040 class reaction_dispatcher
0041 {
0042   private:
0043     struct without_action
0044     {
0045       static result react( State & stt, const EventBase & )
0046       {
0047         return Reactions::react_without_action( stt );
0048       }
0049     };
0050 
0051     struct base_with_action
0052     {
0053       static result react( State & stt, const EventBase & evt )
0054       {
0055         return Reactions::react_with_action( stt, evt );
0056       }
0057     };
0058 
0059     struct base
0060     {
0061       static result react(
0062         State & stt, const EventBase & evt, const IdType & )
0063       {
0064         typedef typename mpl::if_<
0065           is_same< ActionContext, detail::no_context< Event > >,
0066           without_action, base_with_action
0067         >::type reaction;
0068         return reaction::react( stt, evt );
0069       }
0070     };
0071 
0072     struct derived_with_action
0073     {
0074       static result react( State & stt, const EventBase & evt )
0075       {
0076         return Reactions::react_with_action(
0077           stt, *polymorphic_downcast< const Event * >( &evt ) );
0078       }
0079     };
0080 
0081     struct derived
0082     {
0083       static result react(
0084         State & stt, const EventBase & evt, const IdType & eventType )
0085       {
0086         if ( eventType == Event::static_type() )
0087         {
0088           typedef typename mpl::if_<
0089             is_same< ActionContext, detail::no_context< Event > >,
0090             without_action, derived_with_action
0091           >::type reaction;
0092           return reaction::react( stt, evt );
0093         }
0094         else
0095         {
0096           return detail::result_utility::make_result( detail::no_reaction );
0097         }
0098       }
0099     };
0100 
0101   public:
0102     static reaction_result react(
0103       State & stt, const EventBase & evt, const IdType & eventType )
0104     {
0105       typedef typename mpl::if_<
0106         is_same< Event, EventBase >, base, derived
0107       >::type reaction;
0108       return result_utility::get_result(
0109         reaction::react( stt, evt, eventType ) );
0110     }
0111 };
0112 
0113 
0114 
0115 } // namespace detail
0116 } // namespace statechart
0117 } // namespace boost
0118 
0119 
0120 
0121 #endif