浏览代码

Started prototyping StateMachine class (incomplete)

pcmattulat 4 年之前
父节点
当前提交
5828e9b75b
共有 2 个文件被更改,包括 22 次插入2 次删除
  1. 12 1
      source/logic/StateMachine.cpp
  2. 10 1
      source/logic/StateMachine.hpp

+ 12 - 1
source/logic/StateMachine.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2020-09-05
+ * Changed:         2020-09-07
  *
  * */
 
@@ -11,3 +11,14 @@
 
 ls_std::StateMachine::StateMachine() : Class("StateMachine")
 {}
+
+bool ls_std::StateMachine::addState(std::shared_ptr<State> _state) {
+  bool added {};
+  this->states.insert({_state->getId(), std::move(_state)});
+
+  return added;
+}
+
+bool ls_std::StateMachine::_stateExists(const std::string &_id) {
+  return this->states.find(_id) != this->states.end();
+}

+ 10 - 1
source/logic/StateMachine.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2020-09-05
+ * Changed:         2020-09-07
  *
  * */
 
@@ -11,6 +11,8 @@
 #define LS_STD_STATE_MACHINE_HPP
 
 #include <memory>
+#include <unordered_map>
+#include <string>
 #include "../base/Class.hpp"
 #include "State.hpp"
 
@@ -21,9 +23,16 @@ namespace ls_std {
       StateMachine();
       ~StateMachine() = default;
 
+      bool addState(std::shared_ptr<State> _state);
+      bool proceed();
+      bool setStartState(const std::string& _id);
+
     private:
 
       std::shared_ptr<State> currentState {};
+      std::unordered_map<std::string, std::shared_ptr<State>> states {};
+
+      bool _stateExists(const std::string& _id);
   };
 }