From d0b5c8c14d4a41b39470821d43dd719dbb5246aa Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 25 Jul 2024 16:38:30 +0200 Subject: core/turn_order: implement basic serialization --- core/include/turns/core/json_ext.hpp | 43 ++++++++++++++++++++++++++++++++++ core/include/turns/core/turn_order.hpp | 8 +++++++ 2 files changed, 51 insertions(+) create mode 100644 core/include/turns/core/json_ext.hpp (limited to 'core/include') diff --git a/core/include/turns/core/json_ext.hpp b/core/include/turns/core/json_ext.hpp new file mode 100644 index 0000000..3eedb64 --- /dev/null +++ b/core/include/turns/core/json_ext.hpp @@ -0,0 +1,43 @@ +#ifndef TURNS_CORE_JSON_EXT_HPP +#define TURNS_CORE_JSON_EXT_HPP + +#include +#include + +#include + +#include + +NLOHMANN_JSON_NAMESPACE_BEGIN + +template +struct adl_serializer> +{ + static void to_json(json & to, Glib::Property const & from) + { + to = from.get_value(); + } + + static void from_json(json const & from, Glib::Property & to) + { + to = from.template get(); + } +}; + +template<> +struct adl_serializer +{ + static void to_json(json & to, Glib::ustring const & from) + { + to = static_cast(from); + } + + static void from_json(json const & from, Glib::ustring & to) + { + to = from.template get(); + } +}; + +NLOHMANN_JSON_NAMESPACE_END + +#endif \ No newline at end of file diff --git a/core/include/turns/core/turn_order.hpp b/core/include/turns/core/turn_order.hpp index 59556bb..5dbc6c6 100644 --- a/core/include/turns/core/turn_order.hpp +++ b/core/include/turns/core/turn_order.hpp @@ -14,6 +14,8 @@ #include #include +#include + namespace turns::core { @@ -40,6 +42,7 @@ namespace turns::core turn_order(); auto static create() -> Glib::RefPtr; + auto static create(nlohmann::json const & from) -> Glib::RefPtr; /** Properties */ auto is_empty() const -> Glib::PropertyProxy_ReadOnly; @@ -60,7 +63,12 @@ namespace turns::core auto start() -> void; auto stop() -> void; + /** Serialization */ + auto serialize() -> nlohmann::json; + private: + explicit turn_order(nlohmann::json const & from); + auto get_item_type_vfunc() -> GType override; auto get_n_items_vfunc() -> unsigned override; auto get_item_vfunc(unsigned position) -> void * override; -- cgit v1.2.3