diff options
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/converters.h | 121 | ||||
-rw-r--r-- | jobs/generated/banning.cpp | 2 | ||||
-rw-r--r-- | jobs/generated/inviting.cpp | 2 | ||||
-rw-r--r-- | jobs/generated/kicking.cpp | 2 | ||||
-rw-r--r-- | jobs/generated/leaving.cpp | 2 | ||||
-rw-r--r-- | jobs/generated/login.cpp | 2 | ||||
-rw-r--r-- | jobs/generated/logout.cpp | 2 | ||||
-rw-r--r-- | jobs/generated/profile.cpp | 2 |
8 files changed, 7 insertions, 128 deletions
diff --git a/jobs/converters.h b/jobs/converters.h deleted file mode 100644 index f6e850c6..00000000 --- a/jobs/converters.h +++ /dev/null @@ -1,121 +0,0 @@ -/****************************************************************************** -* Copyright (C) 2017 Kitsune Ral <kitsune-ral@users.sf.net> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include <QtCore/QJsonObject> -#include <QtCore/QJsonArray> // Includes <QtCore/QJsonValue> -#include <QtCore/QDate> - -namespace QMatrixClient -{ - template <typename T> - inline QJsonValue toJson(T val) - { - return QJsonValue(val); - } - - template <typename T> - inline QJsonValue toJson(const QVector<T>& vals) - { - QJsonArray ar; - for (const auto& v: vals) - ar.push_back(toJson(v)); - return ar; - } - - inline QJsonValue toJson(const QStringList& strings) - { - return QJsonArray::fromStringList(strings); - } - - template <typename T> - struct FromJson - { - T operator()(QJsonValue jv) const { return static_cast<T>(jv); } - }; - - template <typename T> - inline T fromJson(const QJsonValue& jv) - { - return FromJson<T>()(jv); - } - - template <> struct FromJson<bool> - { - bool operator()(QJsonValue jv) const { return jv.toBool(); } - }; - - template <> struct FromJson<int> - { - int operator()(QJsonValue jv) const { return jv.toInt(); } - }; - - template <> struct FromJson<double> - { - double operator()(QJsonValue jv) const { return jv.toDouble(); } - }; - - template <> struct FromJson<qint64> - { - qint64 operator()(QJsonValue jv) const { return qint64(jv.toDouble()); } - }; - - template <> struct FromJson<QString> - { - QString operator()(QJsonValue jv) const { return jv.toString(); } - }; - - template <> struct FromJson<QDateTime> - { - QDateTime operator()(QJsonValue jv) const - { - return QDateTime::fromMSecsSinceEpoch(fromJson<qint64>(jv), Qt::UTC); - } - }; - - template <> struct FromJson<QDate> - { - QDate operator()(QJsonValue jv) const - { - return fromJson<QDateTime>(jv).date(); - } - }; - - template <> struct FromJson<QJsonObject> - { - QJsonObject operator()(QJsonValue jv) const { return jv.toObject(); } - }; - - template <> struct FromJson<QJsonArray> - { - QJsonArray operator()(QJsonValue jv) const { return jv.toArray(); } - }; - - template <typename T> struct FromJson<QVector<T>> - { - QVector<T> operator()(QJsonValue jv) const - { - const auto jsonArray = jv.toArray(); - QVector<T> vect; vect.resize(jsonArray.size()); - std::transform(jsonArray.begin(), jsonArray.end(), - vect.begin(), FromJson<T>()); - return vect; - } - }; -} // namespace QMatrixClient diff --git a/jobs/generated/banning.cpp b/jobs/generated/banning.cpp index 9fc5810a..c47d3419 100644 --- a/jobs/generated/banning.cpp +++ b/jobs/generated/banning.cpp @@ -5,7 +5,7 @@ #include "banning.h" -#include "jobs/converters.h" +#include "converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; diff --git a/jobs/generated/inviting.cpp b/jobs/generated/inviting.cpp index 95ba658d..11384c5e 100644 --- a/jobs/generated/inviting.cpp +++ b/jobs/generated/inviting.cpp @@ -5,7 +5,7 @@ #include "inviting.h" -#include "jobs/converters.h" +#include "converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; diff --git a/jobs/generated/kicking.cpp b/jobs/generated/kicking.cpp index 2e6797d6..e75b900a 100644 --- a/jobs/generated/kicking.cpp +++ b/jobs/generated/kicking.cpp @@ -5,7 +5,7 @@ #include "kicking.h" -#include "jobs/converters.h" +#include "converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; diff --git a/jobs/generated/leaving.cpp b/jobs/generated/leaving.cpp index 7fed347b..e443612e 100644 --- a/jobs/generated/leaving.cpp +++ b/jobs/generated/leaving.cpp @@ -5,7 +5,7 @@ #include "leaving.h" -#include "jobs/converters.h" +#include "converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; diff --git a/jobs/generated/login.cpp b/jobs/generated/login.cpp index 6e8294e7..0c57c684 100644 --- a/jobs/generated/login.cpp +++ b/jobs/generated/login.cpp @@ -5,7 +5,7 @@ #include "login.h" -#include "jobs/converters.h" +#include "converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; diff --git a/jobs/generated/logout.cpp b/jobs/generated/logout.cpp index b750efe2..a5848e7c 100644 --- a/jobs/generated/logout.cpp +++ b/jobs/generated/logout.cpp @@ -5,7 +5,7 @@ #include "logout.h" -#include "jobs/converters.h" +#include "converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; diff --git a/jobs/generated/profile.cpp b/jobs/generated/profile.cpp index 9d20a480..201bca79 100644 --- a/jobs/generated/profile.cpp +++ b/jobs/generated/profile.cpp @@ -5,7 +5,7 @@ #include "profile.h" -#include "jobs/converters.h" +#include "converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; |