]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpl/example/fsm/player.cpp
2 // Copyright Aleksey Gurtovoy 2002-2004
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/mpl for documentation.
14 #include "state_machine.hpp"
15 #include <boost/mpl/list.hpp>
19 namespace mpl
= boost::mpl
;
22 : public fsm::state_machine
<player
>
28 struct play_event
: event
<play_event
> {};
29 struct stop_event
: event
<stop_event
> {};
30 struct pause_event
: event
<pause_event
> {};
32 // MWCW 8.1 is too eager in inforcing access for non-type template parameters
34 typedef player self_t
;
37 void stopped_state_invariant() const {}
38 void playing_state_invariant() const {}
39 void paused_state_invariant() const {}
41 // states (invariants are passed as non-type template arguments)
42 typedef state
<0, &self_t::stopped_state_invariant
> stopped
;
43 typedef state
<1, &self_t::playing_state_invariant
> playing
;
44 typedef state
<2, &self_t::paused_state_invariant
> paused
;
48 // transition functions
49 bool do_play(play_event
const&) { std::cout
<< "player::do_play\n"; return true; }
50 bool do_stop(stop_event
const&) { std::cout
<< "player::do_stop\n"; return true; }
51 bool do_pause(pause_event
const&) { std::cout
<< "player::do_pause\n"; return true; }
52 bool do_resume(play_event
const&) { std::cout
<< "player::do_resume\n"; return true; }
54 // transitions, in the following format:
55 // | current state | event | next state | transition function |
56 friend class fsm::state_machine
<player
>;
58 transition
<stopped
, play_event
, playing
, &player::do_play
>
59 , transition
<playing
, stop_event
, stopped
, &player::do_stop
>
60 , transition
<playing
, pause_event
, paused
, &player::do_pause
>
61 , transition
<paused
, play_event
, playing
, &player::do_resume
>
62 , transition
<paused
, stop_event
, stopped
, &player::do_stop
>
63 >::type transition_table
;
65 typedef stopped initial_state
;
71 p
.process_event(player::play_event());
72 p
.process_event(player::pause_event());
73 p
.process_event(player::play_event());
74 p
.process_event(player::stop_event());