diff options
author | Jan Dalheimer <jan@dalheimer.de> | 2014-03-10 19:24:29 +0100 |
---|---|---|
committer | Jan Dalheimer <jan@dalheimer.de> | 2014-03-10 19:24:29 +0100 |
commit | fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb (patch) | |
tree | 851d8f8b6e6734e26fd2e4dc7b7477630329ff01 /logic/MMCJson.cpp | |
parent | 73fc9c79cff979e9023df0b1a77848c67b590681 (diff) | |
parent | d11f10ea1ed54336254838ff068258d2d42e0774 (diff) | |
download | MultiMC-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.tar MultiMC-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.tar.gz MultiMC-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.tar.lz MultiMC-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.tar.xz MultiMC-fcc5bc2ce0a1c8c3f9df9230710dd60363eb5cdb.zip |
Merge branch 'develop' into feature_badges
Conflicts:
logic/OneSixInstance.cpp
Diffstat (limited to 'logic/MMCJson.cpp')
-rw-r--r-- | logic/MMCJson.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/logic/MMCJson.cpp b/logic/MMCJson.cpp new file mode 100644 index 00000000..25cc2de3 --- /dev/null +++ b/logic/MMCJson.cpp @@ -0,0 +1,61 @@ +#include "MMCJson.h" +#include <QString> +#include <math.h> + +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(); +} + +QJsonObject MMCJson::ensureObject(const QJsonDocument val, const QString what) +{ + if (!val.isObject()) + throw JSONValidationError(what + " is not an object"); + return val.object(); +} + +QString MMCJson::ensureString(const QJsonValue val, const QString what) +{ + if (!val.isString()) + throw JSONValidationError(what + " is not a string"); + return val.toString(); +} + |