aboutsummaryrefslogtreecommitdiff
path: root/lib/converters.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-01 16:38:05 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-01 20:46:59 +0900
commit68957eace7f840fffe7442f1d50d3793422bc152 (patch)
treed7634862d700d095ff1873660eff5a9f5f6c29ba /lib/converters.h
parent13f891185de9a678d37fe377c1426805c2e974ac (diff)
downloadlibquotient-68957eace7f840fffe7442f1d50d3793422bc152.tar.gz
libquotient-68957eace7f840fffe7442f1d50d3793422bc152.zip
converters.h: Support std::vector<>
Diffstat (limited to 'lib/converters.h')
-rw-r--r--lib/converters.h21
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