aboutsummaryrefslogtreecommitdiff
path: root/shared/FSM.h
diff options
context:
space:
mode:
authorThomasAvans <tv.intanker@student.avans.nl>2024-04-22 10:40:59 +0200
committerThomasAvans <tv.intanker@student.avans.nl>2024-04-22 10:40:59 +0200
commit1640a4fb4bb0c831dd3f2a28bf99a49f3f41e829 (patch)
tree5889fbd9a70ed926a64a6c3cd0183ae25fc18be5 /shared/FSM.h
parent4354adcf0ae2eabbf419a76fc97746cb71962826 (diff)
Processed review
Diffstat (limited to 'shared/FSM.h')
-rw-r--r--shared/FSM.h50
1 files changed, 50 insertions, 0 deletions
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 <map>
+#include <memory>
+
+#include "IBehaviouralState.hpp"
+
+/// <summary>
+///
+/// </summary>
+/// <typeparam name="TState">IBehaviouralState is the only accepted
+/// class.</typeparam>
+template <class TState> class FSM {
+public:
+ template <class... TPState> FSM(TPState &...args) {
+ int i = 0;
+
+ ((void)_states.emplace(i++, args), ...);
+ }
+
+ /// <summary>
+ /// Implement with FSM::act()
+ /// </summary>
+ void act();
+
+ /// <summary>
+ /// Used to check current state.
+ /// </summary>
+ /// <returns>Current state.</returns>
+ std::shared_ptr<TState> &get_state() { return _currentState; }
+
+ /// <summary>
+ /// Used to get all states.
+ /// </summary>
+ /// <returns>Current states.</returns>
+ std::map<int, std::shared_ptr<TState>> get_states();
+
+ /// <summary>
+ /// Sets current state, calls appropiate functions.
+ /// </summary>
+ /// <param name="">State to transition into.</param>
+ void set_state(std::shared_ptr<TState>);
+
+private:
+ std::map<int, std::shared_ptr<TState>> _states;
+ std::shared_ptr<TState> _currentState;
+};
+
+#endif // _FSM_H_ \ No newline at end of file