Files are now in a src directory and I'm using a src/meson.build and tests/meson.build to specify what to build.
This commit is contained in:
parent
4778677647
commit
1d4ae911b9
108 changed files with 94 additions and 83 deletions
32
src/simplefsm.hpp
Normal file
32
src/simplefsm.hpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#ifndef FSM_DEBUG
|
||||
#define FSM_STATE(C, S, E, ...) case C::S: S(E, ##__VA_ARGS__); break
|
||||
#else
|
||||
static int last_event=-1;
|
||||
#define FSM_STATE(C, S, E, ...) case C::S: if(last_event != int(E)) { last_event = int(E); fmt::println(">> " #C " " #S " event={}, state={}", int(E), int($state));}; S(E, ##__VA_ARGS__); break
|
||||
#endif
|
||||
|
||||
template<typename S, typename E>
|
||||
class DeadSimpleFSM {
|
||||
protected:
|
||||
// BUG: don't put this in your class because state() won't work
|
||||
S $state = S::START;
|
||||
|
||||
public:
|
||||
template<typename... Types>
|
||||
void event(E event, Types... args);
|
||||
|
||||
void state(S next_state) {
|
||||
#ifdef FSM_DEBUG
|
||||
fmt::println("<< STATE: {} -> {}", int($state), int(next_state));
|
||||
#endif
|
||||
$state = next_state;
|
||||
}
|
||||
|
||||
bool in_state(S state) {
|
||||
return $state == state;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue