10#if !defined(_WX_JSONVAL_H)
14#pragma interface "jsonval.h"
21#include <wx/hashmap.h>
22#include <wx/dynarray.h>
32#if defined(wxJSON_USE_STL)
36WX_DECLARE_OBJARRAY(
wxJSONValue, wxJSONInternalArray);
37WX_DECLARE_STRING_HASH_MAP(
wxJSONValue, wxJSONInternalMap);
39class WXDLLIMPEXP_JSON wxJSONInternalMap;
40class WXDLLIMPEXP_JSON wxJSONInternalArray;
45 wxJSONTYPE_INVALID = 0,
67 wxJSONVALUE_COMMENT_DEFAULT = 0,
68 wxJSONVALUE_COMMENT_BEFORE,
69 wxJSONVALUE_COMMENT_AFTER,
70 wxJSONVALUE_COMMENT_INLINE,
81 friend class wxJSONReader;
86 wxJSONValue(wxJSONType type);
88 wxJSONValue(
unsigned int i);
90 wxJSONValue(
unsigned short i);
91 wxJSONValue(
long int i);
92 wxJSONValue(
unsigned long int i);
93#if defined(wxJSON_64BIT_INT)
94 wxJSONValue(wxInt64 i);
95 wxJSONValue(wxUint64 ui);
98 wxJSONValue(
double d);
99 wxJSONValue(
const wxChar* str);
100 wxJSONValue(
const wxString& str);
101 wxJSONValue(
const wxMemoryBuffer& buff);
102 wxJSONValue(
const void* buff,
size_t len);
103 wxJSONValue(
const wxJSONValue& other);
104 virtual ~wxJSONValue();
107 wxJSONType GetType()
const;
108 bool IsValid()
const;
112 bool IsShort()
const;
113 bool IsUShort()
const;
115 bool IsULong()
const;
116#if defined(wxJSON_64BIT_INT)
117 bool IsInt32()
const;
118 bool IsInt64()
const;
119 bool IsUInt32()
const;
120 bool IsUInt64()
const;
123 bool IsDouble()
const;
124 bool IsString()
const;
125 bool IsCString()
const;
126 bool IsArray()
const;
127 bool IsObject()
const;
128 bool IsMemoryBuff()
const;
132 unsigned int AsUInt()
const;
133 short AsShort()
const;
134 unsigned short AsUShort()
const;
135 long int AsLong()
const;
136 unsigned long AsULong()
const;
137 bool AsInt(
int& i)
const;
138 bool AsUInt(
unsigned int& ui)
const;
139 bool AsShort(
short int& s)
const;
140 bool AsUShort(
unsigned short& us)
const;
141 bool AsLong(
long int& l)
const;
142 bool AsULong(
unsigned long& ul)
const;
143#if defined(wxJSON_64BIT_INT)
144 wxInt32 AsInt32()
const;
145 wxUint32 AsUInt32()
const;
146 wxInt64 AsInt64()
const;
147 wxUint64 AsUInt64()
const;
148 bool AsInt32(wxInt32& i32)
const;
149 bool AsUInt32(wxUint32& ui32)
const;
150 bool AsInt64(wxInt64& i64)
const;
151 bool AsUInt64(wxUint64& ui64)
const;
154 double AsDouble()
const;
155 wxString AsString()
const;
156 const wxChar* AsCString()
const;
157 bool AsBool(
bool& b)
const;
158 bool AsDouble(
double& d)
const;
159 bool AsString(wxString& str)
const;
160 bool AsCString(wxChar* ch)
const;
161 wxMemoryBuffer AsMemoryBuff()
const;
162 bool AsMemoryBuff(wxMemoryBuffer& buff)
const;
164 const wxJSONInternalMap* AsMap()
const;
165 const wxJSONInternalArray* AsArray()
const;
168 bool HasMember(
unsigned index)
const;
169 bool HasMember(
const wxString& key)
const;
171 wxArrayString GetMemberNames()
const;
174 wxJSONValue& Append(
const wxJSONValue& value);
175 wxJSONValue& Append(
bool b);
176 wxJSONValue& Append(
int i);
177 wxJSONValue& Append(
unsigned int ui);
178 wxJSONValue& Append(
short int i);
179 wxJSONValue& Append(
unsigned short int ui);
180 wxJSONValue& Append(
long int l);
181 wxJSONValue& Append(
unsigned long int ul);
182#if defined(wxJSON_64BIT_INT)
183 wxJSONValue& Append(wxInt64 i);
184 wxJSONValue& Append(wxUint64 ui);
186 wxJSONValue& Append(
double d);
187 wxJSONValue& Append(
const wxChar* str);
188 wxJSONValue& Append(
const wxString& str);
189 wxJSONValue& Append(
const wxMemoryBuffer& buff);
190 wxJSONValue& Append(
const void* buff,
size_t len);
192 bool Remove(
const wxString& key);
194 bool Cat(
const wxChar* str);
195 bool Cat(
const wxString& str);
196 bool Cat(
const wxMemoryBuffer& buff);
199 wxJSONValue& Item(
unsigned index);
200 wxJSONValue& Item(
const wxString& key);
201 wxJSONValue ItemAt(
unsigned index)
const;
202 wxJSONValue ItemAt(
const wxString& key)
const;
204 wxJSONValue& operator[](
unsigned index);
205 wxJSONValue& operator[](
const wxString& key);
207 wxJSONValue& operator=(
int i);
208 wxJSONValue& operator=(
unsigned int ui);
209 wxJSONValue& operator=(
short int i);
210 wxJSONValue& operator=(
unsigned short int ui);
211 wxJSONValue& operator=(
long int l);
212 wxJSONValue& operator=(
unsigned long int ul);
213#if defined(wxJSON_64BIT_INT)
214 wxJSONValue& operator=(wxInt64 i);
215 wxJSONValue& operator=(wxUint64 ui);
217 wxJSONValue& operator=(
bool b);
218 wxJSONValue& operator=(
double d);
219 wxJSONValue& operator=(
const wxChar* str);
220 wxJSONValue& operator=(
const wxString& str);
221 wxJSONValue& operator=(
const wxMemoryBuffer& buff);
224 wxJSONValue& operator=(
const wxJSONValue& value);
227 wxJSONValue Get(
const wxString& key,
const wxJSONValue& defaultValue)
const;
230 bool IsSameAs(
const wxJSONValue& other)
const;
233 int AddComment(
const wxString& str,
234 int position = wxJSONVALUE_COMMENT_DEFAULT);
235 int AddComment(
const wxArrayString& comments,
236 int position = wxJSONVALUE_COMMENT_DEFAULT);
237 wxString GetComment(
int idx = -1)
const;
238 int GetCommentPos()
const;
239 int GetCommentCount()
const;
240 void ClearComments();
241 const wxArrayString& GetCommentArray()
const;
244 wxString GetInfo()
const;
245 wxString Dump(
bool deep =
false,
int mode = 0)
const;
248 wxJSONRefData* GetRefData()
const;
249 wxJSONRefData* SetType(wxJSONType type);
250 int GetLineNo()
const;
251 void SetLineNo(
int num);
254 static wxString TypeToString(wxJSONType type);
255 static wxString MemoryBuffToString(
const wxMemoryBuffer& buff,
257 static wxString MemoryBuffToString(
const void* buff,
size_t len,
258 size_t actualLen = -1);
259 static int CompareMemoryBuff(
const wxMemoryBuffer& buff1,
260 const wxMemoryBuffer& buff2);
261 static int CompareMemoryBuff(
const wxMemoryBuffer& buff1,
const void* buff2);
262 static wxMemoryBuffer ArrayToMemoryBuff(
const wxJSONValue& value);
265 wxJSONValue* Find(
unsigned index)
const;
266 wxJSONValue* Find(
const wxString& key)
const;
267 void DeepCopy(
const wxJSONValue& other);
269 wxJSONRefData* Init(wxJSONType type);
270 wxJSONRefData* COW();
273 virtual wxJSONRefData* CloneRefData(
const wxJSONRefData* data)
const;
274 virtual wxJSONRefData* CreateRefData()
const;
276 void SetRefData(wxJSONRefData* data);
277 void Ref(
const wxJSONValue& clone);
280 void AllocExclusive();
283 wxJSONRefData* m_refData;
286#if defined(WXJSON_USE_VALUE_COUNTER)
292#if !defined(wxJSON_USE_STL)
295WX_DECLARE_OBJARRAY(
wxJSONValue, wxJSONInternalArray);
296WX_DECLARE_STRING_HASH_MAP(
wxJSONValue, wxJSONInternalMap);
318 unsigned int m_valUInt;
319 short int m_valShort;
320 unsigned short m_valUShort;
322 unsigned long m_valULong;
324 const wxChar* m_valCString;
326#if defined(wxJSON_64BIT_INT)
328 wxUint64 m_valUInt64;
337#if defined(wxJSON_64BIT_INT)
338#define VAL_INT m_valInt64
339#define VAL_UINT m_valUInt64
341#define VAL_INT m_valLong
342#define VAL_UINT m_valULong
348 friend class wxJSONValue;
349 friend class wxJSONWriter;
353 virtual ~wxJSONRefData();
355 int GetRefCount()
const;
372 wxJSONValueHolder m_value;
375 wxString m_valString;
378 wxJSONInternalArray m_valArray;
381 wxJSONInternalMap m_valMap;
393 wxArrayString m_comments;
411 wxMemoryBuffer* m_memBuff;
414#if defined(WXJSON_USE_VALUE_COUNTER)
The reference counted JSON value data (internal use).
The JSON value class implementation.
bool Remove(const std::string &name)
Remove a filter, return ok if no errors.
The actual value held by the wxJSONValue class (internal use).