From 1cc5d08159936e87f7c1dc791d6ab3c0e46e7035 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 1 Nov 2017 08:38:59 +0300 Subject: Move converters.h out of jobs/ Because they are applicable beyond jobs. --- jobs/converters.h | 121 ------------------------------------------------------ 1 file changed, 121 deletions(-) delete mode 100644 jobs/converters.h (limited to 'jobs/converters.h') 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 -* -* 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 -#include // Includes -#include - -namespace QMatrixClient -{ - template - inline QJsonValue toJson(T val) - { - return QJsonValue(val); - } - - template - inline QJsonValue toJson(const QVector& 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 - struct FromJson - { - T operator()(QJsonValue jv) const { return static_cast(jv); } - }; - - template - inline T fromJson(const QJsonValue& jv) - { - return FromJson()(jv); - } - - template <> struct FromJson - { - bool operator()(QJsonValue jv) const { return jv.toBool(); } - }; - - template <> struct FromJson - { - int operator()(QJsonValue jv) const { return jv.toInt(); } - }; - - template <> struct FromJson - { - double operator()(QJsonValue jv) const { return jv.toDouble(); } - }; - - template <> struct FromJson - { - qint64 operator()(QJsonValue jv) const { return qint64(jv.toDouble()); } - }; - - template <> struct FromJson - { - QString operator()(QJsonValue jv) const { return jv.toString(); } - }; - - template <> struct FromJson - { - QDateTime operator()(QJsonValue jv) const - { - return QDateTime::fromMSecsSinceEpoch(fromJson(jv), Qt::UTC); - } - }; - - template <> struct FromJson - { - QDate operator()(QJsonValue jv) const - { - return fromJson(jv).date(); - } - }; - - template <> struct FromJson - { - QJsonObject operator()(QJsonValue jv) const { return jv.toObject(); } - }; - - template <> struct FromJson - { - QJsonArray operator()(QJsonValue jv) const { return jv.toArray(); } - }; - - template struct FromJson> - { - QVector operator()(QJsonValue jv) const - { - const auto jsonArray = jv.toArray(); - QVector vect; vect.resize(jsonArray.size()); - std::transform(jsonArray.begin(), jsonArray.end(), - vect.begin(), FromJson()); - return vect; - } - }; -} // namespace QMatrixClient -- cgit v1.2.3