1#pragma once
2
3#include <Quotient/converters.h>
4
5namespace Quotient {
6
7namespace EventContent {
8 template <typename T, const QLatin1String& KeyStr>
9 struct SingleKeyValue {
10 // NOLINTBEGIN(google-explicit-constructor): that check should learn
11 // about explicit(false)
12 QUO_IMPLICIT SingleKeyValue(const T& v = {})
13 : value { v }
14 {}
15 QUO_IMPLICIT SingleKeyValue(T&& v)
16 : value { std::move(v) }
17 {}
18 // NOLINTEND(google-explicit-constructor)
19 T value;
20 };
21} // namespace EventContent
22
23template <typename ValueT, const QLatin1String& KeyStr>
24struct JsonConverter<EventContent::SingleKeyValue<ValueT, KeyStr>> {
25 using content_type = EventContent::SingleKeyValue<ValueT, KeyStr>;
26 static content_type load(const QJsonValue& jv)
27 {
28 return { fromJson<ValueT>(jv.toObject().value(key: JsonKey)) };
29 }
30 static QJsonObject dump(const content_type& c)
31 {
32 return { { JsonKey, toJson(c.value) } };
33 }
34 static inline const auto JsonKey = toSnakeCase(s: KeyStr);
35};
36} // namespace Quotient
37