SerializableJSONStateMachine.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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-06
  7. *
  8. * */
  9. #ifndef LS_STD_SERIALIZABLE_JSON_STATE_MACHINE_HPP
  10. #define LS_STD_SERIALIZABLE_JSON_STATE_MACHINE_HPP
  11. #include "../../../../../include/base/Class.hpp"
  12. #include "../../ISerializable.hpp"
  13. #include "../../../logic/StateMachine.hpp"
  14. #include <memory>
  15. #include <json.hpp>
  16. namespace ls_std {
  17. class SerializableJSONStateMachine : public Class, public ISerializable {
  18. public:
  19. explicit SerializableJSONStateMachine(std::shared_ptr<StateMachine> _value);
  20. ~SerializableJSONStateMachine() = default;
  21. ls_std::byte_field marshal() override;
  22. void unmarshal(const ls_std::byte_field& _data) override;
  23. private:
  24. nlohmann::json jsonObject {};
  25. std::shared_ptr<ls_std::StateMachine> value {};
  26. void _unmarshalCurrentState();
  27. void _unmarshalStates();
  28. void _update();
  29. void _updateCurrentState();
  30. void _updateStates();
  31. };
  32. }
  33. #endif