State.hpp 1.5 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: 2021-07-14
  7. *
  8. * */
  9. #ifndef LS_STD_STATE_HPP
  10. #define LS_STD_STATE_HPP
  11. #include <memory>
  12. #include <unordered_map>
  13. #include <ls_std/base/Class.hpp>
  14. #include "StateMachineTypes.hpp"
  15. #include "StateConnection.hpp"
  16. #include <ls_std/serialization/ISerializable.hpp>
  17. namespace ls_std
  18. {
  19. class State : public ls_std::Class
  20. {
  21. public:
  22. explicit State(const ls_std::StateId& _id);
  23. ~State() override = default;
  24. // additional functionality
  25. bool addStateConnection(const ls_std::StateConnectionId &_connectionId, const std::shared_ptr<ls_std::State> &_connectedState);
  26. bool addStateConnection(const std::shared_ptr<ls_std::StateConnection> &_connection);
  27. void clearConnections();
  28. std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> getConnectedStates();
  29. ls_std::StateId getId();
  30. bool hasConnection(const ls_std::StateConnectionId &_connectionId);
  31. void setId(const ls_std::StateId& _id);
  32. private:
  33. std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> connectedStates{};
  34. ls_std::StateId id{};
  35. void _assignStateId(const ls_std::StateId& _id);
  36. void _clearConnections();
  37. bool _hasConnection(const ls_std::StateConnectionId &_connectionId);
  38. };
  39. }
  40. #endif