Refined the FSM to allow easily passing in data to the even handler and state functions.
This commit is contained in:
parent
40ba7f0b66
commit
c9425aebf9
7 changed files with 75 additions and 74 deletions
|
@ -1,48 +0,0 @@
|
|||
#include <fmt/core.h>
|
||||
#include "../fsm.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
|
||||
enum class MyState {
|
||||
START, RUNNING, END
|
||||
};
|
||||
|
||||
enum class MyEvent {
|
||||
STARTED, PUSH, QUIT
|
||||
};
|
||||
|
||||
class MyFSM : DeadSimpleFSM<MyState, MyEvent> {
|
||||
public:
|
||||
void event(MyEvent ev) override {
|
||||
switch(_state) {
|
||||
FSM_STATE(MyState, START, start, ev);
|
||||
FSM_STATE(MyState, RUNNING, push, ev);
|
||||
FSM_STATE(MyState, END, quit, ev);
|
||||
}
|
||||
}
|
||||
|
||||
void start(MyEvent ev) {
|
||||
println("<<< START");
|
||||
state(MyState::RUNNING);
|
||||
}
|
||||
|
||||
void push(MyEvent ev) {
|
||||
println("<<< RUN");
|
||||
state(MyState::RUNNING);
|
||||
}
|
||||
|
||||
void quit(MyEvent ev) {
|
||||
println("<<< STOP");
|
||||
state(MyState::END);
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
MyFSM fsm;
|
||||
|
||||
fsm.event(MyEvent::STARTED);
|
||||
fsm.event(MyEvent::PUSH);
|
||||
fsm.event(MyEvent::PUSH);
|
||||
fsm.event(MyEvent::PUSH);
|
||||
fsm.event(MyEvent::QUIT);
|
||||
}
|
|
@ -10,9 +10,6 @@ executable('jsontest', 'jsontest.cpp',
|
|||
executable('threadtest', 'threadtest.cpp',
|
||||
dependencies: dependencies)
|
||||
|
||||
executable('fsmtest', 'fsmtest.cpp',
|
||||
dependencies: dependencies)
|
||||
|
||||
executable('badref', 'badref.cpp',
|
||||
dependencies: dependencies)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue