20#include <wx/hashmap.h>
21#include <wx/dynarray.h>
31#if defined(wxJSON_USE_STL)
35WX_DECLARE_OBJARRAY(
wxJSONValue, wxJSONInternalArray);
36WX_DECLARE_STRING_HASH_MAP(
wxJSONValue, wxJSONInternalMap);
38class WXDLLIMPEXP_JSON wxJSONInternalMap;
39class WXDLLIMPEXP_JSON wxJSONInternalArray;
44 wxJSONTYPE_INVALID = 0,
66 wxJSONVALUE_COMMENT_DEFAULT = 0,
67 wxJSONVALUE_COMMENT_BEFORE,
68 wxJSONVALUE_COMMENT_AFTER,
69 wxJSONVALUE_COMMENT_INLINE,
80 friend class wxJSONReader;
92#if defined(wxJSON_64BIT_INT)
115#if defined(wxJSON_64BIT_INT)
116 bool IsInt32()
const;
117 bool IsInt64()
const;
118 bool IsUInt32()
const;
119 bool IsUInt64()
const;
131 unsigned int AsUInt()
const;
136 bool AsInt(
int& i)
const;
137 bool AsUInt(
unsigned int& ui)
const;
138 bool AsShort(
short int& s)
const;
139 bool AsUShort(
unsigned short& us)
const;
140 bool AsLong(
long int& l)
const;
141 bool AsULong(
unsigned long& ul)
const;
142#if defined(wxJSON_64BIT_INT)
143 wxInt32 AsInt32()
const;
144 wxUint32 AsUInt32()
const;
145 wxInt64 AsInt64()
const;
146 wxUint64 AsUInt64()
const;
147 bool AsInt32(wxInt32& i32)
const;
148 bool AsUInt32(wxUint32& ui32)
const;
149 bool AsInt64(wxInt64& i64)
const;
150 bool AsUInt64(wxUint64& ui64)
const;
156 bool AsBool(
bool& b)
const;
163 const wxJSONInternalMap*
AsMap()
const;
164 const wxJSONInternalArray*
AsArray()
const;
168 bool HasMember(
const wxString& key)
const;
181#if defined(wxJSON_64BIT_INT)
191 bool Remove(
const wxString& key);
193 bool Cat(
const wxChar* str);
194 bool Cat(
const wxString& str);
195 bool Cat(
const wxMemoryBuffer& buff);
212#if defined(wxJSON_64BIT_INT)
233 int position = wxJSONVALUE_COMMENT_DEFAULT);
235 int position = wxJSONVALUE_COMMENT_DEFAULT);
244 wxString
Dump(
bool deep =
false,
int mode = 0)
const;
257 size_t actualLen = -1);
259 const wxMemoryBuffer& buff2);
285#if defined(WXJSON_USE_VALUE_COUNTER)
291#if !defined(wxJSON_USE_STL)
294WX_DECLARE_OBJARRAY(
wxJSONValue, wxJSONInternalArray);
295WX_DECLARE_STRING_HASH_MAP(
wxJSONValue, wxJSONInternalMap);
317 unsigned int m_valUInt;
318 short int m_valShort;
319 unsigned short m_valUShort;
321 unsigned long m_valULong;
323 const wxChar* m_valCString;
325#if defined(wxJSON_64BIT_INT)
327 wxUint64 m_valUInt64;
336#if defined(wxJSON_64BIT_INT)
337#define VAL_INT m_valInt64
338#define VAL_UINT m_valUInt64
340#define VAL_INT m_valLong
341#define VAL_UINT m_valULong
347 friend class wxJSONValue;
348 friend class wxJSONWriter;
354 int GetRefCount()
const;
413#if defined(WXJSON_USE_VALUE_COUNTER)
The reference counted JSON value data (internal use).
wxMemoryBuffer * m_memBuff
The pointer to the memory buffer object.
wxJSONInternalMap m_valMap
The JSON object value.
int m_commentPos
The position of the comment line(s), if any.
int m_refCount
the references count
wxJSONInternalArray m_valArray
The JSON array value.
wxJSONType m_type
The actual type of the value held by this object.
int m_lineNo
The line number when this value was read.
wxJSONRefData()
Constructor.
wxString m_valString
The JSON string value.
wxJSONValueHolder m_value
The JSON value held by this object.
wxArrayString m_comments
The array of comment lines; may be empty.
The JSON value class implementation.
bool IsSameAs(const wxJSONValue &other) const
The comparison function.
void Ref(const wxJSONValue &clone)
Increments the referenced data counter.
wxArrayString GetMemberNames() const
Return the array of keys of this JSON object.
bool IsArray() const
Return TRUE if the type of the value stored is an array type.
void UnShare()
Makes an exclusive copy of shared data.
bool Remove(int index)
Remove the item at the specified index or key.
int AddComment(const wxString &str, int position=wxJSONVALUE_COMMENT_DEFAULT)
Add a comment to this JSON value object.
virtual wxJSONRefData * CloneRefData(const wxJSONRefData *data) const
Make a copy of the referenced data.
bool IsUInt() const
Return TRUE if the type of the value stored is a unsigned int.
wxString Dump(bool deep=false, int mode=0) const
Returns informations about the object.
wxJSONRefData * Init(wxJSONType type)
Initialize the JSON value class.
long int AsLong() const
Returns the value as a long integer.
bool IsLong() const
Return TRUE if the stored value is an integer which fits in a long int.
int Size() const
Return the size of the array or map stored in this value.
int GetCommentCount() const
Return the number of comment strings.
bool HasMember(unsigned index) const
Return TRUE if the object contains an element at the specified index.
bool IsDouble() const
Return TRUE if the type of the value stored is a double.
bool IsInt() const
Return TRUE if the type of the value stored is integer.
static wxString MemoryBuffToString(const wxMemoryBuffer &buff, size_t len=-1)
Convert memory buffer object to a string representation.
bool IsShort() const
Return TRUE if the type of the value stored is 16-bit integer.
wxJSONValue Get(const wxString &key, const wxJSONValue &defaultValue) const
Return a value or a default value.
double AsDouble() const
Return the stored value as a double.
virtual wxJSONRefData * CreateRefData() const
Create a new data structure.
wxJSONType GetType() const
Return the type of the value stored in the object.
void UnRef()
Unreferences the shared data.
wxJSONValue * Find(unsigned index) const
Find an element.
void DeepCopy(const wxJSONValue &other)
Do a deep copy of the other object.
static wxMemoryBuffer ArrayToMemoryBuff(const wxJSONValue &value)
Converts an array of INTs to a memory buffer.
wxJSONValue ItemAt(unsigned index) const
Return the item at the specified index.
wxJSONRefData * COW()
Make sure the referenced data is unique.
wxString GetComment(int idx=-1) const
Return a comment string.
void SetRefData(wxJSONRefData *data)
Set the pointer to the referenced data.
bool IsString() const
Return TRUE if the type of the value stored is a wxString object.
void ClearComments()
Clear all comment strings.
bool IsUShort() const
Return TRUE if the type of the value stored is a unsigned short.
const wxJSONInternalMap * AsMap() const
Return the stored value as a map object.
const wxChar * AsCString() const
Return the stored value as a pointer to a static C string.
wxJSONValue & operator[](unsigned index)
Return the item at the specified index.
static int CompareMemoryBuff(const wxMemoryBuffer &buff1, const wxMemoryBuffer &buff2)
Compares two memory buffer objects.
wxJSONValue & Append(const wxJSONValue &value)
Append the specified value in the array.
bool IsBool() const
Return TRUE if the type of the value stored is a boolean.
unsigned int AsUInt() const
Return the stored value as a unsigned int.
unsigned short AsUShort() const
Returns the value as a unsigned short integer.
void AllocExclusive()
Makes a private copy of the referenced data.
wxJSONValue()
Constructors.
wxString AsString() const
Return the stored value as a wxWidget's string.
void Clear()
Clear the object value.
int GetLineNo() const
Return the line number of this JSON value object.
bool IsValid() const
Return TRUE if the value stored is valid.
bool IsMemoryBuff() const
Return TRUE if the type of this value is a binary memory buffer.
short AsShort() const
Returns the value as a short integer.
wxString GetInfo() const
Returns informations about the object.
bool IsNull() const
Return TRUE if the type of the value is wxJSONTYPE_NULL.
void SetLineNo(int num)
Set the line number of this JSON value object.
bool IsObject() const
Return TRUE if the type of this value is a key/value map.
unsigned long AsULong() const
Returns the value as a unsigned long integer.
bool AsBool() const
Return the stored value as a boolean.
wxJSONRefData * SetType(wxJSONType type)
Set the type of the stored value.
int GetCommentPos() const
Return the comment position.
wxJSONRefData * m_refData
the referenced data
wxJSONValue & operator=(int i)
Assign the specified value to this object replacing the old value.
wxJSONValue & Item(unsigned index)
Return the item at the specified index.
int AsInt() const
Return the stored value as an integer.
const wxJSONInternalArray * AsArray() const
Return the stored value as an array object.
wxMemoryBuffer AsMemoryBuff() const
Returns the value as a memory buffer.
const wxArrayString & GetCommentArray() const
Get the comment string's array.
wxJSONRefData * GetRefData() const
Return the pointer to the referenced data structure.
static wxString TypeToString(wxJSONType type)
Return a string description of the type.
JSON Configuration System Definitions.
The actual value held by the wxJSONValue class (internal use).