StateMachine.hpp 833 B

123456789101112131415161718192021222324252627282930313233343536373839
  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-07
  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 "../base/Class.hpp"
  15. #include "State.hpp"
  16. namespace ls_std {
  17. class StateMachine : public Class {
  18. public:
  19. StateMachine();
  20. ~StateMachine() = default;
  21. bool addState(std::shared_ptr<State> _state);
  22. bool proceed();
  23. bool setStartState(const std::string& _id);
  24. private:
  25. std::shared_ptr<State> currentState {};
  26. std::unordered_map<std::string, std::shared_ptr<State>> states {};
  27. bool _stateExists(const std::string& _id);
  28. };
  29. }
  30. #endif