From 755ddd0f7fbb162218e964796bf321e5bb9a6410 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 9 Nov 2025 20:23:57 +0000 Subject: [PATCH] Remove traces of ensure helpers Signed-off-by: TheKodeToad --- launcher/Json.cpp | 2 +- launcher/Json.h | 61 +++++------------------------------------------ 2 files changed, 7 insertions(+), 56 deletions(-) diff --git a/launcher/Json.cpp b/launcher/Json.cpp index 557cb1ff4..dd7287e00 100644 --- a/launcher/Json.cpp +++ b/launcher/Json.cpp @@ -287,7 +287,7 @@ QStringList toStringList(const QString& jsonString) if (parseError.error != QJsonParseError::NoError || !doc.isArray()) return {}; try { - return ensureIsArrayOf(doc.array(), ""); + return requireIsArrayOf(doc); } catch (Json::JsonException& e) { return {}; } diff --git a/launcher/Json.h b/launcher/Json.h index f8c900412..8a994d7bc 100644 --- a/launcher/Json.h +++ b/launcher/Json.h @@ -153,18 +153,6 @@ QUrl requireIsType(const QJsonValue& value, const QString& what); // 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_ = T(), const QString& what = "Value") -{ - if (value.isUndefined() || value.isNull()) { - return default_; - } - try { - return requireIsType(value, what); - } catch (const JsonException&) { - return default_; - } -} /// @throw JsonException template @@ -177,16 +165,6 @@ T requireIsType(const QJsonObject& parent, const QString& key, const QString& wh 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); -} - template QList requireIsArrayOf(const QJsonDocument& doc) { @@ -198,26 +176,6 @@ QList requireIsArrayOf(const QJsonDocument& doc) return out; } -template -QList ensureIsArrayOf(const QJsonValue& value, const QString& what = "Value") -{ - const QJsonArray array = ensureIsType(value, QJsonArray(), what); - QList out; - for (const QJsonValue val : array) { - out.append(requireIsType(val, what)); - } - return out; -} - -template -QList ensureIsArrayOf(const QJsonValue& value, const QList default_, const QString& what = "Value") -{ - if (value.isUndefined()) { - return default_; - } - return ensureIsArrayOf(value, what); -} - /// @throw JsonException template QList requireIsArrayOf(const QJsonObject& parent, const QString& key, const QString& what = "__placeholder__") @@ -226,20 +184,13 @@ QList requireIsArrayOf(const QJsonObject& parent, const QString& key, const Q if (!parent.contains(key)) { throw JsonException(localWhat + "s parent does not contain " + localWhat); } - return ensureIsArrayOf(parent.value(key), localWhat); -} -template -QList ensureIsArrayOf(const QJsonObject& parent, - const QString& key, - const QList& default_ = QList(), - const QString& what = "__placeholder__") -{ - const QString localWhat = QString(what).replace("__placeholder__", '\'' + key + '\''); - if (!parent.contains(key)) { - return default_; + const QJsonArray array = parent[key].toArray(); + QList out; + for (const QJsonValue val : array) { + out.append(requireIsType(val, "Document")); } - return ensureIsArrayOf(parent.value(key), default_, localWhat); + return out; } // this macro part could be replaced by variadic functions that just pass on their arguments, but that wouldn't work well with IDE helpers @@ -251,7 +202,7 @@ QList ensureIsArrayOf(const QJsonObject& parent, inline TYPE require##NAME(const QJsonObject& parent, const QString& key, const QString& what = "__placeholder__") \ { \ return requireIsType(parent, key, what); \ - } \ + } JSON_HELPERFUNCTIONS(Array, QJsonArray) JSON_HELPERFUNCTIONS(Object, QJsonObject)