StateMachine.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2020-11-06
  7. *
  8. * */
  9. #ifndef LS_STD_STATE_MACHINE_HPP
  10. #define LS_STD_STATE_MACHINE_HPP
  11. #include <memory>
  12. #include <unordered_map>
  13. #include <string>
  14. #include <vector>
  15. #include "../../../include/ls_std/base/Class.hpp"
  16. #include "State.hpp"
  17. #include "StateMachineTypes.hpp"
  18. namespace ls_std {
  19. class StateMachine : public Class {
  20. public:
  21. explicit StateMachine(std::string _name);
  22. ~StateMachine() = default;
  23. bool addState(const std::shared_ptr<State>& _state);
  24. std::shared_ptr<State> getCurrentState();
  25. std::vector<ls_std::StateId> getMemory();
  26. std::string getName();
  27. std::unordered_map<StateId, std::shared_ptr<State>> getStates();
  28. bool hasState(const StateId& _id);
  29. bool proceed();
  30. void setMemory(std::vector<ls_std::StateId> _memory);
  31. void setName(std::string _name);
  32. bool setStartState(const StateId& _id);
  33. private:
  34. std::shared_ptr<State> currentState {};
  35. std::vector<ls_std::StateId> memory {};
  36. std::string name {};
  37. std::unordered_map<StateId, std::shared_ptr<State>> states {};
  38. std::vector<StateId> _getNextValidStates();
  39. void _remember(const StateId& _id);
  40. bool _hasState(const StateId& _id);
  41. };
  42. }
  43. #endif