From bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 15 Jul 2018 14:51:05 +0200 Subject: NOISSUE tabs -> spaces --- api/logic/Json.h | 160 +++++++++++++++++++++++++++---------------------------- 1 file changed, 80 insertions(+), 80 deletions(-) (limited to 'api/logic/Json.h') diff --git a/api/logic/Json.h b/api/logic/Json.h index a84d204a..34ff6fe2 100644 --- a/api/logic/Json.h +++ b/api/logic/Json.h @@ -19,7 +19,7 @@ namespace Json class MULTIMC_LOGIC_EXPORT JsonException : public ::Exception { public: - JsonException(const QString &message) : Exception(message) {} + JsonException(const QString &message) : Exception(message) {} }; /// @throw FileSystemException @@ -51,7 +51,7 @@ void writeStringList(QJsonObject & to, const QString &key, const QStringList &va template QJsonValue toJson(const T &t) { - return QJsonValue(t); + return QJsonValue(t); } template<> QJsonValue toJson(const QUrl &url); @@ -69,12 +69,12 @@ QJsonValue toJson(const QVariant &variant); template QJsonArray toJsonArray(const QList &container) { - QJsonArray array; - for (const T item : container) - { - array.append(toJson(item)); - } - return array; + QJsonArray array; + for (const T item : container) + { + array.append(toJson(item)); + } + return array; } ////////////////// READING //////////////////// @@ -115,119 +115,119 @@ template<> MULTIMC_LOGIC_EXPORT QUrl requireIsType(const QJsonValue &value template T ensureIsType(const QJsonValue &value, const T default_ = T(), const QString &what = "Value") { - if (value.isUndefined() || value.isNull()) - { - return default_; - } - try - { - return requireIsType(value, what); - } - catch (const JsonException &) - { - return default_; - } + if (value.isUndefined() || value.isNull()) + { + return default_; + } + try + { + return requireIsType(value, what); + } + catch (const JsonException &) + { + return default_; + } } /// @throw JsonException template T requireIsType(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") { - const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); - if (!parent.contains(key)) - { - throw JsonException(localWhat + "s parent does not contain " + localWhat); - } - return requireIsType(parent.value(key), localWhat); + const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); + if (!parent.contains(key)) + { + throw JsonException(localWhat + "s parent does not contain " + localWhat); + } + return requireIsType(parent.value(key), localWhat); } template T ensureIsType(const QJsonObject &parent, const QString &key, const T default_ = T(), const QString &what = "__placeholder__") { - const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); - if (!parent.contains(key)) - { - return default_; - } - return ensureIsType(parent.value(key), default_, localWhat); + const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); + if (!parent.contains(key)) + { + return default_; + } + return ensureIsType(parent.value(key), default_, localWhat); } template QVector requireIsArrayOf(const QJsonDocument &doc) { - const QJsonArray array = requireArray(doc); - QVector out; - for (const QJsonValue val : array) - { - out.append(requireIsType(val, "Document")); - } - return out; + const QJsonArray array = requireArray(doc); + QVector out; + for (const QJsonValue val : array) + { + out.append(requireIsType(val, "Document")); + } + return out; } template QVector ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value") { - const QJsonArray array = ensureIsType(value, QJsonArray(), what); - QVector out; - for (const QJsonValue val : array) - { - out.append(requireIsType(val, what)); - } - return out; + const QJsonArray array = ensureIsType(value, QJsonArray(), what); + QVector out; + for (const QJsonValue val : array) + { + out.append(requireIsType(val, what)); + } + return out; } template QVector ensureIsArrayOf(const QJsonValue &value, const QVector default_, const QString &what = "Value") { - if (value.isUndefined()) - { - return default_; - } - return ensureIsArrayOf(value, what); + if (value.isUndefined()) + { + return default_; + } + return ensureIsArrayOf(value, what); } /// @throw JsonException template QVector requireIsArrayOf(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") { - const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); - if (!parent.contains(key)) - { - throw JsonException(localWhat + "s parent does not contain " + localWhat); - } - return ensureIsArrayOf(parent.value(key), localWhat); + const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); + if (!parent.contains(key)) + { + throw JsonException(localWhat + "s parent does not contain " + localWhat); + } + return ensureIsArrayOf(parent.value(key), localWhat); } template QVector ensureIsArrayOf(const QJsonObject &parent, const QString &key, - const QVector &default_ = QVector(), const QString &what = "__placeholder__") + const QVector &default_ = QVector(), const QString &what = "__placeholder__") { - const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); - if (!parent.contains(key)) - { - return default_; - } - return ensureIsArrayOf(parent.value(key), default_, localWhat); + const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); + if (!parent.contains(key)) + { + return default_; + } + return ensureIsArrayOf(parent.value(key), default_, localWhat); } // this macro part could be replaced by variadic functions that just pass on their arguments, but that wouldn't work well with IDE helpers #define JSON_HELPERFUNCTIONS(NAME, TYPE) \ - inline TYPE require##NAME(const QJsonValue &value, const QString &what = "Value") \ - { \ - return requireIsType(value, what); \ - } \ - inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_ = TYPE(), const QString &what = "Value") \ - { \ - return ensureIsType(value, default_, what); \ - } \ - inline TYPE require##NAME(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") \ - { \ - return requireIsType(parent, key, what); \ - } \ - inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_ = TYPE(), const QString &what = "__placeholder") \ - { \ - return ensureIsType(parent, key, default_, what); \ - } + inline TYPE require##NAME(const QJsonValue &value, const QString &what = "Value") \ + { \ + return requireIsType(value, what); \ + } \ + inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_ = TYPE(), const QString &what = "Value") \ + { \ + return ensureIsType(value, default_, what); \ + } \ + inline TYPE require##NAME(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") \ + { \ + return requireIsType(parent, key, what); \ + } \ + inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_ = TYPE(), const QString &what = "__placeholder") \ + { \ + return ensureIsType(parent, key, default_, what); \ + } JSON_HELPERFUNCTIONS(Array, QJsonArray) JSON_HELPERFUNCTIONS(Object, QJsonObject) -- cgit