StateMachine.hpp 2.1 KB

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