-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathstate_machine.cpp
56 lines (47 loc) · 1.43 KB
/
state_machine.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "../obfuscator.hpp"
#include <iostream>
#define STATE(Name) struct Name {};
#define EVENT(Name) struct Name {};
STATE(Final);
EVENT(Trigger);
STATE(state1); STATE(state2); STATE(state3); STATE(state4); STATE(state5);
EVENT(event1); EVENT(event2); EVENT(event3); EVENT(event4); EVENT(event5);
struct Action {
static bool trigged;
static void action() {
trigged = true;
std::cout << "Trigged" << std::endl;
}
};
bool Action::trigged = true;
struct Dummy {
static int dummy;
static void dummy1() {
dummy += 10;
std::cout << "Dummy1" << std::endl;
}
static void dummy2() {
dummy *= 20;
std::cout << "Dummy2" << std::endl;
}
static void dummy3() {
std::exit(1);
}
};
int Dummy::dummy = 0;
int main() {
using namespace obfs;
using machine = StateMachine<
Stage<state1, Next<event5 , state2, Dummy::dummy1>,
Next<event1 , state3, Dummy::dummy3>>,
Stage<state2, Next<event2 , state4>>,
Stage<state3, Next<None , state3>>,
Stage<state4, Next<event4 , state1>,
Next<event3 , state5, Dummy::dummy2>>,
Stage<state5, Next<Trigger, Final, Action::action>>>;
auto next1 = machine::run(state1{}, event5{});
auto next2 = machine::run(next1, event2{});
auto next3 = machine::run(next2, event3{});
auto next4 = machine::run(next3, Trigger{});
return 0;
}