From 57b75dfcf79d738b955db1815284f5baaf91d2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 3 Jun 2015 21:11:03 +0200 Subject: [PATCH] NOISSUE document exceptions a bit more --- logic/Json.h | 16 ++++++++++++++++ logic/settings/INIFile.cpp | 1 + 2 files changed, 17 insertions(+) diff --git a/logic/Json.h b/logic/Json.h index d22aa606..9f4c5445 100644 --- a/logic/Json.h +++ b/logic/Json.h @@ -23,17 +23,25 @@ enum Requirement Required }; +/// @throw FileSystemException void write(const QJsonDocument &doc, const QString &filename); +/// @throw FileSystemException void write(const QJsonObject &object, const QString &filename); +/// @throw FileSystemException void write(const QJsonArray &array, const QString &filename); + QByteArray toBinary(const QJsonObject &obj); QByteArray toBinary(const QJsonArray &array); QByteArray toText(const QJsonObject &obj); QByteArray toText(const QJsonArray &array); +/// @throw JsonException QJsonDocument ensureDocument(const QByteArray &data, const QString &what = "Document"); +/// @throw JsonException QJsonDocument ensureDocument(const QString &filename, const QString &what = "Document"); +/// @throw JsonException QJsonObject ensureObject(const QJsonDocument &doc, const QString &what = "Document"); +/// @throw JsonException QJsonArray ensureArray(const QJsonDocument &doc, const QString &what = "Document"); /////////////////// WRITING //////////////////// @@ -127,6 +135,8 @@ T ensureIsType(const QJsonValue &value, const T default_, const QString &what = } return ensureIsType(value, Required, what); } + +/// @throw JsonException template T ensureIsType(const QJsonObject &parent, const QString &key, const Requirement requirement = Required, @@ -139,6 +149,7 @@ T ensureIsType(const QJsonObject &parent, const QString &key, } return ensureIsType(parent.value(key), requirement, localWhat); } + template T ensureIsType(const QJsonObject &parent, const QString &key, const T default_, const QString &what = "__placeholder__") @@ -162,6 +173,7 @@ QList ensureIsArrayOf(const QJsonDocument &doc) } return out; } + template QList ensureIsArrayOf(const QJsonValue &value, const Requirement = Required, const QString &what = "Value") @@ -174,6 +186,7 @@ QList ensureIsArrayOf(const QJsonValue &value, const Requirement = Required, } return out; } + template QList ensureIsArrayOf(const QJsonValue &value, const QList default_, const QString &what = "Value") @@ -184,6 +197,8 @@ QList ensureIsArrayOf(const QJsonValue &value, const QList default_, } return ensureIsArrayOf(value, Required, what); } + +/// @throw JsonException template QList ensureIsArrayOf(const QJsonObject &parent, const QString &key, const Requirement requirement = Required, @@ -196,6 +211,7 @@ QList ensureIsArrayOf(const QJsonObject &parent, const QString &key, } return ensureIsArrayOf(parent.value(key), requirement, localWhat); } + template QList ensureIsArrayOf(const QJsonObject &parent, const QString &key, const QList &default_, const QString &what = "__placeholder__") diff --git a/logic/settings/INIFile.cpp b/logic/settings/INIFile.cpp index 5f39f213..69a6b87e 100644 --- a/logic/settings/INIFile.cpp +++ b/logic/settings/INIFile.cpp @@ -109,6 +109,7 @@ bool INIFile::loadFile(QString fileName) file.close(); return success; } + bool INIFile::loadFile(QByteArray file) { QTextStream in(file);