Skip to content

Commit 4729ec6

Browse files
committed
updated interface for state machine
1 parent 888d71b commit 4729ec6

File tree

14 files changed

+233
-177
lines changed

14 files changed

+233
-177
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,5 @@ Temporary Items
173173
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
174174
.cache/
175175
build/
176-
176+
.html/
177+
.latex/

include/concrete_state.hpp

Lines changed: 0 additions & 86 deletions
This file was deleted.

include/concrete_states.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#pragma once
2+
#include <print>
3+
#include "./state.hpp"
4+
5+
class UserInputState : public State {
6+
public:
7+
void enter() override;
8+
void handle() override;
9+
void exit() override;
10+
};
11+
12+
class ElfParserState : public State {
13+
public:
14+
void enter() override;
15+
void handle() override;
16+
void exit() override;
17+
};
18+
19+
class CallgraphState : public State {
20+
public:
21+
void enter() override;
22+
void handle() override;
23+
void exit() override;
24+
};
25+
26+
class AbiParserState : public State {
27+
public:
28+
void enter() override;
29+
void handle() override;
30+
void exit() override;
31+
};
32+
33+
class ValidatorState : public State {
34+
public:
35+
void enter() override;
36+
void handle() override;
37+
void exit() override;
38+
};
39+
40+
class OutputState : public State {
41+
public:
42+
void enter() override;
43+
void handle() override;
44+
void exit() override;
45+
};
46+
47+
class ErrorState : public State {
48+
public:
49+
void enter() override;
50+
void handle() override;
51+
void exit() override;
52+
};

include/safe.hpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

include/safe_state.hpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

include/state.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include "./state_context.hpp"
3+
4+
class StateContext;
5+
6+
class State {
7+
protected:
8+
StateContext *context;
9+
public:
10+
virtual void enter() = 0;
11+
virtual void handle() = 0;
12+
virtual void exit() = 0;
13+
14+
void set_context(StateContext *context);
15+
16+
virtual ~State() = 0;
17+
};

include/state_context.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include "./state.hpp"
3+
4+
class State;
5+
6+
class StateContext {
7+
public:
8+
StateContext(State *state);
9+
~StateContext();
10+
State* get_current_state();
11+
void run_state();
12+
void transition_state(State* new_state);
13+
private:
14+
State* current_state;
15+
int total_state;
16+
};
17+

src/concrete_state.cpp

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/concrete_states.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "../include/concrete_state.hpp"
2+
#include "../include/state.hpp"
3+
#include "../include/state_context.hpp"
4+
5+
//User Input
6+
void UserInputState::enter() {
7+
print("Enter User Input State\n");
8+
}
9+
10+
void UserInputState::handle() {
11+
print("Handle User Input State\n");
12+
}
13+
14+
void UserInputState::exit() {
15+
print("Exit User Input State\n-------------\n");
16+
this->contect->transition_state(new ElfParserState);
17+
}
18+
19+
//Elf Parser
20+
void ElfParserState::enter() {
21+
print("Enter Elf Parser State\n");
22+
}
23+
24+
void ElfParserState::handle() {
25+
print("Handle Elf Parser State\n");
26+
}
27+
28+
void ElfParserState::exit() {
29+
print("Exit Elf Parser State\n-------------\n");
30+
this->context->transition_state(new CallgraphState);
31+
}
32+
33+
//Callgraph
34+
void CallgraphState::enter() {
35+
print("Enter Callgraph State\n");
36+
}
37+
38+
void CallgraphState::handle() {
39+
print("Handle Callgraph State\n");
40+
}
41+
42+
void CallgraphState::exit() {
43+
print("Exit Callgraph State\n-------------\n");
44+
this->context->transition_state(new AbiParserState);
45+
}
46+
47+
//Abi Parser
48+
void AbiParserState::enter() {
49+
print("Enter ABI Parser State\n");
50+
}
51+
52+
void AbiParserState::handle() {
53+
print("Handle ABI Parser State\n");
54+
}
55+
56+
void AbiParserState::exit() {
57+
print("Exit ABI Parser State\n-------------\n");
58+
this->context->transition_state(new ValidatorState);
59+
}
60+
61+
//Validator
62+
void ValidatorState::enter() {
63+
print("Enter Validator State\n")
64+
}
65+
66+
void ValidatorState::handle() {
67+
print("Handle Validator State\n");
68+
}
69+
70+
void ValidatorState::exit() {
71+
print("Exit Validator State\n-------------\n");
72+
this->context->transition_state(new OutputState);
73+
}
74+
75+
//Output
76+
void OutputState::enter() {
77+
print("Enter Output State\n");
78+
}
79+
80+
void OutputState::handle() {
81+
print("Handle Output State\n");
82+
}
83+
84+
void OutputState::exit() {
85+
print("Exit Output State\n-------------\n");
86+
this->context->transition_state(new OutputState);
87+
}
88+
89+
//Error
90+
void ErrorState::enter() {
91+
print("Enter Error State\n")
92+
}
93+
94+
void ErrorState::handle() {
95+
print("Handle Error State\n");
96+
}
97+
98+
void ErrorState::exit() {
99+
print("Exit Error State\n-------------\n")
100+
}

src/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
#include <print>
22

3+
#include "state.hpp"
4+
#include "state_context.hpp"
5+
#include "concrete_states.hpp"
6+
7+
void state_init() {
8+
UserInputState inital_state;
9+
StateContext *context = new StateContext(&inital_state);
10+
context->run_state();
11+
delete context;
12+
}
13+
314
int main()
415
{
516
std::println("yeet: {}", __cplusplus);
17+
18+
state_init();
19+
620
return 0;
721
}

0 commit comments

Comments
 (0)