StateMachine.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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-11
  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. bool proceed();
  28. bool setStartState(const StateId& _id);
  29. private:
  30. std::shared_ptr<State> currentState {};
  31. std::vector<ls_std::StateId> memory {};
  32. std::string name {};
  33. std::unordered_map<StateId, std::shared_ptr<State>> states {};
  34. std::vector<StateId> _getNextValidStates();
  35. void _remember(const StateId& _id);
  36. bool _stateExists(const StateId& _id);
  37. };
  38. }
  39. #endif