diff options
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 |
