StateMachine.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2020-09-17
  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 "../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 setName(std::string _name);
  31. bool setStartState(const StateId& _id);
  32. private:
  33. std::shared_ptr<State> currentState {};
  34. std::vector<ls_std::StateId> memory {};
  35. std::string name {};
  36. std::unordered_map<StateId, std::shared_ptr<State>> states {};
  37. std::vector<StateId> _getNextValidStates();
  38. void _remember(const StateId& _id);
  39. bool _hasState(const StateId& _id);
  40. };
  41. }
  42. #endif