StateMachine.hpp 2.0 KB

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