-
Notifications
You must be signed in to change notification settings - Fork 1
/
Element.h
76 lines (52 loc) · 1.51 KB
/
Element.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
#ifndef ELEMENT_H
#define ELEMENT_H
#include <QObject>
#include <Value.h>
#include <QVector>
namespace Json
{
struct Key
{
int key_int;
QString key_string;
};
class Element : public QObject
{
Q_OBJECT
friend class Parser;
public:
explicit Element(QObject *parent = 0);
explicit Element(const Element &other);
~Element();
const Key &key() const { return __key; }
const QVariant &value() const { return __value.get(); }
int toInt() const { return __value.get().toInt(); }
QString toString() const { return __value.get().toString(); }
const char * toCharArray() const { return __value.get().toString().toLatin1().constData(); }
Element &operator [] (QString key);
Element &operator [] (const char *key);
Element &operator [] (int key);
QVariant &operator() (int index) { return __value[index]; }
void operator = (const int value);
void operator = (const QString &value);
void operator = (const double value);
void operator = (const bool value);
void operator = (const Element &value);
void operator += (const int value);
void operator += (const char *value);
void operator += (const double value);
operator int() { return __value.get().toInt(); }
operator QString() { return __value.get().toString(); }
operator bool() { return __value.get().toBool(); }
int count() { return __elements.count(); }
signals:
public slots:
private:
Key __key;
Value __value;
QVector<Element *> __elements;
QVector<QString> __keys;
};
}
Q_DECLARE_METATYPE(Json::Element)
#endif // ELEMENT_H