SerializableJsonStateMachine.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-17
  6. * Changed: 2022-05-12
  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/core/interface/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. namespace std
  19. {
  20. namespace logic
  21. {
  22. class SerializableJsonStateMachine : public ls::std::core::Class, public ls::std::core::ISerializable
  23. {
  24. public:
  25. explicit SerializableJsonStateMachine(const ::std::shared_ptr<ls::std::logic::StateMachine> &_value);
  26. ~SerializableJsonStateMachine() 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::StateMachine> getValue();
  32. void setValue(const ::std::shared_ptr<ls::std::logic::StateMachine> &_value);
  33. private:
  34. nlohmann::json jsonObject{};
  35. ::std::shared_ptr<ls::std::logic::StateMachine> value{};
  36. void _assignValue(const ::std::shared_ptr<ls::std::logic::StateMachine> &_value);
  37. void _unmarshalCurrentState();
  38. void _unmarshalStates();
  39. void _update();
  40. void _updateCurrentState();
  41. void _updateStates();
  42. };
  43. }
  44. }
  45. }
  46. #endif