2 #ifndef BOOST_FSM_STATE_MACHINE_INCLUDED
3 #define BOOST_FSM_STATE_MACHINE_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 "aux_/event.hpp"
18 #include "aux_/state.hpp"
19 #include "aux_/transition.hpp"
20 #include "aux_/STT_impl_gen.hpp"
21 #include <boost/shared_ptr.hpp>
29 template< typename Derived >
33 typedef state_machine self_t;
34 typedef aux::base_event base_event_t;
35 typedef boost::shared_ptr<base_event_t const> base_event_ptr_t;
39 typedef void (Derived::* invariant_func_t)() const;
41 template< typename DerivedEvent >
43 : aux::event<DerivedEvent>
47 void process_event(base_event_t const& evt)
49 // all internal events should be handled at this point
50 assert(!m_events_queue.size());
52 // process the external event passed
55 // if the previous transition generated any internal events,
57 while (m_events_queue.size())
59 do_transition(*m_events_queue.front());
64 state_t current_state() const
70 // interface for the derived class
72 state_machine(state_t const& initial_state)
73 : m_state(initial_state)
78 : m_state(typename Derived::initial_state())
82 virtual ~state_machine()
86 void post_event(std::auto_ptr<base_event_t const> evt)
88 m_events_queue.push(base_event_ptr_t(evt.release()));
93 #if !defined(BOOST_INTEL_CXX_VERSION) && (!defined(__GNUC__) || __GNUC__ >= 3)
94 , invariant_func_t f = static_cast<invariant_func_t>(0)
96 , invariant_func_t f = 0
100 : fsm::aux::state<Derived,State,f>
108 , bool (Derived::* transition_func)(Event const&)
111 : aux::transition< Derived,From,Event,To,transition_func >
117 void do_transition(base_event_t const& evt)
119 typedef typename Derived::transition_table STT_;
120 typedef typename aux::STT_impl_gen< STT_ >::type STT_impl_;
122 m_state = STT_impl_::do_transition(
123 static_cast<Derived&>(*this)
130 std::queue< base_event_ptr_t > m_events_queue;
135 #endif // BOOST_FSM_STATE_MACHINE_INCLUDED