Chris@16
|
1 #ifndef BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED
|
Chris@16
|
2 #define BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED
|
Chris@16
|
3 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
4 // Copyright 2005-2008 Andreas Huber Doenni
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See accompany-
|
Chris@16
|
6 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
8
|
Chris@16
|
9
|
Chris@16
|
10
|
Chris@16
|
11 #include <boost/statechart/result.hpp>
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/statechart/detail/reaction_dispatcher.hpp>
|
Chris@16
|
14
|
Chris@16
|
15
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost
|
Chris@16
|
18 {
|
Chris@16
|
19 namespace statechart
|
Chris@16
|
20 {
|
Chris@16
|
21
|
Chris@16
|
22
|
Chris@16
|
23
|
Chris@16
|
24 class event_base;
|
Chris@16
|
25
|
Chris@16
|
26 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
27 template< class Event,
|
Chris@16
|
28 class ReactionContext = detail::no_context< Event >,
|
Chris@16
|
29 void ( ReactionContext::*pAction )( const Event & ) =
|
Chris@16
|
30 &detail::no_context< Event >::no_function >
|
Chris@16
|
31 class in_state_reaction
|
Chris@16
|
32 {
|
Chris@16
|
33 private:
|
Chris@16
|
34 //////////////////////////////////////////////////////////////////////////
|
Chris@16
|
35 template< class State >
|
Chris@16
|
36 struct reactions
|
Chris@16
|
37 {
|
Chris@16
|
38 static result react_without_action( State & stt )
|
Chris@16
|
39 {
|
Chris@16
|
40 return stt.discard_event();
|
Chris@16
|
41 }
|
Chris@16
|
42
|
Chris@16
|
43 static result react_with_action( State & stt, const Event & evt )
|
Chris@16
|
44 {
|
Chris@16
|
45 ( stt.template context< ReactionContext >().*pAction )( evt );
|
Chris@16
|
46 return react_without_action( stt );
|
Chris@16
|
47 }
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 public:
|
Chris@16
|
51 //////////////////////////////////////////////////////////////////////////
|
Chris@16
|
52 // The following declarations should be private.
|
Chris@16
|
53 // They are only public because many compilers lack template friends.
|
Chris@16
|
54 //////////////////////////////////////////////////////////////////////////
|
Chris@16
|
55 template< class State, class EventBase, class IdType >
|
Chris@16
|
56 static detail::reaction_result react(
|
Chris@16
|
57 State & stt, const EventBase & evt, const IdType & eventType )
|
Chris@16
|
58 {
|
Chris@16
|
59 typedef detail::reaction_dispatcher<
|
Chris@16
|
60 reactions< State >, State, EventBase, Event, ReactionContext, IdType
|
Chris@16
|
61 > dispatcher;
|
Chris@16
|
62 return dispatcher::react( stt, evt, eventType );
|
Chris@16
|
63 }
|
Chris@16
|
64 };
|
Chris@16
|
65
|
Chris@16
|
66
|
Chris@16
|
67
|
Chris@16
|
68 } // namespace statechart
|
Chris@16
|
69 } // namespace boost
|
Chris@16
|
70
|
Chris@16
|
71
|
Chris@16
|
72
|
Chris@16
|
73 #endif
|