libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
single_key_value.h
Go to the documentation of this file.
1#pragma once
2
3#include <Quotient/converters.h>
4
5namespace Quotient {
6
7namespace EventContent {
8 template <typename T, const QLatin1String& KeyStr>
10 Q_IMPLICIT SingleKeyValue(const T& v = {}) : value(v) {}
13 };
14} // namespace EventContent
15
16template <typename ValueT, const QLatin1String& KeyStr>
17struct JsonConverter<EventContent::SingleKeyValue<ValueT, KeyStr>> {
18 using content_type = EventContent::SingleKeyValue<ValueT, KeyStr>;
19 static content_type load(const QJsonValue& jv)
20 {
21 return fromJson<ValueT>(jv.toObject().value(JsonKey));
22 }
23 static QJsonObject dump(const content_type& c)
24 {
25 return { { JsonKey, toJson(c.value) } };
26 }
27 static inline const auto JsonKey = toSnakeCase(KeyStr);
28};
29} // namespace Quotient
The switchboard for extra conversion algorithms behind from/toJson.
Definition converters.h:78