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
7
fsm.hpp
7
fsm.hpp
|
@ -3,9 +3,9 @@
|
|||
#include <fmt/core.h>
|
||||
|
||||
#ifndef FSM_DEBUG
|
||||
#define FSM_STATE(C, S, F, E) case C::S: F(E); break
|
||||
#define FSM_STATE(C, S, F, E, ...) case C::S: F(E, ##__VA_ARGS__); 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
|
||||
#define FSM_STATE(C, S, F, E, ...) case C::S: fmt::println(">> " #C " " #S ":" #F " event={}, state={}", int(E), int(_state)); F(E, ##__VA_ARGS__); fmt::println("<< " #C " state={}", int(_state)); break
|
||||
#endif
|
||||
|
||||
template<typename S, typename E>
|
||||
|
@ -15,7 +15,8 @@ protected:
|
|||
S _state = S::START;
|
||||
|
||||
public:
|
||||
virtual void event(E event) = 0;
|
||||
template<typename... Types>
|
||||
void event(E event, Types... args);
|
||||
|
||||
void state(S next_state) {
|
||||
_state = next_state;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue