forked from mrkite/minutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.h
79 lines (69 loc) · 1.45 KB
/
json.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/** Copyright (c) 2013, Sean Kasun */
#ifndef JSON_H_
#define JSON_H_
#include <QHash>
#include <QList>
#include <memory>
class JSONHelper;
class JSONData {
public:
JSONData();
virtual ~JSONData();
virtual bool has(const QString key);
virtual JSONData *at(const QString key);
virtual JSONData *at(int index);
virtual int length();
virtual QString asString();
virtual double asNumber();
virtual bool asBool();
};
class JSONBool : public JSONData {
public:
explicit JSONBool(bool val);
bool asBool();
private:
bool data;
};
class JSONString : public JSONData {
public:
explicit JSONString(QString val);
QString asString();
private:
QString data;
};
class JSONNumber : public JSONData {
public:
explicit JSONNumber(double val);
double asNumber();
private:
double data;
};
class JSONObject : public JSONData {
public:
explicit JSONObject(JSONHelper &);
~JSONObject();
bool has(const QString key);
JSONData *at(const QString key);
private:
QHash<QString, JSONData *>children;
};
class JSONArray : public JSONData {
public:
explicit JSONArray(JSONHelper &);
~JSONArray();
JSONData *at(int index);
int length();
private:
QList<JSONData *>data;
};
class JSONParseException {
public:
JSONParseException(QString reason, QString at) :
reason(QString("%1 at %2").arg(reason).arg(at)) {}
QString reason;
};
class JSON {
public:
static std::unique_ptr<JSONData> parse(const QString data);
};
#endif // JSON_H_