diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-03-02 19:12:04 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-03-02 19:12:04 +0100 |
commit | 28ad9befdcac246eb69a434be970abc29a80bc80 (patch) | |
tree | 330451feee32c4163b02132076491ad4fd311e9b /logic/MMCJson.cpp | |
parent | 80d146866c8c5f00c6d790b476a774def71010bf (diff) | |
download | MultiMC-28ad9befdcac246eb69a434be970abc29a80bc80.tar MultiMC-28ad9befdcac246eb69a434be970abc29a80bc80.tar.gz MultiMC-28ad9befdcac246eb69a434be970abc29a80bc80.tar.lz MultiMC-28ad9befdcac246eb69a434be970abc29a80bc80.tar.xz MultiMC-28ad9befdcac246eb69a434be970abc29a80bc80.zip |
Remove a lot of error code and error handling madness.
Diffstat (limited to 'logic/MMCJson.cpp')
-rw-r--r-- | logic/MMCJson.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/logic/MMCJson.cpp b/logic/MMCJson.cpp new file mode 100644 index 00000000..14cde0c1 --- /dev/null +++ b/logic/MMCJson.cpp @@ -0,0 +1,53 @@ +#include "MMCJson.h" +#include <QString> + +bool MMCJson::ensureBoolean(const QJsonValue val, const QString what) +{ + if (!val.isBool()) + throw JSONValidationError(what + " is not boolean"); + return val.isBool(); +} + +QJsonValue MMCJson::ensureExists(QJsonValue val, const QString what) +{ + if(val.isNull()) + throw JSONValidationError(what + " does not exist"); + return val; +} + +QJsonArray MMCJson::ensureArray(const QJsonValue val, const QString what) +{ + if (!val.isArray()) + throw JSONValidationError(what + " is not an array"); + return val.toArray(); +} + +double MMCJson::ensureDouble(const QJsonValue val, const QString what) +{ + if (!val.isDouble()) + throw JSONValidationError(what + " is not a number"); + double ret = val.toDouble(); +} + +int MMCJson::ensureInteger(const QJsonValue val, const QString what) +{ + double ret = ensureDouble(val, what); + if (fmod(ret, 1) != 0) + throw JSONValidationError(what + " is not an integer"); + return ret; +} + +QJsonObject MMCJson::ensureObject(const QJsonValue val, const QString what) +{ + if (!val.isObject()) + throw JSONValidationError(what + " is not an object"); + return val.toObject(); +} + +QString MMCJson::ensureString(const QJsonValue val, const QString what) +{ + if (!val.isString()) + throw JSONValidationError(what + " is not a string"); + return val.toString(); +} + |