diff options
Diffstat (limited to 'src/FSM.hpp')
-rw-r--r-- | src/FSM.hpp | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/src/FSM.hpp b/src/FSM.hpp deleted file mode 100644 index 346d0f0..0000000 --- a/src/FSM.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include <utility> -#include <functional> -#include <map> - -template<class T> -class FSM { -public: - using Transaction = std::pair<T, T>; - using Handler = std::function<void(T &)>; - - FSM(T initialState) : state(initialState), previousState(initialState) {} - - ~FSM() = default; - - void Update() { - auto &handler = handlers[Transaction{previousState, state}]; - if (handler) - handler(state); - previousState = state; - } - - void RegisterHandler(T state, Handler handler) { - handlers[Transaction{state, state}] = handler; - } - - void RegisterTransactionHandler(Transaction transaction, Handler handler) { - handlers[transaction] = handler; - } - -private: - T previousState; - T state; - std::map<Transaction, Handler> handlers; -};
\ No newline at end of file |