StateMachine.hpp 1.5 KB

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