aboutsummaryrefslogtreecommitdiff
path: root/lib/converters.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-01 21:01:33 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-01 21:01:33 +0900
commit1e42eca5c3d864750609eacd4996794c901c6c37 (patch)
tree88a2ca014bfd38bdbd2c30cd3918fc49dd7a7255 /lib/converters.h
parent38934c2310b426be640988dc10f48de88a3d92bc (diff)
parent2a341e30ef2db74b331a8870ceb2f182af68f194 (diff)
downloadlibquotient-1e42eca5c3d864750609eacd4996794c901c6c37.tar.gz
libquotient-1e42eca5c3d864750609eacd4996794c901c6c37.zip
Merge branch 'master' into kitsune-gtad
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