SerializableJsonStateMachine.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-17
  6. * Changed: 2022-05-09
  7. *
  8. * */
  9. #ifndef LS_STD_SERIALIZABLE_JSON_STATE_MACHINE_HPP
  10. #define LS_STD_SERIALIZABLE_JSON_STATE_MACHINE_HPP
  11. #include "ls_std/core/Class.hpp"
  12. #include "ls_std/serialization/ISerializable.hpp"
  13. #include "ls_std/logic/StateMachine.hpp"
  14. #include <memory>
  15. #include "ls_std/lib/nlohmann_json/include/nlohmann/json.hpp"
  16. namespace ls
  17. {
  18. class SerializableJsonStateMachine : public ls::std::core::Class, public ls::ISerializable
  19. {
  20. public:
  21. explicit SerializableJsonStateMachine(const ::std::shared_ptr<ls::StateMachine> &_value);
  22. ~SerializableJsonStateMachine() override = default;
  23. // implementation
  24. ls::std::core::byte_field marshal() override;
  25. void unmarshal(const ls::std::core::byte_field &_data) override;
  26. // additional functionality
  27. ::std::shared_ptr<ls::StateMachine> getValue();
  28. void setValue(const ::std::shared_ptr<ls::StateMachine> &_value);
  29. private:
  30. nlohmann::json jsonObject{};
  31. ::std::shared_ptr<ls::StateMachine> value{};
  32. void _assignValue(const ::std::shared_ptr<ls::StateMachine> &_value);
  33. void _unmarshalCurrentState();
  34. void _unmarshalStates();
  35. void _update();
  36. void _updateCurrentState();
  37. void _updateStates();
  38. };
  39. }
  40. #endif