]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/msm/doc/PDF/examples/distributed_table/DistributedTable.cpp
1 // Copyright 2010 Christophe Henry
2 // henry UNDERSCORE christophe AT hotmail DOT com
3 // This is an extended version of the state machine available in the boost::mpl library
4 // Distributed under the same license as the original.
5 // Copyright for the original version:
6 // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
7 // under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
14 #include <boost/msm/back/state_machine.hpp>
16 #include <boost/msm/front/state_machine_def.hpp>
18 #include <boost/msm/front/functor_row.hpp>
19 #include <boost/msm/front/euml/common.hpp>
25 namespace msm
= boost::msm
;
26 namespace mpl
= boost::mpl
;
27 using namespace msm::front
;
30 // front-end: define the FSM structure
31 struct player_
: public msm::front::state_machine_def
<player_
>
33 // the initial state of the player SM. Must be defined
34 typedef Empty initial_state
;
35 typedef mpl::vector
<Empty
,Open
> explicit_creation
;
37 typedef player_ p
; // makes transition table cleaner
39 // Replaces the default no-transition response.
40 template <class FSM
,class Event
>
41 void no_transition(Event
const& e
, FSM
&,int state
)
43 std::cout
<< "no transition from state " << state
44 << " on event " << typeid(e
).name() << std::endl
;
48 typedef msm::back::state_machine
<player_
> player
;
53 static char const* const state_names
[] = { "Empty", "Open" };
54 void pstate(player
const& p
)
56 std::cout
<< " -> " << state_names
[p
.current_state()[0]] << std::endl
;
62 // needed to start the highest-level SM. This will call on_entry and mark the start of the SM
64 // go to Open, call on_exit on Empty, then action, then on_entry on Open
65 p
.process_event(open_close()); pstate(p
);
66 p
.process_event(open_close()); pstate(p
);