From 1640a4fb4bb0c831dd3f2a28bf99a49f3f41e829 Mon Sep 17 00:00:00 2001 From: ThomasAvans Date: Mon, 22 Apr 2024 10:40:59 +0200 Subject: Processed review --- shared/FSM.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 shared/FSM.h (limited to 'shared/FSM.h') diff --git a/shared/FSM.h b/shared/FSM.h new file mode 100644 index 0000000..792a44f --- /dev/null +++ b/shared/FSM.h @@ -0,0 +1,50 @@ +#ifndef _FSM_H_ +#define _FSM_H_ + +#include +#include + +#include "IBehaviouralState.hpp" + +/// +/// +/// +/// IBehaviouralState is the only accepted +/// class. +template class FSM { +public: + template FSM(TPState &...args) { + int i = 0; + + ((void)_states.emplace(i++, args), ...); + } + + /// + /// Implement with FSM::act() + /// + void act(); + + /// + /// Used to check current state. + /// + /// Current state. + std::shared_ptr &get_state() { return _currentState; } + + /// + /// Used to get all states. + /// + /// Current states. + std::map> get_states(); + + /// + /// Sets current state, calls appropiate functions. + /// + /// State to transition into. + void set_state(std::shared_ptr); + +private: + std::map> _states; + std::shared_ptr _currentState; +}; + +#endif // _FSM_H_ \ No newline at end of file -- cgit v1.2.3