summaryrefslogtreecommitdiffstats
path: root/logic/MMCJson.h
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-03-02 19:12:04 +0100
committerPetr Mrázek <peterix@gmail.com>2014-03-02 19:12:04 +0100
commit28ad9befdcac246eb69a434be970abc29a80bc80 (patch)
tree330451feee32c4163b02132076491ad4fd311e9b /logic/MMCJson.h
parent80d146866c8c5f00c6d790b476a774def71010bf (diff)
downloadMultiMC-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.h')
-rw-r--r--logic/MMCJson.h46
1 files changed, 46 insertions, 0 deletions
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 <QJsonValue>
+#include <QJsonObject>
+#include <QJsonArray>
+#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");
+}