StateMachine.hpp 1.3 KB

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