From 28ad9befdcac246eb69a434be970abc29a80bc80 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 2 Mar 2014 19:12:04 +0100 Subject: Remove a lot of error code and error handling madness. --- logic/MMCJson.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 logic/MMCJson.h (limited to 'logic/MMCJson.h') diff --git a/logic/MMCJson.h b/logic/MMCJson.h new file mode 100644 index 00000000..3e7342b5 --- /dev/null +++ b/logic/MMCJson.h @@ -0,0 +1,46 @@ +/** + * Some de-bullshitting for Qt JSON failures. + * + * Simple exception-throwing + */ + +#pragma once +#include +#include +#include +#include "MMCError.h" + +class JSONValidationError : public MMCError +{ +public: + JSONValidationError(QString cause) : MMCError(cause) {}; + virtual QString errorName() + { + return "JSONValidationError"; + }; + virtual ~JSONValidationError() {}; +}; + +namespace MMCJson +{ +/// make sure the value exists. throw otherwise. +QJsonValue ensureExists(QJsonValue val, const QString what = "value"); + +/// make sure the value is converted into an object. throw otherwise. +QJsonObject ensureObject(const QJsonValue val, const QString what = "value"); + +/// make sure the value is converted into an array. throw otherwise. +QJsonArray ensureArray(const QJsonValue val, QString what = "value"); + +/// make sure the value is converted into a string. throw otherwise. +QString ensureString(const QJsonValue val, QString what = "value"); + +/// make sure the value is converted into a boolean. throw otherwise. +bool ensureBoolean(const QJsonValue val, QString what = "value"); + +/// make sure the value is converted into an integer. throw otherwise. +int ensureInteger(const QJsonValue val, QString what = "value"); + +/// make sure the value is converted into a double precision floating number. throw otherwise. +double ensureDouble(const QJsonValue val, QString what = "value"); +} -- cgit From 47bc7e5ee377dacfeb7cf3d13f07cfd24db906fb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 5 Mar 2014 01:50:05 +0100 Subject: More refactor. --- logic/MMCJson.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'logic/MMCJson.h') diff --git a/logic/MMCJson.h b/logic/MMCJson.h index 3e7342b5..b0d898fc 100644 --- a/logic/MMCJson.h +++ b/logic/MMCJson.h @@ -7,6 +7,7 @@ #pragma once #include #include +#include #include #include "MMCError.h" @@ -29,6 +30,9 @@ QJsonValue ensureExists(QJsonValue val, const QString what = "value"); /// make sure the value is converted into an object. throw otherwise. QJsonObject ensureObject(const QJsonValue val, const QString what = "value"); +/// make sure the document is converted into an object. throw otherwise. +QJsonObject ensureObject(const QJsonDocument val, const QString what = "value"); + /// make sure the value is converted into an array. throw otherwise. QJsonArray ensureArray(const QJsonValue val, QString what = "value"); -- cgit From b2c803a378695026f12aabc3729eb2139bee1b2c Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 9 Mar 2014 23:42:25 +0100 Subject: Improve reporting of version file errors.x --- logic/MMCJson.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'logic/MMCJson.h') diff --git a/logic/MMCJson.h b/logic/MMCJson.h index b0d898fc..f2cc4b31 100644 --- a/logic/MMCJson.h +++ b/logic/MMCJson.h @@ -15,10 +15,6 @@ class JSONValidationError : public MMCError { public: JSONValidationError(QString cause) : MMCError(cause) {}; - virtual QString errorName() - { - return "JSONValidationError"; - }; virtual ~JSONValidationError() {}; }; -- cgit From d11f10ea1ed54336254838ff068258d2d42e0774 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 10 Mar 2014 18:55:54 +0100 Subject: Fix a compiling error by adding noexcept --- logic/MMCJson.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'logic/MMCJson.h') diff --git a/logic/MMCJson.h b/logic/MMCJson.h index f2cc4b31..71ded435 100644 --- a/logic/MMCJson.h +++ b/logic/MMCJson.h @@ -15,7 +15,7 @@ class JSONValidationError : public MMCError { public: JSONValidationError(QString cause) : MMCError(cause) {}; - virtual ~JSONValidationError() {}; + virtual ~JSONValidationError() noexcept {} }; namespace MMCJson -- cgit