-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatemachine-2.1.cpp
42 lines (37 loc) · 1.21 KB
/
statemachine-2.1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <boost/statechart/event.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/custom_reaction.hpp>
namespace sc = boost::statechart;
using namespace std;
namespace mpl = boost::mpl;
struct firstState;
struct secondState;
struct thirdState;
struct statemachine : sc::state_machine<statemachine, firstState> {};
struct event_MoveToSecondState : sc::event<event_MoveToSecondState> {};
struct event_MoveToThirdState : sc::event<event_MoveToThirdState> {};
struct firstState : sc::simple_state<firstState, statemachine>
{
firstState() { cout << "In State => firstState" << endl; }
typedef mpl::list<
sc::transition<event_MoveToSecondState, secondState>,
sc::transition<event_MoveToThirdState, thirdState>
> reactions;
};
struct secondState : sc::simple_state<secondState, statemachine>
{
secondState() { cout << "In State => secondState" << endl; }
};
struct thirdState : sc::simple_state<thirdState, statemachine>
{
thirdState() { cout << "In State => thirdState" << endl; }
};
int main() {
statemachine sm;
sm.initiate();
sm.process_event(event_MoveToThirdState());
return 0;
}