Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/statechart/in_state_reaction.hpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.5 KB
Line 
1#ifndef BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED
2#define BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED
3//////////////////////////////////////////////////////////////////////////////
4// Copyright 2005-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/mpl/if.hpp>
14
15#include <boost/cast.hpp> // boost::polymorphic_downcast
16#include <boost/type_traits/is_same.hpp>
17
18
19
20namespace boost
21{
22namespace statechart
23{
24
25
26
27class event_base;
28
29//////////////////////////////////////////////////////////////////////////////
30template< class Event, 
31          class ReactionContext,
32          void ( ReactionContext::*pAction )( const Event & ) >
33class in_state_reaction
34{
35  private:
36    //////////////////////////////////////////////////////////////////////////
37    struct react_base
38    {
39      template< class State, class EventBase, class IdType >
40      static detail::reaction_result react(
41        State & stt, const EventBase & evt, const IdType & )
42      {
43        ( stt.template context< ReactionContext >().*pAction )( evt );
44        return detail::do_discard_event;
45      }
46    };
47
48    struct react_derived
49    {
50      template< class State, class EventBase, class IdType >
51      static detail::reaction_result react(
52        State & stt, const EventBase & evt, const IdType & eventType )
53      {
54        if ( eventType == Event::static_type() )
55        {
56          ( stt.template context< ReactionContext >().*pAction )(
57            *polymorphic_downcast< const Event * >( &evt ) );
58          return detail::do_discard_event;
59        }
60        else
61        {
62          return detail::no_reaction;
63        }
64      }
65    };
66
67  public:
68    //////////////////////////////////////////////////////////////////////////
69    // The following declarations should be private.
70    // They are only public because many compilers lack template friends.
71    //////////////////////////////////////////////////////////////////////////
72    template< class State, class EventBase, class IdType >
73    static detail::reaction_result react(
74      State & stt, const EventBase & evt, const IdType & eventType )
75    {
76      typedef typename mpl::if_<
77        is_same< Event, event_base >, react_base, react_derived
78      >::type impl;
79
80      return impl::react( stt, evt, eventType );
81    }
82};
83
84
85
86} // namespace statechart
87} // namespace boost
88
89
90
91#endif
Note: See TracBrowser for help on using the repository browser.