SerializableJSONState.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-15
  6. * Changed: 2020-11-20
  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/serialization/ISerializable.hpp>
  15. #include <ls_std/base/Class.hpp>
  16. namespace ls_std {
  17. class SerializableJSONState : public Class, public ISerializable {
  18. public:
  19. explicit SerializableJSONState(std::shared_ptr<State> _value);
  20. ~SerializableJSONState() = default;
  21. // implementation
  22. ls_std::byte_field marshal() override;
  23. void unmarshal(const ls_std::byte_field& _data) override;
  24. // additional functionality
  25. void setValue(std::shared_ptr<State> _value);
  26. private:
  27. nlohmann::json jsonObject {};
  28. std::shared_ptr<ls_std::State> value {};
  29. void _clear();
  30. void _unmarshalExistingStateConnection(nlohmann::json _jsonObject);
  31. void _unmarshalNewStateConnection(nlohmann::json _jsonObject);
  32. void _unmarshalStateConnections();
  33. void _update();
  34. void _updateStateConnections();
  35. };
  36. }
  37. #endif