From 00e5968bd28ab1df33b3a39dbac8cda99aa2a0d2 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 6 Apr 2016 23:09:30 +0200 Subject: NOISSUE Add a skeleton of the wonko system --- logic/Json.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'logic/Json.h') diff --git a/logic/Json.h b/logic/Json.h index cb266c6e..2cb60f0e 100644 --- a/logic/Json.h +++ b/logic/Json.h @@ -113,9 +113,9 @@ template<> MULTIMC_LOGIC_EXPORT QUrl requireIsType(const QJsonValue &value // the following functions are higher level functions, that make use of the above functions for // type conversion template -T ensureIsType(const QJsonValue &value, const T default_, const QString &what = "Value") +T ensureIsType(const QJsonValue &value, const T default_ = T(), const QString &what = "Value") { - if (value.isUndefined()) + if (value.isUndefined() || value.isNull()) { return default_; } @@ -142,7 +142,7 @@ T requireIsType(const QJsonObject &parent, const QString &key, const QString &wh } template -T ensureIsType(const QJsonObject &parent, const QString &key, const T default_, const QString &what = "__placeholder__") +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)) @@ -153,10 +153,10 @@ T ensureIsType(const QJsonObject &parent, const QString &key, const T default_, } template -QList requireIsArrayOf(const QJsonDocument &doc) +QVector requireIsArrayOf(const QJsonDocument &doc) { const QJsonArray array = requireArray(doc); - QList out; + QVector out; for (const QJsonValue val : array) { out.append(requireIsType(val, "Document")); @@ -165,19 +165,19 @@ QList requireIsArrayOf(const QJsonDocument &doc) } template -QList ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value") +QVector ensureIsArrayOf(const QJsonValue &value, const QString &what = "Value") { - const QJsonArray array = requireIsType(value, what); - QList out; + const QJsonArray array = ensureIsType(value, QJsonArray(), what); + QVector out; for (const QJsonValue val : array) { - out.append(ensureIsType(val, what)); + out.append(requireIsType(val, what)); } return out; } template -QList ensureIsArrayOf(const QJsonValue &value, const QList default_, const QString &what = "Value") +QVector ensureIsArrayOf(const QJsonValue &value, const QVector default_, const QString &what = "Value") { if (value.isUndefined()) { @@ -188,19 +188,19 @@ QList ensureIsArrayOf(const QJsonValue &value, const QList default_, const /// @throw JsonException template -QList requireIsArrayOf(const QJsonObject &parent, const QString &key, const QString &what = "__placeholder__") +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 requireIsArrayOf(parent.value(key), localWhat); + return ensureIsArrayOf(parent.value(key), localWhat); } template -QList ensureIsArrayOf(const QJsonObject &parent, const QString &key, - const QList &default_, const QString &what = "__placeholder__") +QVector ensureIsArrayOf(const QJsonObject &parent, const QString &key, + const QVector &default_ = QVector(), const QString &what = "__placeholder__") { const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); if (!parent.contains(key)) @@ -216,7 +216,7 @@ QList ensureIsArrayOf(const QJsonObject &parent, const QString &key, { \ return requireIsType(value, what); \ } \ - inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_, const QString &what = "Value") \ + inline TYPE ensure##NAME(const QJsonValue &value, const TYPE default_ = TYPE(), const QString &what = "Value") \ { \ return ensureIsType(value, default_, what); \ } \ @@ -224,7 +224,7 @@ QList ensureIsArrayOf(const QJsonObject &parent, const QString &key, { \ return requireIsType(parent, key, what); \ } \ - inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_, const QString &what = "__placeholder") \ + inline TYPE ensure##NAME(const QJsonObject &parent, const QString &key, const TYPE default_ = TYPE(), const QString &what = "__placeholder") \ { \ return ensureIsType(parent, key, default_, what); \ } -- cgit v1.2.3