SerializableJsonState.hpp 1.3 KB

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