2014-03-02 23:42:04 +05:30
|
|
|
/**
|
|
|
|
* Some de-bullshitting for Qt JSON failures.
|
|
|
|
*
|
|
|
|
* Simple exception-throwing
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <QJsonValue>
|
|
|
|
#include <QJsonObject>
|
2014-03-05 06:20:05 +05:30
|
|
|
#include <QJsonDocument>
|
2014-03-02 23:42:04 +05:30
|
|
|
#include <QJsonArray>
|
|
|
|
#include "MMCError.h"
|
|
|
|
|
|
|
|
class JSONValidationError : public MMCError
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
JSONValidationError(QString cause) : MMCError(cause) {};
|
2014-03-10 23:25:54 +05:30
|
|
|
virtual ~JSONValidationError() noexcept {}
|
2014-03-02 23:42:04 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2014-03-05 06:20:05 +05:30
|
|
|
/// make sure the document is converted into an object. throw otherwise.
|
|
|
|
QJsonObject ensureObject(const QJsonDocument val, const QString what = "value");
|
|
|
|
|
2014-03-02 23:42:04 +05:30
|
|
|
/// 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");
|
|
|
|
}
|