diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2024-07-25 14:39:16 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2024-07-25 14:39:16 +0200 |
| commit | 2b9ad3fbcbea86bd2cf702ff4c6e603c33492e45 (patch) | |
| tree | 762f3a71b3b7f212c7167e49d370cb297d33d45d /core/src | |
| parent | 9ec62f964df0070cb13df4e1de3d52dc7f27189b (diff) | |
| download | turns-2b9ad3fbcbea86bd2cf702ff4c6e603c33492e45.tar.xz turns-2b9ad3fbcbea86bd2cf702ff4c6e603c33492e45.zip | |
core/participant: implement basic serialization
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/participant.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/core/src/participant.cpp b/core/src/participant.cpp index 24d1cff..0c32172 100644 --- a/core/src/participant.cpp +++ b/core/src/participant.cpp @@ -2,8 +2,11 @@ #include <glibmm/refptr.h> -#include <typeinfo> +#include <nlohmann/json.hpp> + #include <compare> +#include <string> +#include <typeinfo> namespace turns::core { @@ -12,6 +15,19 @@ namespace turns::core return Glib::make_refptr_for_instance(new participant{name, priority, disposition}); } + auto participant::create(nlohmann::json const & serialized) -> Glib::RefPtr<participant> + { + auto active = serialized.value("active", false); + auto disposition = serialized.value("disposition", disposition::neutral); + auto priority = serialized.value("priority", 0.0f); + auto name = serialized.value("name", std::string{}); + + auto instance = create(name, priority, disposition); + instance->is_active() = active; + + return instance; + } + participant::participant() : Glib::ObjectBase{typeid(participant)} , Glib::Object{} @@ -31,4 +47,14 @@ namespace turns::core return m_priority <=> other.m_priority; } + auto participant::serialize() -> nlohmann::json + { + return nlohmann::json{ + {"active", m_is_active.get_value() }, + {"disposition", m_disposition.get_value() }, + {"name", static_cast<std::string>(m_name.get_value())}, + {"priority", m_priority.get_value() }, + }; + } + } // namespace turns::core
\ No newline at end of file |
