You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/core.h>
|
|
|
|
|
|
|
|
#define FSM_EV(S, F) case S: F(); break
|
|
|
|
#define FSM_STATE(S, F, E) case S: fmt::println(">>> " #S ":" #F ":{}", int(E)); F(E); break
|
|
|
|
|
|
|
|
template<typename S, typename E>
|
|
|
|
class DeadSimpleFSM {
|
|
|
|
protected:
|
|
|
|
S _state = S::START;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void event(E event) = 0;
|
|
|
|
|
|
|
|
void state(S next_state) {
|
|
|
|
_state = next_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool in_state(S state) {
|
|
|
|
return _state == state;
|
|
|
|
}
|
|
|
|
};
|