sl@0
|
1 |
#ifndef BOOST_STATECHART_TRANSITION_HPP_INCLUDED
|
sl@0
|
2 |
#define BOOST_STATECHART_TRANSITION_HPP_INCLUDED
|
sl@0
|
3 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
4 |
// Copyright 2002-2006 Andreas Huber Doenni
|
sl@0
|
5 |
// Distributed under the Boost Software License, Version 1.0. (See accompany-
|
sl@0
|
6 |
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
7 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
8 |
|
sl@0
|
9 |
|
sl@0
|
10 |
|
sl@0
|
11 |
#include <boost/statechart/result.hpp>
|
sl@0
|
12 |
|
sl@0
|
13 |
#include <boost/mpl/if.hpp>
|
sl@0
|
14 |
|
sl@0
|
15 |
#include <boost/cast.hpp> // boost::polymorphic_downcast
|
sl@0
|
16 |
#include <boost/type_traits/is_same.hpp>
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
namespace boost
|
sl@0
|
21 |
{
|
sl@0
|
22 |
namespace statechart
|
sl@0
|
23 |
{
|
sl@0
|
24 |
namespace detail
|
sl@0
|
25 |
{
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
30 |
template< class Event >
|
sl@0
|
31 |
struct no_context
|
sl@0
|
32 |
{
|
sl@0
|
33 |
void no_function( const Event & );
|
sl@0
|
34 |
};
|
sl@0
|
35 |
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
} // namespace detail
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
|
sl@0
|
42 |
class event_base;
|
sl@0
|
43 |
|
sl@0
|
44 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
45 |
template< class Event, class Destination,
|
sl@0
|
46 |
class TransitionContext = detail::no_context< Event >,
|
sl@0
|
47 |
void ( TransitionContext::*pTransitionAction )( const Event & ) =
|
sl@0
|
48 |
&detail::no_context< Event >::no_function >
|
sl@0
|
49 |
class transition
|
sl@0
|
50 |
{
|
sl@0
|
51 |
private:
|
sl@0
|
52 |
//////////////////////////////////////////////////////////////////////////
|
sl@0
|
53 |
struct react_without_transition_action_impl
|
sl@0
|
54 |
{
|
sl@0
|
55 |
template< class State, class EventBase >
|
sl@0
|
56 |
static detail::reaction_result react( State & stt, const EventBase & )
|
sl@0
|
57 |
{
|
sl@0
|
58 |
return detail::result_utility::get_result(
|
sl@0
|
59 |
stt.template transit< Destination >() );
|
sl@0
|
60 |
}
|
sl@0
|
61 |
};
|
sl@0
|
62 |
|
sl@0
|
63 |
struct react_base_with_transition_action_impl
|
sl@0
|
64 |
{
|
sl@0
|
65 |
template< class State, class EventBase >
|
sl@0
|
66 |
static detail::reaction_result react(
|
sl@0
|
67 |
State & stt, const EventBase & toEvent )
|
sl@0
|
68 |
{
|
sl@0
|
69 |
return detail::result_utility::get_result(
|
sl@0
|
70 |
stt.template transit< Destination >( pTransitionAction, toEvent ) );
|
sl@0
|
71 |
}
|
sl@0
|
72 |
};
|
sl@0
|
73 |
|
sl@0
|
74 |
struct react_base
|
sl@0
|
75 |
{
|
sl@0
|
76 |
template< class State, class EventBase, class IdType >
|
sl@0
|
77 |
static detail::reaction_result react(
|
sl@0
|
78 |
State & stt, const EventBase & evt, const IdType & )
|
sl@0
|
79 |
{
|
sl@0
|
80 |
typedef typename mpl::if_<
|
sl@0
|
81 |
is_same< TransitionContext, detail::no_context< Event > >,
|
sl@0
|
82 |
react_without_transition_action_impl,
|
sl@0
|
83 |
react_base_with_transition_action_impl
|
sl@0
|
84 |
>::type impl;
|
sl@0
|
85 |
return impl::react( stt, evt );
|
sl@0
|
86 |
}
|
sl@0
|
87 |
};
|
sl@0
|
88 |
|
sl@0
|
89 |
struct react_derived_with_transition_action_impl
|
sl@0
|
90 |
{
|
sl@0
|
91 |
template< class State, class EventBase >
|
sl@0
|
92 |
static detail::reaction_result react(
|
sl@0
|
93 |
State & stt, const EventBase & toEvent )
|
sl@0
|
94 |
{
|
sl@0
|
95 |
return detail::result_utility::get_result(
|
sl@0
|
96 |
stt.template transit< Destination >(
|
sl@0
|
97 |
pTransitionAction,
|
sl@0
|
98 |
*polymorphic_downcast< const Event * >( &toEvent ) ) );
|
sl@0
|
99 |
}
|
sl@0
|
100 |
};
|
sl@0
|
101 |
|
sl@0
|
102 |
struct react_derived
|
sl@0
|
103 |
{
|
sl@0
|
104 |
template< class State, class EventBase, class IdType >
|
sl@0
|
105 |
static detail::reaction_result react(
|
sl@0
|
106 |
State & stt, const EventBase & evt, const IdType & eventType )
|
sl@0
|
107 |
{
|
sl@0
|
108 |
if ( eventType == Event::static_type() )
|
sl@0
|
109 |
{
|
sl@0
|
110 |
typedef typename mpl::if_<
|
sl@0
|
111 |
is_same< TransitionContext, detail::no_context< Event > >,
|
sl@0
|
112 |
react_without_transition_action_impl,
|
sl@0
|
113 |
react_derived_with_transition_action_impl
|
sl@0
|
114 |
>::type impl;
|
sl@0
|
115 |
return impl::react( stt, evt );
|
sl@0
|
116 |
}
|
sl@0
|
117 |
else
|
sl@0
|
118 |
{
|
sl@0
|
119 |
return detail::no_reaction;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
}
|
sl@0
|
122 |
};
|
sl@0
|
123 |
|
sl@0
|
124 |
public:
|
sl@0
|
125 |
//////////////////////////////////////////////////////////////////////////
|
sl@0
|
126 |
// The following declarations should be private.
|
sl@0
|
127 |
// They are only public because many compilers lack template friends.
|
sl@0
|
128 |
//////////////////////////////////////////////////////////////////////////
|
sl@0
|
129 |
template< class State, class EventBase, class IdType >
|
sl@0
|
130 |
static detail::reaction_result react(
|
sl@0
|
131 |
State & stt, const EventBase & evt, const IdType & eventType )
|
sl@0
|
132 |
{
|
sl@0
|
133 |
typedef typename mpl::if_<
|
sl@0
|
134 |
is_same< Event, event_base >, react_base, react_derived
|
sl@0
|
135 |
>::type impl;
|
sl@0
|
136 |
|
sl@0
|
137 |
return impl::react( stt, evt, eventType );
|
sl@0
|
138 |
}
|
sl@0
|
139 |
};
|
sl@0
|
140 |
|
sl@0
|
141 |
|
sl@0
|
142 |
|
sl@0
|
143 |
} // namespace statechart
|
sl@0
|
144 |
} // namespace boost
|
sl@0
|
145 |
|
sl@0
|
146 |
|
sl@0
|
147 |
|
sl@0
|
148 |
#endif
|