SerializableJsonState.hpp 1.5 KB

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