2 #ifndef BOOST_FSM_HANDLER_INCLUDED
3 #define BOOST_FSM_HANDLER_INCLUDED
5 // Copyright Aleksey Gurtovoy 2002-2004
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 // See http://www.boost.org/libs/mpl for documentation.
17 #include <boost/mpl/if.hpp>
18 #include <boost/mpl/fold.hpp>
19 #include <boost/mpl/front.hpp>
20 #include <boost/type_traits/is_same.hpp>
25 namespace fsm { namespace aux {
27 namespace mpl = boost::mpl;
28 using namespace mpl::placeholders;
30 template< typename Transition >
31 struct STT_void_row_impl
33 typedef typename Transition::from_state_t state_t;
34 typedef typename Transition::fsm_t fsm_t;
35 typedef typename Transition::base_event_t base_event_t;
37 static long do_process_event(fsm_t&, long state, base_event_t const&)
43 static long do_transition(fsm_t&, long state, base_event_t const&)
55 struct STT_event_row_impl
58 typedef typename Transition::from_state_t state_t;
59 typedef typename Transition::fsm_t fsm_t;
60 typedef typename Transition::base_event_t base_event_t;
62 static long do_process_event(fsm_t& fsm, long state, base_event_t const& evt)
64 if (typeid(typename Transition::event_t) == typeid(evt))
66 // typedefs are here to make GCC happy
67 typedef typename Transition::to_state_t to_state_;
68 typedef typename Transition::from_state_t from_state_;
70 return Transition::do_transition(fsm, evt)
71 ? to_state_::do_check_invariant(fsm)
72 : from_state_::do_check_invariant(fsm)
76 return PrevRowImpl::do_process_event(fsm, state, evt);
84 struct STT_state_row_impl
87 typedef typename PrevRowImpl::fsm_t fsm_t;
88 typedef typename PrevRowImpl::base_event_t base_event_t;
90 static long do_transition(fsm_t& fsm, long state, base_event_t const& evt)
92 return state == StateType::value
93 ? PrevRowImpl::do_process_event(fsm, state, evt)
94 : PrevRowImpl::do_transition(fsm, state, evt)
98 static long do_process_event(fsm_t&, long state, base_event_t const&)
107 , typename Transition
111 typedef typename mpl::if_<
113 typename PrevRowImpl::state_t
114 , typename Transition::from_state_t
116 , STT_event_row_impl< PrevRowImpl,Transition >
117 , STT_event_row_impl<
118 STT_state_row_impl< PrevRowImpl,typename PrevRowImpl::state_t >
125 template< typename Transitions >
129 typedef typename mpl::front<Transitions>::type first_;
130 typedef typename mpl::fold<
132 , STT_void_row_impl<first_>
137 typedef STT_state_row_impl<
139 , typename STT_impl_::state_t
145 #endif // BOOST_FSM_HANDLER_INCLUDED