-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
57 lines (46 loc) · 1.59 KB
/
main.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
57
#include <iostream>
#include <memory>
#include <map>
#include <string>
#include "StateMachineManager.h"
using namespace std;
bool mfg_to_registered() {
std::cout << "Transition from mfg to registered" << std::endl;
return true;
}
bool registered_to_associated() {
std::cout << "Transition from registered to associated" << std::endl;
return true;
}
bool associated_to_mfg() {
std::cout << "Transition from associated to manufactured" << std::endl;
return true;
}
int main() {
std::cout << "Hello, World!" << std::endl;
StateMachineManager mgr("StateMachine");
mgr.addState("MANUFACTURED",
{ nodeInitializer{"REGISTERED", mfg_to_registered} });
mgr.addState("REGISTERED",
{ nodeInitializer{"USER_ASSOCIATED", registered_to_associated}});
mgr.addState("USER_ASSOCIATED",
{ nodeInitializer{"MANUFACTURED", associated_to_mfg}});
if (mgr.setState("MANUFACTURED")) {
std::cout << "State is manufactured" << std::endl;
if (mgr.setState("USER_ASSOCIATED")) {
std::cout << "Should not be possible" << std::endl;
} else {
std::cout << "State is " << mgr.getState() << std::endl;
}
if (mgr.setState("REGISTERED")) {
std::cout << "Transitioned to registered" << std::endl;
}
if (mgr.setState("USER_ASSOCIATED")) {
std::cout << "Transitioned to associated" << std::endl;
}
if (mgr.setState("REGISTERED")) {
std::cout << "Transitioned to registered" << std::endl;
}
}
return 0;
}