Improve vacpp support.
[boost.git] / boost / boost / statechart / transition.hpp
blob0cad99d027dee78180b9b2c279f955aaeba36955
1 #ifndef BOOST_STATECHART_TRANSITION_HPP_INCLUDED
2 #define BOOST_STATECHART_TRANSITION_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 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/statechart/result.hpp>
13 #include <boost/mpl/if.hpp>
15 #include <boost/cast.hpp> // boost::polymorphic_downcast
16 #include <boost/type_traits/is_same.hpp>
20 namespace boost
22 namespace statechart
24 namespace detail
29 //////////////////////////////////////////////////////////////////////////////
30 template< class Event >
31 struct no_context
33 void no_function( const Event & );
38 } // namespace detail
42 class event_base;
44 //////////////////////////////////////////////////////////////////////////////
45 template< class Event, class Destination,
46 class TransitionContext = detail::no_context< Event >,
47 void ( TransitionContext::*pTransitionAction )( const Event & ) =
48 &detail::no_context< Event >::no_function >
49 class transition
51 private:
52 //////////////////////////////////////////////////////////////////////////
53 struct react_without_transition_action_impl
55 template< class State, class EventBase >
56 static detail::reaction_result react( State & stt, const EventBase & )
58 return detail::result_utility::get_result(
59 stt.template transit< Destination >() );
63 struct react_base_with_transition_action_impl
65 template< class State, class EventBase >
66 static detail::reaction_result react(
67 State & stt, const EventBase & toEvent )
69 return detail::result_utility::get_result(
70 stt.template transit< Destination >( pTransitionAction, toEvent ) );
74 struct react_base
76 template< class State, class EventBase, class IdType >
77 static detail::reaction_result react(
78 State & stt, const EventBase & evt, const IdType & )
80 typedef typename mpl::if_<
81 is_same< TransitionContext, detail::no_context< Event > >,
82 react_without_transition_action_impl,
83 react_base_with_transition_action_impl
84 >::type impl;
85 return impl::react( stt, evt );
89 struct react_derived_with_transition_action_impl
91 template< class State, class EventBase >
92 static detail::reaction_result react(
93 State & stt, const EventBase & toEvent )
95 return detail::result_utility::get_result(
96 stt.template transit< Destination >(
97 pTransitionAction,
98 *polymorphic_downcast< const Event * >( &toEvent ) ) );
102 struct react_derived
104 template< class State, class EventBase, class IdType >
105 static detail::reaction_result react(
106 State & stt, const EventBase & evt, const IdType & eventType )
108 if ( eventType == Event::static_type() )
110 typedef typename mpl::if_<
111 is_same< TransitionContext, detail::no_context< Event > >,
112 react_without_transition_action_impl,
113 react_derived_with_transition_action_impl
114 >::type impl;
115 return impl::react( stt, evt );
117 else
119 return detail::no_reaction;
124 public:
125 //////////////////////////////////////////////////////////////////////////
126 // The following declarations should be private.
127 // They are only public because many compilers lack template friends.
128 //////////////////////////////////////////////////////////////////////////
129 template< class State, class EventBase, class IdType >
130 static detail::reaction_result react(
131 State & stt, const EventBase & evt, const IdType & eventType )
133 typedef typename mpl::if_<
134 is_same< Event, event_base >, react_base, react_derived
135 >::type impl;
137 return impl::react( stt, evt, eventType );
143 } // namespace statechart
144 } // namespace boost
148 #endif