1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/statechart/transition.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,148 @@
1.4 +#ifndef BOOST_STATECHART_TRANSITION_HPP_INCLUDED
1.5 +#define BOOST_STATECHART_TRANSITION_HPP_INCLUDED
1.6 +//////////////////////////////////////////////////////////////////////////////
1.7 +// Copyright 2002-2006 Andreas Huber Doenni
1.8 +// Distributed under the Boost Software License, Version 1.0. (See accompany-
1.9 +// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.10 +//////////////////////////////////////////////////////////////////////////////
1.11 +
1.12 +
1.13 +
1.14 +#include <boost/statechart/result.hpp>
1.15 +
1.16 +#include <boost/mpl/if.hpp>
1.17 +
1.18 +#include <boost/cast.hpp> // boost::polymorphic_downcast
1.19 +#include <boost/type_traits/is_same.hpp>
1.20 +
1.21 +
1.22 +
1.23 +namespace boost
1.24 +{
1.25 +namespace statechart
1.26 +{
1.27 +namespace detail
1.28 +{
1.29 +
1.30 +
1.31 +
1.32 +//////////////////////////////////////////////////////////////////////////////
1.33 +template< class Event >
1.34 +struct no_context
1.35 +{
1.36 + void no_function( const Event & );
1.37 +};
1.38 +
1.39 +
1.40 +
1.41 +} // namespace detail
1.42 +
1.43 +
1.44 +
1.45 +class event_base;
1.46 +
1.47 +//////////////////////////////////////////////////////////////////////////////
1.48 +template< class Event, class Destination,
1.49 + class TransitionContext = detail::no_context< Event >,
1.50 + void ( TransitionContext::*pTransitionAction )( const Event & ) =
1.51 + &detail::no_context< Event >::no_function >
1.52 +class transition
1.53 +{
1.54 + private:
1.55 + //////////////////////////////////////////////////////////////////////////
1.56 + struct react_without_transition_action_impl
1.57 + {
1.58 + template< class State, class EventBase >
1.59 + static detail::reaction_result react( State & stt, const EventBase & )
1.60 + {
1.61 + return detail::result_utility::get_result(
1.62 + stt.template transit< Destination >() );
1.63 + }
1.64 + };
1.65 +
1.66 + struct react_base_with_transition_action_impl
1.67 + {
1.68 + template< class State, class EventBase >
1.69 + static detail::reaction_result react(
1.70 + State & stt, const EventBase & toEvent )
1.71 + {
1.72 + return detail::result_utility::get_result(
1.73 + stt.template transit< Destination >( pTransitionAction, toEvent ) );
1.74 + }
1.75 + };
1.76 +
1.77 + struct react_base
1.78 + {
1.79 + template< class State, class EventBase, class IdType >
1.80 + static detail::reaction_result react(
1.81 + State & stt, const EventBase & evt, const IdType & )
1.82 + {
1.83 + typedef typename mpl::if_<
1.84 + is_same< TransitionContext, detail::no_context< Event > >,
1.85 + react_without_transition_action_impl,
1.86 + react_base_with_transition_action_impl
1.87 + >::type impl;
1.88 + return impl::react( stt, evt );
1.89 + }
1.90 + };
1.91 +
1.92 + struct react_derived_with_transition_action_impl
1.93 + {
1.94 + template< class State, class EventBase >
1.95 + static detail::reaction_result react(
1.96 + State & stt, const EventBase & toEvent )
1.97 + {
1.98 + return detail::result_utility::get_result(
1.99 + stt.template transit< Destination >(
1.100 + pTransitionAction,
1.101 + *polymorphic_downcast< const Event * >( &toEvent ) ) );
1.102 + }
1.103 + };
1.104 +
1.105 + struct react_derived
1.106 + {
1.107 + template< class State, class EventBase, class IdType >
1.108 + static detail::reaction_result react(
1.109 + State & stt, const EventBase & evt, const IdType & eventType )
1.110 + {
1.111 + if ( eventType == Event::static_type() )
1.112 + {
1.113 + typedef typename mpl::if_<
1.114 + is_same< TransitionContext, detail::no_context< Event > >,
1.115 + react_without_transition_action_impl,
1.116 + react_derived_with_transition_action_impl
1.117 + >::type impl;
1.118 + return impl::react( stt, evt );
1.119 + }
1.120 + else
1.121 + {
1.122 + return detail::no_reaction;
1.123 + }
1.124 + }
1.125 + };
1.126 +
1.127 + public:
1.128 + //////////////////////////////////////////////////////////////////////////
1.129 + // The following declarations should be private.
1.130 + // They are only public because many compilers lack template friends.
1.131 + //////////////////////////////////////////////////////////////////////////
1.132 + template< class State, class EventBase, class IdType >
1.133 + static detail::reaction_result react(
1.134 + State & stt, const EventBase & evt, const IdType & eventType )
1.135 + {
1.136 + typedef typename mpl::if_<
1.137 + is_same< Event, event_base >, react_base, react_derived
1.138 + >::type impl;
1.139 +
1.140 + return impl::react( stt, evt, eventType );
1.141 + }
1.142 +};
1.143 +
1.144 +
1.145 +
1.146 +} // namespace statechart
1.147 +} // namespace boost
1.148 +
1.149 +
1.150 +
1.151 +#endif