From e044744fafe4d0c088446b7cd57ae788d5e3a645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 20 Nov 2022 15:59:05 +0100 Subject: [PATCH] NOISSUE add a way to require object from Json value ref --- launcher/Json.cpp | 8 ++++++++ launcher/Json.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/launcher/Json.cpp b/launcher/Json.cpp index 37ada1aa..8f6908d3 100644 --- a/launcher/Json.cpp +++ b/launcher/Json.cpp @@ -78,6 +78,14 @@ QJsonObject requireObject(const QJsonDocument &doc, const QString &what) } return doc.object(); } +QJsonObject requireObject(const QJsonValueRef &node, const QString &what) +{ + if (!node.isObject()) + { + throw JsonException(what + " is not an object"); + } + return node.toObject(); +} QJsonArray requireArray(const QJsonDocument &doc, const QString &what) { if (!doc.isArray()) diff --git a/launcher/Json.h b/launcher/Json.h index dd70bf56..359f4757 100644 --- a/launcher/Json.h +++ b/launcher/Json.h @@ -41,6 +41,8 @@ QJsonDocument requireDocument(const QString &filename, const QString &what = "Do /// @throw JsonException QJsonObject requireObject(const QJsonDocument &doc, const QString &what = "Document"); /// @throw JsonException +QJsonObject requireObject(const QJsonValueRef &node, const QString &what = "Node"); +/// @throw JsonException QJsonArray requireArray(const QJsonDocument &doc, const QString &what = "Document"); /////////////////// WRITING ////////////////////