diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-05-08 19:08:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 19:08:57 +0200 |
commit | 3458fdf7b416fe64b82ec9b99553c7b2aa299e4c (patch) | |
tree | b3b1bce3ebf0631597aa6d8451e62d198a42c2be /lib/events/single_key_value.h | |
parent | 272cb01b05529971ea38e09bf75d8d8f194a9dd8 (diff) | |
parent | c42d268db0b40cdba06381fc64a6966a72c90709 (diff) | |
download | libquotient-3458fdf7b416fe64b82ec9b99553c7b2aa299e4c.tar.gz libquotient-3458fdf7b416fe64b82ec9b99553c7b2aa299e4c.zip |
Merge #548: Streamline usage of event types, part 1
Diffstat (limited to 'lib/events/single_key_value.h')
-rw-r--r-- | lib/events/single_key_value.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/events/single_key_value.h b/lib/events/single_key_value.h new file mode 100644 index 00000000..75ca8cd2 --- /dev/null +++ b/lib/events/single_key_value.h @@ -0,0 +1,27 @@ +#pragma once + +#include "converters.h" + +namespace Quotient { + +namespace EventContent { + template <typename T, const QLatin1String* KeyStr> + struct SingleKeyValue { + T value; + }; +} // namespace EventContent + +template <typename ValueT, const QLatin1String* KeyStr> +struct JsonConverter<EventContent::SingleKeyValue<ValueT, KeyStr>> { + using content_type = EventContent::SingleKeyValue<ValueT, KeyStr>; + static content_type load(const QJsonValue& jv) + { + return { fromJson<ValueT>(jv.toObject().value(JsonKey)) }; + } + static QJsonObject dump(const content_type& c) + { + return { { JsonKey, toJson(c.value) } }; + } + static inline const auto JsonKey = toSnakeCase(*KeyStr); +}; +} // namespace Quotient |