State.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2021-04-30
  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(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(ls_std::StateId _id);
  35. void setSerializable(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 _clearConnections();
  41. bool _hasConnection(const ls_std::StateConnectionId &_connectionId);
  42. };
  43. }
  44. #endif