libQuotient
A Qt library for building matrix clients
single_key_value.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Quotient/converters.h>
4 
5 namespace Quotient {
6 
7 namespace EventContent {
8  template <typename T, const QLatin1String& KeyStr>
9  struct SingleKeyValue {
10  Q_IMPLICIT SingleKeyValue(const T& v = {}) : value(v) {}
11  Q_IMPLICIT SingleKeyValue(T&& v) : value(std::move(v)) {}
12  T value;
13  };
14 } // namespace EventContent
15 
16 template <typename ValueT, const QLatin1String& KeyStr>
17 struct 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