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