diff options
Diffstat (limited to 'lib/converters.h')
-rw-r--r-- | lib/converters.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/converters.h b/lib/converters.h index 22b22f25..cfe9c01c 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -34,6 +34,15 @@ namespace QMatrixClient #endif template <typename T> + inline QJsonArray toJson(const std::vector<T>& vals) + { + QJsonArray ar; + for (const auto& v: vals) + ar.push_back(toJson(v)); + return ar; + } + + template <typename T> inline QJsonArray toJson(const QVector<T>& vals) { QJsonArray ar; @@ -142,6 +151,18 @@ namespace QMatrixClient } }; + template <typename T> struct FromJson<std::vector<T>> + { + std::vector<T> operator()(const QJsonValue& jv) const + { + const auto jsonArray = jv.toArray(); + std::vector<T> vect; vect.resize(size_t(jsonArray.size())); + std::transform(jsonArray.begin(), jsonArray.end(), + vect.begin(), FromJson<T>()); + return vect; + } + }; + template <typename T> struct FromJson<QVector<T>> { QVector<T> operator()(const QJsonValue& jv) const |