SerializableJsonState.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-15
  6. * Changed: 2022-07-03
  7. *
  8. * */
  9. #ifndef LS_STD_SERIALIZABLE_JSON_STATE_HPP
  10. #define LS_STD_SERIALIZABLE_JSON_STATE_HPP
  11. #include <memory>
  12. #include <ls_std/lib/nlohmann_json/include/nlohmann/json.hpp>
  13. #include <ls_std/logic/State.hpp>
  14. #include <ls_std/core/interface/ISerializable.hpp>
  15. #include <ls_std/core/Class.hpp>
  16. #include <ls_std/os/dynamic_goal.hpp>
  17. namespace ls
  18. {
  19. namespace std
  20. {
  21. namespace logic
  22. {
  23. class LS_STD_DYNAMIC_GOAL SerializableJsonState : public ls::std::core::Class, public ls::std::core::interface_type::ISerializable
  24. {
  25. public:
  26. explicit SerializableJsonState(const ::std::shared_ptr<ls::std::logic::State> &_value);
  27. ~SerializableJsonState() override = default;
  28. // implementation
  29. ls::std::core::type::byte_field marshal() override;
  30. void unmarshal(const ls::std::core::type::byte_field &_data) override;
  31. // additional functionality
  32. ::std::shared_ptr<ls::std::logic::State> getValue();
  33. void setValue(const ::std::shared_ptr<ls::std::logic::State> &_value);
  34. private:
  35. nlohmann::json jsonObject{};
  36. ::std::shared_ptr<ls::std::logic::State> value{};
  37. void _assignValue(const ::std::shared_ptr<ls::std::logic::State> &_value);
  38. void _clear();
  39. void _unmarshalStateConnections();
  40. void _update();
  41. void _updateStateConnections();
  42. };
  43. }
  44. }
  45. }
  46. #endif