SerializableJSONStateMachine.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-17
  6. * Changed: 2020-11-26
  7. *
  8. * */
  9. #ifndef LS_STD_SERIALIZABLE_JSON_STATE_MACHINE_HPP
  10. #define LS_STD_SERIALIZABLE_JSON_STATE_MACHINE_HPP
  11. #include <ls_std/base/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_std {
  17. class SerializableJSONStateMachine : public Class, public ISerializable {
  18. public:
  19. explicit SerializableJSONStateMachine(const std::shared_ptr<ls_std::StateMachine>& _value);
  20. ~SerializableJSONStateMachine() override = default;
  21. // implementation
  22. ls_std::byte_field marshal() override;
  23. void unmarshal(const ls_std::byte_field& _data) override;
  24. // additional functionality
  25. std::shared_ptr<ls_std::StateMachine> getValue();
  26. void setValue(const std::shared_ptr<ls_std::StateMachine>& _value);
  27. private:
  28. nlohmann::json jsonObject {};
  29. std::shared_ptr<ls_std::StateMachine> value {};
  30. void _assignValue(const std::shared_ptr<ls_std::StateMachine>& _value);
  31. void _unmarshalCurrentState();
  32. void _unmarshalStates();
  33. void _update();
  34. void _updateCurrentState();
  35. void _updateStates();
  36. };
  37. }
  38. #endif