State.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2021-05-28
  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, public ls_std::ISerializable
  20. {
  21. public:
  22. explicit State(const ls_std::StateId& _id);
  23. ~State() override = default;
  24. // implementation
  25. ls_std::byte_field marshal() override;
  26. void unmarshal(const ls_std::byte_field &_data) override;
  27. // additional functionality
  28. bool addStateConnection(const ls_std::StateConnectionId &_connectionId, const std::shared_ptr<ls_std::State> &_connectedState);
  29. bool addStateConnection(const std::shared_ptr<ls_std::StateConnection> &_connection);
  30. void clearConnections();
  31. std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> getConnectedStates();
  32. ls_std::StateId getId();
  33. bool hasConnection(const ls_std::StateConnectionId &_connectionId);
  34. void setId(const ls_std::StateId& _id);
  35. void setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
  36. private:
  37. std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> connectedStates{};
  38. ls_std::StateId id{};
  39. std::shared_ptr<ISerializable> serializable{};
  40. void _assignSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
  41. void _assignStateId(const ls_std::StateId& _id);
  42. void _clearConnections();
  43. bool _hasConnection(const ls_std::StateConnectionId &_connectionId);
  44. };
  45. }
  46. #endif