From 68957eace7f840fffe7442f1d50d3793422bc152 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 16:38:05 +0900 Subject: converters.h: Support std::vector<> --- lib/converters.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/converters.h b/lib/converters.h index 22b22f25..cfe9c01c 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -33,6 +33,15 @@ namespace QMatrixClient inline QJsonValue toJson(const QString& s) { return s; } #endif + template + inline QJsonArray toJson(const std::vector& vals) + { + QJsonArray ar; + for (const auto& v: vals) + ar.push_back(toJson(v)); + return ar; + } + template inline QJsonArray toJson(const QVector& vals) { @@ -142,6 +151,18 @@ namespace QMatrixClient } }; + template struct FromJson> + { + std::vector operator()(const QJsonValue& jv) const + { + const auto jsonArray = jv.toArray(); + std::vector vect; vect.resize(size_t(jsonArray.size())); + std::transform(jsonArray.begin(), jsonArray.end(), + vect.begin(), FromJson()); + return vect; + } + }; + template struct FromJson> { QVector operator()(const QJsonValue& jv) const -- cgit v1.2.3