5
#include <wx/variant.h>
6
#include <wx/filename.h>
11
#include <wx/colour.h>
13
//////////////////////////////////////////////////////////////////////////
14
//////////////////////////////////////////////////////////////////////////
27
typedef std::map<wxString, wxString> wxStringMap_t;
30
JSONElement(cJSON *json);
31
JSONElement(const wxString &name, const wxVariant& val, int type);
33
virtual ~JSONElement() {}
36
////////////////////////////////////////////////
37
void setName(const wxString& _name) {
40
void setType(int _type) {
46
const wxString& getName() const {
49
const wxVariant& getValue() const {
52
void setValue(const wxVariant& _value) {
53
this->_value = _value;
56
////////////////////////////////////////////////
57
JSONElement namedObject(const wxString& name) const ;
58
bool hasNamedObject(const wxString &name) const;
60
bool toBool(bool defaultValue = false) const ;
61
wxString toString(const wxString &defaultValue = wxEmptyString) const ;
62
wxArrayString toArrayString() const ;
63
JSONElement arrayItem(int pos) const ;
66
bool isString() const ;
67
wxString format() const ;
68
int arraySize() const ;
69
int toInt(int defaultVal = -1) const ;
70
size_t toSize_t(size_t defaultVal = 0) const ;
71
double toDouble(double defaultVal = -1.0) const;
72
wxSize toSize() const;
73
wxPoint toPoint() const;
74
wxColour toColour(const wxColour& defaultColour = wxNullColour) const;
75
JSONElement::wxStringMap_t toStringMap() const;
79
////////////////////////////////////////////////
81
* @brief create new named object and append it to this json element
82
* @return the newly created object
84
static JSONElement createObject(const wxString &name = wxT(""));
86
* @brief create new named array and append it to this json element
87
* @return the newly created array
89
static JSONElement createArray(const wxString &name = wxT(""));
92
* @brief append new element to this json element
94
void append(const JSONElement& element);
96
JSONElement& addProperty(const wxString &name, const wxString &value);
97
JSONElement& addProperty(const wxString& name, const wxChar* value);
98
JSONElement& addProperty(const wxString &name, int value);
99
JSONElement& addProperty(const wxString &name, size_t value);
100
JSONElement& addProperty(const wxString &name, bool value);
101
JSONElement& addProperty(const wxString &name, const wxSize& sz);
102
JSONElement& addProperty(const wxString &name, const wxPoint& pt);
103
JSONElement& addProperty(const wxString &name, const wxColour& colour);
104
JSONElement& addProperty(const wxString &name, const wxArrayString &arr);
105
JSONElement& addProperty(const wxString &name, const JSONElement::wxStringMap_t& stringMap);
106
JSONElement& addProperty(const wxString &name, const JSONElement& element);
109
* @brief delete property by name
111
void removeProperty(const wxString &name);
113
//////////////////////////////////////////////////
115
//////////////////////////////////////////////////
118
* @brief append new number
119
* @return the newly added property
121
void arrayAppend(const JSONElement& element);
122
void arrayAppend(const wxString &value);
125
return _json != NULL;
129
//////////////////////////////////////////////////////////////////////////
130
//////////////////////////////////////////////////////////////////////////
135
wxString _errorString;
139
JSONRoot(const wxString& text);
140
JSONRoot(const wxFileName& filename);
143
void save(const wxFileName &fn) const;
144
wxString errorString() const;
146
return _json != NULL;
149
JSONElement toElement() const;
154
// Make this class not copyable
155
JSONRoot(const JSONRoot& src);
156
JSONRoot& operator=(const JSONRoot& src);
160
#endif // ZJSONNODE_H