Remove a lot of error code and error handling madness.
This commit is contained in:
46
logic/MMCJson.h
Normal file
46
logic/MMCJson.h
Normal file
@ -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");
|
||||
}
|
Reference in New Issue
Block a user