#pragma once #include #ifndef FSM_DEBUG #define FSM_STATE(C, S, F, E) case C::S: F(E); break #else #define FSM_STATE(C, S, F, E) case C::S: fmt::println(">> " #C " " #S ":" #F " event={}, state={}", int(E), int(_state)); F(E); fmt::println("<< " #C " state={}", int(_state)); break #endif template class DeadSimpleFSM { protected: // BUG: don't put this in your class because state() won't work 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; } };