-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatemachine-2.0.cpp
35 lines (31 loc) · 1.12 KB
/
statemachine-2.0.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
#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;
struct firstState;
struct secondState;
struct statemachine : sc::state_machine<statemachine, firstState> {};
struct event_MoveToSecondState : sc::event<event_MoveToSecondState> {};
struct event_MoveToFirstState : sc::event<event_MoveToFirstState> {};
struct firstState : sc::simple_state<firstState, statemachine>
{
firstState() { cout << "In State => firstState" << endl; }
typedef sc::transition<event_MoveToSecondState, secondState> reactions;
};
struct secondState : sc::simple_state<secondState, statemachine>
{
secondState() { cout << "In State => secondState" << endl; }
typedef sc::transition<event_MoveToFirstState, firstState> reactions;
};
int main() {
statemachine sm;
sm.initiate();
sm.process_event(event_MoveToSecondState());
sm.process_event(event_MoveToFirstState());
sm.process_event(event_MoveToSecondState());
return 0;
}