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 9 10 11 #include <boost/statechart/result.hpp> 12 13 #include <boost/polymorphic_cast.hpp> // boost::polymorphic_downcast 14 15 16 17 namespace boost 18 { 19 namespace statechart 20 { 21 22 23 24 class event_base; 25 26 ////////////////////////////////////////////////////////////////////////////// 27 template< class Event > 28 class custom_reaction 29 { 30 public: 31 ////////////////////////////////////////////////////////////////////////// 32 // The following declarations should be private. 33 // They are only public because many compilers lack template friends. 34 ////////////////////////////////////////////////////////////////////////// 35 template< class State, class EventBase, class IdType > react(State & stt,const EventBase & evt,const IdType & eventType)36 static detail::reaction_result react( 37 State & stt, const EventBase & evt, const IdType & eventType ) 38 { 39 if ( eventType == Event::static_type() ) 40 { 41 return detail::result_utility::get_result( 42 stt.react( *polymorphic_downcast< const Event * >( &evt ) ) ); 43 } 44 else 45 { 46 return detail::no_reaction; 47 } 48 } 49 }; 50 51 template<> 52 class custom_reaction< event_base > 53 { 54 public: 55 ////////////////////////////////////////////////////////////////////////// 56 // The following declarations should be private. 57 // They are only public because many compilers lack template friends. 58 ////////////////////////////////////////////////////////////////////////// 59 template< class State, class EventBase, class IdType > react(State & stt,const EventBase & evt,const IdType &)60 static detail::reaction_result react( 61 State & stt, const EventBase & evt, const IdType & ) 62 { 63 return detail::result_utility::get_result( stt.react( evt ) ); 64 } 65 }; 66 67 68 69 } // namespace statechart 70 } // namespace boost 71 72 73 74 #endif 75