mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-12-05 01:10:12 +00:00
Remove traces of ensure helpers
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@@ -287,7 +287,7 @@ QStringList toStringList(const QString& jsonString)
|
||||
if (parseError.error != QJsonParseError::NoError || !doc.isArray())
|
||||
return {};
|
||||
try {
|
||||
return ensureIsArrayOf<QString>(doc.array(), "");
|
||||
return requireIsArrayOf<QString>(doc);
|
||||
} catch (Json::JsonException& e) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -153,18 +153,6 @@ QUrl requireIsType<QUrl>(const QJsonValue& value, const QString& what);
|
||||
|
||||
// the following functions are higher level functions, that make use of the above functions for
|
||||
// type conversion
|
||||
template <typename T>
|
||||
T ensureIsType(const QJsonValue& value, const T default_ = T(), const QString& what = "Value")
|
||||
{
|
||||
if (value.isUndefined() || value.isNull()) {
|
||||
return default_;
|
||||
}
|
||||
try {
|
||||
return requireIsType<T>(value, what);
|
||||
} catch (const JsonException&) {
|
||||
return default_;
|
||||
}
|
||||
}
|
||||
|
||||
/// @throw JsonException
|
||||
template <typename T>
|
||||
@@ -177,16 +165,6 @@ T requireIsType(const QJsonObject& parent, const QString& key, const QString& wh
|
||||
return requireIsType<T>(parent.value(key), localWhat);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
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<T>(parent.value(key), default_, localWhat);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> requireIsArrayOf(const QJsonDocument& doc)
|
||||
{
|
||||
@@ -198,26 +176,6 @@ QList<T> requireIsArrayOf(const QJsonDocument& doc)
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> ensureIsArrayOf(const QJsonValue& value, const QString& what = "Value")
|
||||
{
|
||||
const QJsonArray array = ensureIsType<QJsonArray>(value, QJsonArray(), what);
|
||||
QList<T> out;
|
||||
for (const QJsonValue val : array) {
|
||||
out.append(requireIsType<T>(val, what));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> ensureIsArrayOf(const QJsonValue& value, const QList<T> default_, const QString& what = "Value")
|
||||
{
|
||||
if (value.isUndefined()) {
|
||||
return default_;
|
||||
}
|
||||
return ensureIsArrayOf<T>(value, what);
|
||||
}
|
||||
|
||||
/// @throw JsonException
|
||||
template <typename T>
|
||||
QList<T> requireIsArrayOf(const QJsonObject& parent, const QString& key, const QString& what = "__placeholder__")
|
||||
@@ -226,20 +184,13 @@ QList<T> requireIsArrayOf(const QJsonObject& parent, const QString& key, const Q
|
||||
if (!parent.contains(key)) {
|
||||
throw JsonException(localWhat + "s parent does not contain " + localWhat);
|
||||
}
|
||||
return ensureIsArrayOf<T>(parent.value(key), localWhat);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QList<T> ensureIsArrayOf(const QJsonObject& parent,
|
||||
const QString& key,
|
||||
const QList<T>& default_ = QList<T>(),
|
||||
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<T> out;
|
||||
for (const QJsonValue val : array) {
|
||||
out.append(requireIsType<T>(val, "Document"));
|
||||
}
|
||||
return ensureIsArrayOf<T>(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<T> ensureIsArrayOf(const QJsonObject& parent,
|
||||
inline TYPE require##NAME(const QJsonObject& parent, const QString& key, const QString& what = "__placeholder__") \
|
||||
{ \
|
||||
return requireIsType<TYPE>(parent, key, what); \
|
||||
} \
|
||||
}
|
||||
|
||||
JSON_HELPERFUNCTIONS(Array, QJsonArray)
|
||||
JSON_HELPERFUNCTIONS(Object, QJsonObject)
|
||||
|
||||
Reference in New Issue
Block a user