wxJSONValue Class Reference

The JSON value class implementation. More...

#include <jsonval.h>

List of all members.

Public Member Functions

 wxJSONValue ()
 Constructors.
 wxJSONValue (wxJSONType type)
 wxJSONValue (int i)
 wxJSONValue (unsigned int i)
 wxJSONValue (short i)
 wxJSONValue (unsigned short i)
 wxJSONValue (long int i)
 wxJSONValue (unsigned long int i)
 wxJSONValue (wxInt64 i)
 wxJSONValue (wxUint64 ui)
 wxJSONValue (bool b)
 wxJSONValue (double d)
 wxJSONValue (const wxChar *str)
 wxJSONValue (const wxString &str)
 wxJSONValue (const wxJSONValue &other)
 Copy constructor.
virtual ~wxJSONValue ()
 Dtor - calls UnRef().
wxJSONType GetType () const
 Return the type of the value stored in the object.
bool IsValid () const
 Return TRUE if the value stored is valid.
bool IsNull () const
 Return TRUE if the type of the value is wxJSONTYPE_NULL.
bool IsInt () const
 Return TRUE if the type of the value stored is integer.
bool IsUInt () const
 Return TRUE if the type of the value stored is a unsigned int.
bool IsShort () const
 Return TRUE if the type of the value stored is 16-bit integer.
bool IsUShort () const
 Return TRUE if the type of the value stored is a unsigned short.
bool IsLong () const
 Return TRUE if the stored value is an integer which fits in a long int.
bool IsULong () const
 Return TRUE if the stored value is an integer which fits in a unsigned long int.
bool IsInt32 () const
 Return TRUE if the stored value is a 32-bits integer.
bool IsInt64 () const
 Return TRUE if the stored value is integer.
bool IsUInt32 () const
 Return TRUE if the stored value is a unsigned 32-bits integer.
bool IsUInt64 () const
 Return TRUE if the stored value is a unsigned integer.
bool IsBool () const
 Return TRUE if the type of the value stored is a boolean.
bool IsDouble () const
 Return TRUE if the type of the value stored is a double.
bool IsString () const
 Return TRUE if the type of the value stored is a wxString object.
bool IsCString () const
 Return TRUE if the type of the value stored is a pointer to a static C string.
bool IsArray () const
 Return TRUE if the type of the value stored is an array type.
bool IsObject () const
 Return TRUE if the type of this value is a key/value map.
int AsInt () const
 Return the stored value as an integer.
unsigned int AsUInt () const
 Return the stored value as a unsigned int.
short AsShort () const
 Returns the value as a short integer.
unsigned short AsUShort () const
 Returns the value as a unsigned short integer.
long int AsLong () const
 Returns the value as a long integer.
unsigned long AsULong () const
 Returns the value as a unsigned long integer.
wxInt32 AsInt32 () const
 Returns the low-order 32 bits of the value as an integer.
wxUint32 AsUInt32 () const
 Returns the low-order 32 bits of the value as an unsigned integer.
wxInt64 AsInt64 () const
 Return the numeric value as a 64-bit integer.
wxUint64 AsUInt64 () const
 Return the numeric value as a 64-bit unsigned integer.
bool AsBool () const
 Return the stored value as a boolean.
double AsDouble () const
 Return the stored value as a double.
wxString AsString () const
 Return the stored value as a wxWidget's string.
const wxChar * AsCString () const
 Return the stored value as a pointer to a static C string.
const wxJSONInternalMapAsMap () const
 Return the stored value as a map object.
const wxJSONInternalArrayAsArray () const
 Return the stored value as an array object.
bool HasMember (unsigned index) const
 Return TRUE if the object contains an element at the specified index.
bool HasMember (const wxString &key) const
 Return TRUE if the object contains an element at the specified key.
int Size () const
 Return the size of the array or map stored in this value.
wxArrayString GetMemberNames () const
 Return the array of keys of this JSON object.
wxJSONValueAppend (const wxJSONValue &value)
 Append the specified value in the array.
wxJSONValueAppend (bool b)
wxJSONValueAppend (int i)
wxJSONValueAppend (unsigned int ui)
wxJSONValueAppend (short int i)
wxJSONValueAppend (unsigned short int ui)
wxJSONValueAppend (long int l)
wxJSONValueAppend (unsigned long int ul)
wxJSONValueAppend (wxInt64 i)
wxJSONValueAppend (wxUint64 ui)
wxJSONValueAppend (double d)
wxJSONValueAppend (const wxChar *str)
wxJSONValueAppend (const wxString &str)
bool Remove (int index)
 Remove the item at the specified index or key.
bool Remove (const wxString &key)
void Clear ()
 Clear the object value.
bool Cat (const wxChar *str)
bool Cat (const wxString &str)
 Concatenate a string to this string object.
wxJSONValueItem (unsigned index)
 Return the item at the specified index.
wxJSONValueItem (const wxString &key)
 Return the item at the specified key.
wxJSONValue ItemAt (unsigned index) const
 Return the item at the specified index.
wxJSONValue ItemAt (const wxString &key) const
 Return the item at the specified key.
wxJSONValueoperator[] (unsigned index)
 Return the item at the specified index.
wxJSONValueoperator[] (const wxString &key)
 Return the item at the specified key.
wxJSONValueoperator= (int i)
 Assign the specified value to this object replacing the old value.
wxJSONValueoperator= (unsigned int ui)
wxJSONValueoperator= (short int i)
wxJSONValueoperator= (unsigned short int ui)
wxJSONValueoperator= (long int l)
wxJSONValueoperator= (unsigned long int ul)
wxJSONValueoperator= (wxInt64 i)
wxJSONValueoperator= (wxUint64 ui)
wxJSONValueoperator= (bool b)
wxJSONValueoperator= (double d)
wxJSONValueoperator= (const wxChar *str)
wxJSONValueoperator= (const wxString &str)
wxJSONValueoperator= (const wxJSONValue &value)
 Assignment operator using reference counting.
wxJSONValue Get (const wxString &key, const wxJSONValue &defaultValue) const
 Return a value or a default value.
bool IsSameAs (const wxJSONValue &other) const
 The comparison function.
int AddComment (const wxString &str, int position=wxJSONVALUE_COMMENT_DEFAULT)
 Add a comment to this JSON value object.
int AddComment (const wxArrayString &comments, int position=wxJSONVALUE_COMMENT_DEFAULT)
 Add one or more comments to this JSON value object.
wxString GetComment (int idx=-1) const
 Return a comment string.
int GetCommentPos () const
 Return the comment position.
int GetCommentCount () const
 Return the number of comment strings.
void ClearComments ()
 Clear all comment strings.
const wxArrayString & GetCommentArray () const
 Get the comment string's array.
wxString GetInfo () const
 Returns informations about the object.
wxString Dump (bool deep=false, int mode=0) const
 Returns informations about the object.
wxJSONRefDataGetRefData () const
 Return the pointer to the referenced data structure.
wxJSONRefDataSetType (wxJSONType type)
 Set the type of the stored value.
int GetLineNo () const
 Return the line number of this JSON value object.
void SetLineNo (int num)
 Set the line number of this JSON value object.

Static Public Member Functions

static wxString TypeToString (wxJSONType type)
 Return a string description of the type.

Protected Member Functions

wxJSONValueFind (unsigned index) const
 Find an element.
wxJSONValueFind (const wxString &key) const
 Find an element.
void DeepCopy (const wxJSONValue &other)
 Do a deep copy of the other object.
wxJSONRefDataInit (wxJSONType type)
 Initialize the JSON value class.
wxJSONRefDataCOW ()
 Make sure the referenced data is unique.
virtual wxJSONRefDataCloneRefData (const wxJSONRefData *data) const
 Make a copy of the referenced data.
virtual wxJSONRefDataCreateRefData () const
 Create a new data structure.
void SetRefData (wxJSONRefData *data)
 Set the pointer to the referenced data.
void Ref (const wxJSONValue &clone)
 Increments the referenced data counter.
void UnRef ()
 Unreferences the shared data.
void UnShare ()
 Makes an exclusive copy of shared data.
void AllocExclusive ()
 Makes a private copy of the referenced data.

Protected Attributes

wxJSONRefDatam_refData
 the referenced data

Friends

class wxJSONReader


Detailed Description

The JSON value class implementation.

This class holds a JSON value which may be of variuos types (see the wxJSONType constants for a description of the types). To know more about the internal representation of JSON values see wxJSON internals.

Starting from version 0.5 the wxJSON library supports 64-bits integers on platforms that have native support for very large integers. Note that the integer type is still stored as a generic wxJSONTYPE_(U)INT constant regardless the size of the value but the JSON value class defines functions in order to let the user know if an integer value fits in a 32-bit integer or it is so large that it needs a 64-bits integer storage. To know more about 64-bits integer support see 64-bits and 32-bits integers

Storing values in a JSON value object of this class is very simple. The following is an example:

 wxJSONValue v( _T( "A string"));   // store a string value in the object
 wxString s = v.AsString();         // get the string value

 v = 12;             // now 'v' contains an integer value
 int i = v.AsInt();  // get the integer

To know more about using this class see the wxJSON - A brief tutorial.


Constructor & Destructor Documentation

wxJSONValue::wxJSONValue (  ) 

Constructors.

The overloaded constructors allow the user to construct a JSON value object that holds the specified value and type of value. The default ctor construct a valid JSON object that constains a null value.

If you want to create an empty JSON value object you have to use the wxJSONValue( wxJSONTYPE_INVALID ) ctor. Note that this object is not a valid JSON value - to know more about this topic see the SetType() function.

The C-string JSON value object
The wxJSONValue(const wxChar*) ctor allows you to create a JSON value object that contains a string value which is stored as a pointer-to-statci-string.

In fact, the ctor DOES NOT copy the string: it only stores the pointer in a data member and the pointed-to buffer is not deleted by the dtor. If the string is not static you have to use the wxJSONValue(const wxString&) constructor.

Also note that this does NOT mean that the value stored in this JSON object cannot change: you can assign whatever other value you want, an integer, a double or an array of values. What I intended is that the pointed-to string must exist for the lifetime of the wxJSONValue object. The following code is perfectly legal:

   wxJSONvalue aString( "this is a static string" );
   aString = 10;
To know more about this topic see wxJSON internals: the C string type

References Init(), m_refData, and wxJSONTYPE_NULL.

wxJSONValue::wxJSONValue ( wxJSONType  type  ) 

References Init(), and m_refData.

wxJSONValue::wxJSONValue ( int  i  ) 

wxJSONValue::wxJSONValue ( unsigned int  i  ) 

wxJSONValue::wxJSONValue ( short  i  ) 

wxJSONValue::wxJSONValue ( unsigned short  i  ) 

wxJSONValue::wxJSONValue ( long int  i  ) 

wxJSONValue::wxJSONValue ( unsigned long int  i  ) 

wxJSONValue::wxJSONValue ( wxInt64  i  ) 

wxJSONValue::wxJSONValue ( wxUint64  ui  ) 

wxJSONValue::wxJSONValue ( bool  b  ) 

wxJSONValue::wxJSONValue ( double  d  ) 

wxJSONValue::wxJSONValue ( const wxChar *  str  ) 

wxJSONValue::wxJSONValue ( const wxString &  str  ) 

wxJSONValue::wxJSONValue ( const wxJSONValue other  ) 

Copy constructor.

The function copies the content of other in this object. Note that the JSON value object is not really copied; the function calls Ref() in order to increment the reference count of the wxJSONRefData structure.

References __PRETTY_FUNCTION__, m_refData, and Ref().

wxJSONValue::~wxJSONValue (  )  [virtual]

Dtor - calls UnRef().

References UnRef().


Member Function Documentation

wxJSONType wxJSONValue::GetType (  )  const

Return the type of the value stored in the object.

This function is the only one that does not ASSERT that the m_refData data member is not NULL. In fact, if the JSON value object does not contain a pointer to a wxJSONRefData structure, the function returns the wxJSONTYPE_INVALID constant which represent an invalid JSON value object. Also note that the pointer to the referenced data structure should NEVER be NULL.

Integer types
Integers are stored internally in a (unsigned) long int or, on platforms that support 64-bits integers, in a wx(U)Int64 data type. When constructed, it is assigned a generic integer type that only depends on the sign: wxJSON_(U)INT regardless the size of the stored value.

This function can be used to know the actual size requirement of the stored value and how it can be retrieved. The value returned by this function is:

  • for signed integers:
    • wxJSONTYPE_SHORT if the value is between SHORT_MIN and SHORT_MAX
    • wxJSONTYPE_LONG if the value is between LONG_MIN and LONG_MAX and greater than SHORT_MAX and less than SHORT_MIN
    • wxJSONTYPE_INT64 if the value is greater than LONG_MAX and less than LONG_MIN

  • for unsigned integers:
    • wxJSONTYPE_USHORT if the value is between 0 and USHORT_MAX
    • wxJSONTYPE_ULONG if the value is between 0 and ULONG_MAX and greater than USHORT_MAX
    • wxJSONTYPE_UINT64 if the value is greater than ULONG_MAX

Note that this function never returns the wxJSONTYPE_(U)INT constant because the int data type may have the same width as SHORT or LONG depending on the platform. This does not mean that you cannot use int as the return value: if you use wxWidgets to develop application in only one platform, you can use int because you know the size of the data type. Otherwise, if is preferable to always use long instead of int.

Also note that the class defines the IsInt() memberfunction which works fine regardless the actual width of the int data type. This function returns TRUE if the stored value fits in a int data type whatever its size is on the current platform (16 or 32-bits).

See also:
SetType IsInt

References GetRefData(), LONG_MAX, LONG_MIN, wxJSONRefData::m_type, wxJSONRefData::m_value, SHORT_MAX, SHORT_MIN, ULONG_MAX, USHORT_MAX, wxJSONTYPE_INT, wxJSONTYPE_INT64, wxJSONTYPE_INVALID, wxJSONTYPE_LONG, wxJSONTYPE_SHORT, wxJSONTYPE_UINT, wxJSONTYPE_UINT64, wxJSONTYPE_ULONG, and wxJSONTYPE_USHORT.

Referenced by wxJSONWriter::DoWrite(), Dump(), IsArray(), IsBool(), IsCString(), IsDouble(), IsInt(), IsLong(), IsNull(), IsObject(), IsShort(), IsString(), IsUInt(), IsULong(), IsUShort(), and IsValid().

bool wxJSONValue::IsValid (  )  const

Return TRUE if the value stored is valid.

The function returns TRUE if the wxJSONValue object was correctly initialized - that is it contains a valid value. A JSON object is valid if its type is not equal to wxJSONTYPE_INVALID.

References GetType(), and wxJSONTYPE_INVALID.

Referenced by wxJSONReader::DoRead(), wxJSONReader::ReadString(), wxJSONReader::ReadValue(), wxJSONReader::StoreComment(), and wxJSONReader::StoreValue().

bool wxJSONValue::IsNull (  )  const

Return TRUE if the type of the value is wxJSONTYPE_NULL.

References GetType(), and wxJSONTYPE_NULL.

bool wxJSONValue::IsInt (  )  const

Return TRUE if the type of the value stored is integer.

This function returns TRUE if the stored value is of type signed integer and the numeric value fits in a int data type. In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_INT and:

   INT_MIN <= m_value <= INT_MAX

Note that if you are developing cross-platform applications you should never use int as the integer data type but long for 32-bits integers and short for 16-bits integers. This is because the int data type may have different width on different platforms. Regardless the widht of the data type (16 or 32 bits), the function returns the correct result because it relies on the INT_MAX and INT_MIN macros.

See also:
64-bits and 32-bits integers

References GetType(), INT_MAX, LONG_MAX, wxJSONTYPE_LONG, and wxJSONTYPE_SHORT.

Referenced by AsInt().

bool wxJSONValue::IsUInt (  )  const

Return TRUE if the type of the value stored is a unsigned int.

This function returns TRUE if the stored value is of type unsigned integer and the numeric value fits int a int data type. In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_UINT and:

   0 <= m_value <= UINT_MAX

Note that if you are developing cross-platform applications you should never use unsigned int as the integer data type but unsigned long for 32-bits integers and unsigned short for 16-bits integers. This is because the unsigned int data type may have different width on different platforms. Regardless the widht of the data type (16 or 32 bits), the function returns the correct result because it relies on the UINT_MAX macro.

See also:
64-bits and 32-bits integers

References GetType(), INT_MAX, LONG_MAX, wxJSONTYPE_ULONG, and wxJSONTYPE_USHORT.

Referenced by AsUInt().

bool wxJSONValue::IsShort (  )  const

Return TRUE if the type of the value stored is 16-bit integer.

This function returns TRUE if the stored value is of type signed integer and the numeric value fits in a short int data type (16-bit integer). In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_INT and:

   SHORT_MIN <= m_value <= SHORT_MAX

See also:
64-bits and 32-bits integers

References GetType(), and wxJSONTYPE_SHORT.

Referenced by AsShort().

bool wxJSONValue::IsUShort (  )  const

Return TRUE if the type of the value stored is a unsigned short.

This function returns TRUE if the stored value is of type unsigned integer and the numeric value fits in a unsigned short int data type. In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_UINT and:

   0 <= m_value <= USHORT_MAX

See also:
64-bits and 32-bits integers

References GetType(), and wxJSONTYPE_USHORT.

Referenced by AsUShort().

bool wxJSONValue::IsLong (  )  const

Return TRUE if the stored value is an integer which fits in a long int.

This function returns TRUE if the stored value is of type signed LONG integer and the numeric value fits int a long int data type. In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_INT and:

   LONG_MIN <= m_value <= LONG_MAX

See also:
64-bits and 32-bits integers

References GetType(), wxJSONTYPE_LONG, and wxJSONTYPE_SHORT.

Referenced by AsLong().

bool wxJSONValue::IsULong (  )  const

Return TRUE if the stored value is an integer which fits in a unsigned long int.

This function returns TRUE if the stored value is of type unsigned LONG integer and the numeric value fits int a unsigned long int data type. In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_UINT and:

   0 <= m_value <= ULONG_MAX

See also:
64-bits and 32-bits integers

References GetType(), wxJSONTYPE_ULONG, and wxJSONTYPE_USHORT.

Referenced by AsULong().

bool wxJSONValue::IsInt32 (  )  const

Return TRUE if the stored value is a 32-bits integer.

This function is only available on 64-bits platforms and returns TRUE if, and only if, the stored value is of type wxJSONTYPE_INT and the numeric value fits in a 32-bits signed integer. The function just calls IsLong() and returns the value returned by that function. The use of this function is deprecated: use IsLong() instead

bool wxJSONValue::IsInt64 (  )  const

Return TRUE if the stored value is integer.

This function returns TRUE if the stored value is of type signed integer. In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_INT The function is only available if 64-bits integer support is enabled.

See also:
64-bits and 32-bits integers

bool wxJSONValue::IsUInt32 (  )  const

Return TRUE if the stored value is a unsigned 32-bits integer.

This function is only available on 64-bits platforms and returns TRUE if, and only if, the stored value is of type wxJSONTYPE_UINT and the numeric value fits in a 32-bits unsigned integer. The function just calls IsULong() and returns the value returned by that function. The use of this function is deprecated: use IsULong() instead

bool wxJSONValue::IsUInt64 (  )  const

Return TRUE if the stored value is a unsigned integer.

This function returns TRUE if the stored value is of type unsigned integer. In other words, the function returns TRUE if the wxJSONRefData::m_type data member is of type wxJSONTYPE_UINT. The function is only available if 64-bits integer support is enabled.

See also:
64-bits and 32-bits integers

bool wxJSONValue::IsBool (  )  const

Return TRUE if the type of the value stored is a boolean.

References GetType(), and wxJSONTYPE_BOOL.

bool wxJSONValue::IsDouble (  )  const

Return TRUE if the type of the value stored is a double.

References GetType(), and wxJSONTYPE_DOUBLE.

Referenced by AsDouble().

bool wxJSONValue::IsString (  )  const

Return TRUE if the type of the value stored is a wxString object.

References GetType(), and wxJSONTYPE_STRING.

Referenced by wxJSONReader::DoRead(), and wxJSONReader::ReadString().

bool wxJSONValue::IsCString (  )  const

Return TRUE if the type of the value stored is a pointer to a static C string.

This function returns TRUE if, and only if the stored value is a pointer to a static C-string and the C-string storage is enabled in the wxJSON library. By default, C-string storage is not enabled in the library so this function always returns FALSE. To know more about C-strings read wxJSON internals: the C string type

References GetType(), and wxJSONTYPE_CSTRING.

bool wxJSONValue::IsArray (  )  const

Return TRUE if the type of the value stored is an array type.

References GetType(), and wxJSONTYPE_ARRAY.

Referenced by wxJSONReader::DoRead(), and wxJSONReader::StoreValue().

bool wxJSONValue::IsObject (  )  const

Return TRUE if the type of this value is a key/value map.

References GetType(), and wxJSONTYPE_OBJECT.

Referenced by wxJSONReader::DoRead(), and wxJSONReader::StoreValue().

int wxJSONValue::AsInt (  )  const

Return the stored value as an integer.

The function returns the stored value as an integer. Note that the function does not check that the type of the value is actually an integer and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value IsInt().

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

References GetRefData(), IsInt(), wxJSONValueHolder::m_valInt, wxJSONRefData::m_value, and wxJSON_ASSERT.

unsigned int wxJSONValue::AsUInt (  )  const

Return the stored value as a unsigned int.

The function returns the stored value as a unsigned integer. Note that the function does not check that the type of the value is actually a unsigned integer and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value is wxJSONTYPE_UINT.

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

References GetRefData(), IsUInt(), wxJSONRefData::m_value, wxJSONValueHolder::m_valUInt, and wxJSON_ASSERT.

short int wxJSONValue::AsShort (  )  const

Returns the value as a short integer.

The function returns the stored value as a short integer. Note that the function does not check that the type of the value is actually a short integer and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value IsShort().

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

References GetRefData(), IsShort(), wxJSONValueHolder::m_valShort, wxJSONRefData::m_value, and wxJSON_ASSERT.

unsigned short wxJSONValue::AsUShort (  )  const

Returns the value as a unsigned short integer.

The function returns the stored value as a unsigned short integer. Note that the function does not check that the type of the value is actually a unsigned short and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value IsUShort().

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

References GetRefData(), IsUShort(), wxJSONRefData::m_value, wxJSONValueHolder::m_valUShort, and wxJSON_ASSERT.

long int wxJSONValue::AsLong (  )  const

Returns the value as a long integer.

The function returns the stored value as a long integer. Note that the function does not check that the type of the value is actually a long integer and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value IsLong().

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

References GetRefData(), IsLong(), wxJSONValueHolder::m_valLong, wxJSONRefData::m_value, and wxJSON_ASSERT.

unsigned long int wxJSONValue::AsULong (  )  const

Returns the value as a unsigned long integer.

The function returns the stored value as a unsigned long integer. Note that the function does not check that the type of the value is actually a unsigned long integer and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value IsLong().

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

References GetRefData(), IsULong(), wxJSONRefData::m_value, wxJSONValueHolder::m_valULong, and wxJSON_ASSERT.

wxInt32 wxJSONValue::AsInt32 (  )  const

Returns the low-order 32 bits of the value as an integer.

This function is only available on 64-bits platforms and returns the low-order 32-bits of the integer stored in the JSON value. Note that all integer types are stored as wx(U)Int64 data types by the JSON value class and that the function does not check that the numeric value fits in a 32-bit integer. The function just calls AsLong() and casts the value in a wxInt32 data type

See also:
Obtaining values from JSON value class

wxUint32 wxJSONValue::AsUInt32 (  )  const

Returns the low-order 32 bits of the value as an unsigned integer.

This function is only available on 64-bits platforms and returns the low-order 32-bits of the integer stored in the JSON value. Note that all integer types are stored as wx(U)Int64 data types by the JSON value class and that the function does not check that the numeric value fits in a 32-bit integer. The function just calls AsULong() and casts the value in a wxUInt32 data type

See also:
Obtaining values from JSON value class

wxInt64 wxJSONValue::AsInt64 (  )  const

Return the numeric value as a 64-bit integer.

This function is only available on 64-bits platforms and returns the numeric value as a 64-bit integer.

Note that the function does not check that the type of the value is actually an integer and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value is wxJSONTYPE_INT.

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

wxUint64 wxJSONValue::AsUInt64 (  )  const

Return the numeric value as a 64-bit unsigned integer.

This function is only available on 64-bits platforms and returns the numeric value as a 64-bit unsigned integer.

Note that the function does not check that the type of the value is actually an integer and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function wxJSON_ASSERTs that the type of the stored value is wxJSONTYPE_UINT.

See also:
64-bits and 32-bits integers

Obtaining values from JSON value class

bool wxJSONValue::AsBool (  )  const

Return the stored value as a boolean.

The function returns the stored value as a boolean. Note that the function does not check that the type of the value is actually a boolean and it just returns the content of the wxJSONValueHolder union. However, in debug builds, the function ASSERTs that the type of the stored value is wxJSONTYPE_BOOL.

See also:
Obtaining values from JSON value class

References GetRefData(), wxJSONRefData::m_type, wxJSONValueHolder::m_valBool, wxJSONRefData::m_value, wxJSON_ASSERT, and wxJSONTYPE_BOOL.

double wxJSONValue::AsDouble (  )  const

Return the stored value as a double.

The function returns the stored value as a double. Note that the function does not check that the type of the value is actually a double and it just returns the content of the wxJSONValueHolder union as if it was a double. However, in debug builds, the function ASSERTs that the type of the stored value IsDouble().

See also:
Obtaining values from JSON value class

References GetRefData(), IsDouble(), wxJSONValueHolder::m_valDouble, wxJSONRefData::m_value, and wxJSON_ASSERT.

wxString wxJSONValue::AsString (  )  const

Return the stored value as a wxWidget's string.

The function returns a string representation of the value stored in the JSON object. All primitive values can be converted to a string.

If the stored value is a boolean, the function returns the literal string true or false. If the value is a NULL value the null literal string is returned.

If the value is of type wxJSONTYPE_INVALID, the literal string <invalid> is returned. Note that this is NOT a valid JSON text. If the value is an array or map, an empty string is returned.

See also:
Obtaining values from JSON value class

References GetRefData(), wxJSONRefData::m_type, wxJSONValueHolder::m_valBool, wxJSONValueHolder::m_valCString, wxJSONValueHolder::m_valDouble, wxJSONValueHolder::m_valInt64, wxJSONValueHolder::m_valLong, wxJSONRefData::m_valString, wxJSONRefData::m_value, wxJSONValueHolder::m_valUInt64, wxJSONValueHolder::m_valULong, TypeToString(), wxJSON_ASSERT, wxJSONTYPE_ARRAY, wxJSONTYPE_BOOL, wxJSONTYPE_CSTRING, wxJSONTYPE_DOUBLE, wxJSONTYPE_INT, wxJSONTYPE_INVALID, wxJSONTYPE_NULL, wxJSONTYPE_OBJECT, wxJSONTYPE_STRING, and wxJSONTYPE_UINT.

Referenced by wxJSONReader::DoRead(), wxJSONWriter::DoWrite(), wxJSONReader::ReadString(), wxJSONReader::ReadValue(), wxJSONReader::StoreValue(), and wxJSONWriter::WritePrimitiveValue().

const wxChar * wxJSONValue::AsCString (  )  const

Return the stored value as a pointer to a static C string.

If the type of the value is stored as a C-string data type the function just returns that pointer. If the stored value is a wxString object, the function returns the pointer returned by the wxString::c_str() function. If the stored value is of all other JSON types, the functions returns a NULL pointer.

This changed in version 0.5 and later. In previous versions, the functions returned a NULL pointer also if the value is a wxString object (thanks to Robbie Groenewoudt).

See also:
wxJSON internals: the C string type

Obtaining values from JSON value class

References GetRefData(), wxJSONRefData::m_type, wxJSONValueHolder::m_valCString, wxJSONRefData::m_valString, wxJSONRefData::m_value, wxJSON_ASSERT, wxJSONTYPE_CSTRING, and wxJSONTYPE_STRING.

const wxJSONInternalMap * wxJSONValue::AsMap (  )  const

Return the stored value as a map object.

This function is for testing and debugging purposes and you shold never use it. To retreive values from an array or map JSON object use the Item() or ItemAt() memberfunctions or the subscript operator. If the stored value is not a map type, returns a NULL pointer.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valMap, wxJSON_ASSERT, wxJSONInternalMap, and wxJSONTYPE_OBJECT.

Referenced by wxJSONWriter::DoWrite(), and Dump().

const wxJSONInternalArray * wxJSONValue::AsArray (  )  const

Return the stored value as an array object.

This function is for testing and debugging purposes and you shold never use it. To retreive values from an array or map JSON object use the Item() or ItemAt() memberfunctions or the subscript operator. If the stored value is not an array type, returns a NULL pointer.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valArray, wxJSON_ASSERT, wxJSONInternalArray, and wxJSONTYPE_ARRAY.

Referenced by wxJSONReader::StoreValue().

bool wxJSONValue::HasMember ( unsigned  index  )  const

Return TRUE if the object contains an element at the specified index.

If the stoerd value is not an array or a map, the function returns FALSE.

References Size().

bool wxJSONValue::HasMember ( const wxString &  key  )  const

Return TRUE if the object contains an element at the specified key.

If the stored value is not a key/map map, the function returns FALSE.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valMap, wxJSON_ASSERT, and wxJSONTYPE_OBJECT.

int wxJSONValue::Size (  )  const

Return the size of the array or map stored in this value.

Note that both the array and the key/value map may have a size of ZERO elements. If the stored value is not an array nor a key/value hashmap, the function returns -1.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valArray, wxJSONRefData::m_valMap, wxJSON_ASSERT, wxJSONTYPE_ARRAY, and wxJSONTYPE_OBJECT.

Referenced by wxJSONWriter::DoWrite(), Dump(), GetInfo(), HasMember(), IsSameAs(), Item(), and ItemAt().

wxArrayString wxJSONValue::GetMemberNames (  )  const

Return the array of keys of this JSON object.

If the stored value is a key/value map, the function returns an array of strings containing the key of all elements. Note that the returned array may be empty if the map has ZERO elements. An empty string array is also returned if the stored value is not a key/value map. Also note that in debug builds, the function wxJSON_ASSERTs that the type of the stored object is wxJSONTYPE_OBJECT.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valMap, wxJSON_ASSERT, and wxJSONTYPE_OBJECT.

Referenced by GetInfo().

wxJSONValue & wxJSONValue::Append ( const wxJSONValue value  ) 

Append the specified value in the array.

The function appends the value specified in the parameter to the array contained in this object. If this object does not contain an array type, the actual content is deleted, a new array type is created and the JSON value value is appended to the newly created array. Returns a reference to the appended object.

References COW(), wxJSONRefData::m_type, wxJSONRefData::m_valArray, SetType(), wxJSON_ASSERT, and wxJSONTYPE_ARRAY.

Referenced by Append(), and wxJSONReader::StoreValue().

wxJSONValue & wxJSONValue::Append ( bool  b  ) 

References Append().

wxJSONValue & wxJSONValue::Append ( int  i  ) 

References Append().

wxJSONValue & wxJSONValue::Append ( unsigned int  ui  ) 

References Append().

wxJSONValue & wxJSONValue::Append ( short int  i  ) 

References Append().

wxJSONValue& wxJSONValue::Append ( unsigned short int  ui  ) 

wxJSONValue & wxJSONValue::Append ( long int  l  ) 

References Append().

wxJSONValue& wxJSONValue::Append ( unsigned long int  ul  ) 

wxJSONValue & wxJSONValue::Append ( wxInt64  i  ) 

wxJSONValue & wxJSONValue::Append ( wxUint64  ui  ) 

wxJSONValue & wxJSONValue::Append ( double  d  ) 

References Append().

wxJSONValue & wxJSONValue::Append ( const wxChar *  str  ) 

References Append().

wxJSONValue & wxJSONValue::Append ( const wxString &  str  ) 

References Append().

bool wxJSONValue::Remove ( int  index  ) 

Remove the item at the specified index or key.

The function removes the item at index index or at the specified key in the array or map. If this object does not contain an array (for a index parameter) or a map (for a key parameter), the function does nothing and returns FALSE. If the element does not exist, FALSE is returned.

References COW(), wxJSONRefData::m_type, wxJSONRefData::m_valArray, wxJSON_ASSERT, and wxJSONTYPE_ARRAY.

bool wxJSONValue::Remove ( const wxString &  key  ) 

void wxJSONValue::Clear (  ) 

Clear the object value.

This function causes the object to be empty. The function simply calls UnRef() making this object to become invalid and set its type to wxJSONTYPE_INVALID.

References SetType(), UnRef(), and wxJSONTYPE_INVALID.

bool wxJSONValue::Cat ( const wxChar *  str  ) 

bool wxJSONValue::Cat ( const wxString &  str  ) 

Concatenate a string to this string object.

The function concatenates str to the string contained in this object and returns TRUE if the operation is succefull. If the value stored in this value is not a string object the function does nothing and returns FALSE. Note that in order to be successfull, the value must contain a wxString object and not a pointer to C-string.

References COW(), GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valString, wxJSON_ASSERT, and wxJSONTYPE_STRING.

wxJSONValue & wxJSONValue::Item ( unsigned  index  ) 

Return the item at the specified index.

The function returns a reference to the object at the specified index. If the element does not exist, the array is enlarged to index + 1 elements and a reference to the last element will be returned. New elements will contain NULL values. If this object does not contain an array, the old value is replaced by an array object which will be enlarged to the needed dimension.

References COW(), wxJSONRefData::m_type, wxJSONRefData::m_valArray, SetType(), Size(), wxJSON_ASSERT, wxJSONTYPE_ARRAY, and wxJSONTYPE_NULL.

Referenced by operator[]().

wxJSONValue & wxJSONValue::Item ( const wxString &  key  ) 

Return the item at the specified key.

The function returns a reference to the object in the map that has the specified key. If key does not exist, a new NULL value is created with the provided key and a reference to it is returned. If this object does not contain a map, the old value is replaced by a map object.

References __PRETTY_FUNCTION__, COW(), GetInfo(), wxJSONRefData::m_type, wxJSONRefData::m_valMap, SetType(), wxJSON_ASSERT, and wxJSONTYPE_OBJECT.

wxJSONValue wxJSONValue::ItemAt ( unsigned  index  )  const

Return the item at the specified index.

The function returns a copy of the object at the specified index. If the element does not exist, the function returns an 'empty' value.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valArray, Size(), wxJSON_ASSERT, wxJSONTYPE_ARRAY, and wxJSONTYPE_INVALID.

Referenced by wxJSONWriter::DoWrite(), and IsSameAs().

wxJSONValue wxJSONValue::ItemAt ( const wxString &  key  )  const

Return the item at the specified key.

The function returns a copy of the object in the map

that has the specified key. If key does not exist, an 'empty' value is returned.

References __PRETTY_FUNCTION__, GetInfo(), GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valMap, wxJSON_ASSERT, wxJSONTYPE_INVALID, and wxJSONTYPE_OBJECT.

wxJSONValue & wxJSONValue::operator[] ( unsigned  index  ) 

Return the item at the specified index.

The function returns a reference to the object at the specified index. If the element does not exist, the array is enlarged to index + 1 elements and a reference to the last element will be returned. New elements will contain NULL values. If this object does not contain an array, the old value is replaced by an array object.

References Item().

wxJSONValue & wxJSONValue::operator[] ( const wxString &  key  ) 

Return the item at the specified key.

The function returns a reference to the object in the map that has the specified key. If key does not exist, a new NULL value is created with the provided key and a reference to it is returned. If this object does not contain a map, the old value is replaced by a map object.

References Item().

wxJSONValue & wxJSONValue::operator= ( int  i  ) 

Assign the specified value to this object replacing the old value.

The assignment operator assigns to this object the value specified in the right operand of the assignment operator. Note that the old value is deleted but not the other data members in the wxJSONRefData structure. This is particularly usefull for the parser class which stores comment lines in a temporary wxJSONvalue object that is of type wxJSONTYPE_INVALID. As comment lines may apear before the value they refer to, comments are stored in a value that is not yet being read. when the value is read, it is assigned to the temporary JSON value object without deleting the comment lines.

References wxJSONRefData::m_value, SetType(), and wxJSONTYPE_INT.

wxJSONValue & wxJSONValue::operator= ( unsigned int  ui  ) 

wxJSONValue& wxJSONValue::operator= ( short int  i  ) 

wxJSONValue& wxJSONValue::operator= ( unsigned short int  ui  ) 

wxJSONValue& wxJSONValue::operator= ( long int  l  ) 

wxJSONValue& wxJSONValue::operator= ( unsigned long int  ul  ) 

wxJSONValue & wxJSONValue::operator= ( wxInt64  i  ) 

wxJSONValue & wxJSONValue::operator= ( wxUint64  ui  ) 

wxJSONValue & wxJSONValue::operator= ( bool  b  ) 

wxJSONValue & wxJSONValue::operator= ( double  d  ) 

wxJSONValue & wxJSONValue::operator= ( const wxChar *  str  ) 

wxJSONValue & wxJSONValue::operator= ( const wxString &  str  ) 

wxJSONValue & wxJSONValue::operator= ( const wxJSONValue other  ) 

Assignment operator using reference counting.

Unlike all other assignment operators, this one makes a swallow copy of the other JSON value object. The function calls Ref() to get a shared referenced data.

See also:
wxJSON internals: reference counting

References Ref().

wxJSONValue wxJSONValue::Get ( const wxString &  key,
const wxJSONValue defaultValue 
) const

Return a value or a default value.

This function returns a copy of the value object for the specified key. If the key is not found, a copy of defaultValue is returned. Note that the returned values are not real copy of the key or the default values because copy-on-write is used by this class. However, you have to treat them as real copies; in other words, if you change the values of the returned object your changes does not reflect in the otiginal value. Example:

  wxJSONValue defaultValue( 0 );
  wxJSONvalue v1;
  v1["key"] = 100;   // 'v1["key"]' contains the integer 100

  // 'v2' contains 100 but it is a swallow copy of 'v1["key"]'
  wxJSONValue v2 = v1.Get( "key", defaultValue );

  // 'v1["key"]' still contains 100
  v2 = 200;

  // if you want your change to be reflected in the 'v1' object
  // you have to assign it
  v1["key"] = v2;

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valMap, wxJSON_ASSERT, and wxJSONTYPE_OBJECT.

bool wxJSONValue::IsSameAs ( const wxJSONValue other  )  const

The comparison function.

This function returns TRUE if this object looks like other. Note that this class does not define a comparison operator (the classical operator== function) because the notion of equal for JSON values objects is not applicable. The comment strings array are not compared: JSON value objects are the same if they contains the same values, regardless the comment's strings.

Note that the function does not return the element that cause the comparison to return FALSE. There is not a good structure to tell this information. If you need it for debugging purposes, you have to turn on the sameas tracing feature by setting the WXTRACE environment variable (you need a debug version of the application):

   export WXTRACE=sameas     // for unix systems that use bash

Note that if the two JSON value objects share the same referenced data, the function immediatly returns TRUE without doing a deep comparison which is, sure, useless. For further info see The comparison function and operator.

Bug:
comparing very large 64-bits integers that differ by a small value may cause the function to return TRUE intead of FALSE

References __PRETTY_FUNCTION__, GetRefData(), IsSameAs(), ItemAt(), wxJSONRefData::m_type, wxJSONValueHolder::m_valBool, wxJSONValueHolder::m_valCString, wxJSONValueHolder::m_valDouble, wxJSONRefData::m_valMap, wxJSONRefData::m_valString, wxJSONRefData::m_value, Size(), wxJSONTYPE_ARRAY, wxJSONTYPE_BOOL, wxJSONTYPE_CSTRING, wxJSONTYPE_DOUBLE, wxJSONTYPE_INT, wxJSONTYPE_INVALID, wxJSONTYPE_NULL, wxJSONTYPE_OBJECT, wxJSONTYPE_STRING, and wxJSONTYPE_UINT.

Referenced by IsSameAs().

int wxJSONValue::AddComment ( const wxString &  str,
int  position = wxJSONVALUE_COMMENT_DEFAULT 
)

Add a comment to this JSON value object.

The function adds a comment string to this JSON value object and returns the total number of comment strings belonging to this value. Note that the comment string must be a valid C/C++ comment because the wxJSONWriter does not modify it. In other words, a C++ comment string must start with '//' and must end with a new-line character. If the final LF char is missing, the automatically adds it. You can also add C-style comments which must be enclosed in the usual C-comment characters. For C-style comments, the function does not try to append the final comment characters but allows trailing whitespaces and new-line chars. The position parameter is one of:

  • wxJSONVALUE_COMMENT_BEFORE: the comment will be written before the value
  • wxJSONVALUE_COMMENT_INLINE: the comment will be written on the same line
  • wxJSONVALUE_COMMENT_AFTER: the comment will be written after the value
  • wxJSONVALUE_COMMENT_DEFAULT: the old value of comment's position is not changed; if no comments were added to the value object this is the same as wxJSONVALUE_COMMENT_BEFORE.
To know more about comment's storage see Adding C/C++ comments using member functions

References __PRETTY_FUNCTION__, COW(), wxJSONRefData::m_commentPos, wxJSONRefData::m_comments, wxJSON_ASSERT, and wxJSONVALUE_COMMENT_DEFAULT.

Referenced by AddComment(), and wxJSONReader::StoreComment().

int wxJSONValue::AddComment ( const wxArrayString &  comments,
int  position = wxJSONVALUE_COMMENT_DEFAULT 
)

Add one or more comments to this JSON value object.

The function adds the strings contained in comments to the comment's string array of this value object by calling the AddComment( const wxString&,int) function for every string in the comment array. Returns the number of strings correctly added.

References AddComment().

wxString wxJSONValue::GetComment ( int  idx = -1  )  const

Return a comment string.

The function returns the comment string at index idx. If idx is out of range, an empty string is returned. If idx is equal to -1, then the function returns a string that contains all comment's strings stored in the array.

References GetRefData(), wxJSONRefData::m_comments, and wxJSON_ASSERT.

int wxJSONValue::GetCommentPos (  )  const

Return the comment position.

References GetRefData(), wxJSONRefData::m_commentPos, and wxJSON_ASSERT.

Referenced by wxJSONWriter::DoWrite().

int wxJSONValue::GetCommentCount (  )  const

Return the number of comment strings.

References __PRETTY_FUNCTION__, GetRefData(), wxJSONRefData::m_comments, and wxJSON_ASSERT.

Referenced by wxJSONWriter::DoWrite().

void wxJSONValue::ClearComments (  ) 

Clear all comment strings.

Referenced by wxJSONReader::StoreValue().

const wxArrayString & wxJSONValue::GetCommentArray (  )  const

Get the comment string's array.

References GetRefData(), wxJSONRefData::m_comments, and wxJSON_ASSERT.

Referenced by wxJSONWriter::WriteComment().

wxString wxJSONValue::GetInfo (  )  const

Returns informations about the object.

The function is only usefull for debugging purposes and will probably be dropped in future versions. You should not rely on this function to exist in future versions.

References GetMemberNames(), GetRefData(), wxJSONRefData::m_comments, wxJSONRefData::m_type, Size(), TypeToString(), wxJSON_ASSERT, and wxJSONTYPE_OBJECT.

Referenced by Item(), and ItemAt().

wxString wxJSONValue::Dump ( bool  deep = false,
int  indent = 0 
) const

Returns informations about the object.

The function is only usefull for debugging purposes and will probably be dropped in future versions. Returns a string that contains info about the object such as:

  • the type of the object
  • the size
  • the progressive counter
  • the pointer to referenced data
  • the progressive counter of referenced data
  • the number of share of referenced data
The deep parameter is used to specify if the function will be called recursively in order to dump sub-items. If the parameter is TRUE than a deep dump is executed.

The indent is the initial indentation: it is incremented by 3 every time the Dump() function is called recursively.

References AsMap(), Dump(), Find(), wxJSONRefData::GetRefCount(), GetRefData(), GetType(), wxJSONRefData::m_comments, Size(), TypeToString(), wxJSON_ASSERT, wxJSONInternalMap, wxJSONTYPE_ARRAY, and wxJSONTYPE_OBJECT.

Referenced by Dump().

wxJSONRefData * wxJSONValue::GetRefData (  )  const

wxJSONRefData * wxJSONValue::SetType ( wxJSONType  type  ) 

Set the type of the stored value.

The function sets the type of the stored value as specified in the provided argument. If the actual type is equal to type, nothing happens and this JSON value object retains the original type and value. If the type differs, however, the original type and value are lost.

The function just sets the type of the object and not the value itself. If the object does not have a data structure it is allocated using the CreateRefData() function unless the type to be set is wxJSONTYPE_INVALID. In this case and if a data structure is not yet allocated, it is not allocated.

If the object already contains a data structure it is not deleted but the type is changed in the original data structure. Complex values in the old structure are cleared. The type argument can be one of the following:

  • wxJSONTYPE_INVALID: an empty (not initialized) JSON value
  • wxJSONTYPE_NULL: a NULL value
  • wxJSONTYPE_INT: an integer value
  • wxJSONTYPE_UINT: an unsigned integer
  • wxJSONTYPE_DOUBLE: a double precision number
  • wxJSONTYPE_BOOL: a boolean
  • wxJSONTYPE_CSTRING: a C string
  • wxJSONTYPE_STRING: a wxString object
  • wxJSONTYPE_ARRAY: an array of wxJSONValue objects
  • wxJSONTYPE_OBJECT: a hashmap of key/value pairs where value is a wxJSONValue object
  • wxJSONTYPE_LONG: a 32-bits integer value
  • wxJSONTYPE_ULONG: an unsigned 32-bits integer
  • wxJSONTYPE_INT64: a 64-bits integer value
  • wxJSONTYPE_UINT64: an unsigned 64-bits integer
  • wxJSONTYPE_SHORT: a signed short integer
  • wxJSONTYPE_USHORT: an unsigned short integer
The integer storage depends on the platform: for platforms that support 64-bits integers, integers are always stored as 64-bits integers. On platforms that do not support 64-bits integers, ints are stored as long int. To know more about the internal representation of integers, read 64-bits and 32-bits integers.

Note that there is no need to set a type for the object in order to assign a value to it. In other words, if you want to construct a JSON value which holds an integer value of 10, just use the specific constructor:

   wxJSONValue value( 10 );
which sets the integer type and also the numeric value. Moreover, there is no need to set the type for none of the handled types, not only for primitive types but for complex types, too. For example, if you want to construct an array of JSON values, just use the default ctor and call the Append() member function which will append the first element to the array and will set the array type:
   wxJSONValue value;
   value.Append( "a string" );
See also:
GetType

Referenced by Append(), Clear(), wxJSONReader::DoRead(), Item(), operator=(), wxJSONReader::Parse(), wxJSONReader::ReadValue(), and wxJSONReader::StoreValue().

int wxJSONValue::GetLineNo (  )  const

Return the line number of this JSON value object.

The line number of a JSON value object is set to -1 when the object is constructed. The line number is set by the parser class, wxJSONReader, when a JSON text is read from a stream or a string. it is used when reading a comment line: comment lines that apear on the same line as a value are considered inline comments of the value.

Referenced by wxJSONReader::StoreComment().

void wxJSONValue::SetLineNo ( int  num  ) 

Set the line number of this JSON value object.

Referenced by wxJSONReader::DoRead(), wxJSONReader::Parse(), wxJSONReader::ReadString(), and wxJSONReader::StoreValue().

wxString wxJSONValue::TypeToString ( wxJSONType  type  )  [static]

Return a string description of the type.

This static function is only usefull for debugging purposes and should not be used by users of this class. It simply returns a string representation of the JSON value type stored in a object. For example, if type is wxJSONTYPE_INT the function returns the string "wxJSONTYPE_INT". If type is out of range, an empty string is returned (should never happen).

Referenced by AsString(), Dump(), and GetInfo().

wxJSONValue * wxJSONValue::Find ( unsigned  index  )  const [protected]

Find an element.

The function returns a pointer to the element at index index or a NULL pointer if index does not exist. A NULL pointer is also returned if the object does not contain an array nor a key/value map.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valArray, wxJSON_ASSERT, and wxJSONTYPE_ARRAY.

Referenced by Dump().

wxJSONValue * wxJSONValue::Find ( const wxString &  key  )  const [protected]

Find an element.

The function returns a pointer to the element with key key or a NULL pointer if key does not exist. A NULL pointer is also returned if the object does not contain a key/value map.

References GetRefData(), wxJSONRefData::m_type, wxJSONRefData::m_valMap, wxJSON_ASSERT, and wxJSONTYPE_OBJECT.

void wxJSONValue::DeepCopy ( const wxJSONValue other  )  [protected]

Do a deep copy of the other object.

This function allocates a new ref-data structure and copies it from the object other.

wxJSONRefData * wxJSONValue::Init ( wxJSONType  type  )  [protected]

Initialize the JSON value class.

The function is called by the ctors and allocates a new instance of the wxJSONRefData class and sets the type of the JSON value. Note that only the type is set, not the value. Also note that this function may be called from other memberfunctions if the m_refData data member is NULL.

References __PRETTY_FUNCTION__, GetRefData(), wxJSONRefData::m_commentPos, wxJSONRefData::m_type, SetRefData(), UnRef(), wxJSON_ASSERT, wxJSONRefData, and wxJSONVALUE_COMMENT_BEFORE.

Referenced by wxJSONValue().

wxJSONRefData * wxJSONValue::COW (  )  [protected]

Make sure the referenced data is unique.

This function is called by all non-const member functions and makes sure that the referenced data is unique by calling UnShare() If the referenced data is shared acrosss other wxJSONValue instances, the UnShare() function makes a private copy of the shared data.

Referenced by AddComment(), Append(), Cat(), Item(), and Remove().

wxJSONRefData * wxJSONValue::CloneRefData ( const wxJSONRefData otherData  )  const [protected, virtual]

Make a copy of the referenced data.

The function allocates a new instance of the wxJSONRefData structure, copies the content of other and returns the pointer to the newly created structure. This function is called by the wxObject::UnRef() function when a non-const member function is called on multiple referenced data.

wxJSONRefData * wxJSONValue::CreateRefData (  )  const [protected, virtual]

Create a new data structure.

The function allocates a new instance of the wxJSONRefData structure and returns its pointer. The type of the JSON value is set to wxJSONTYPE_INVALID (= a not initialized value).

Referenced by AllocExclusive().

void wxJSONValue::SetRefData ( wxJSONRefData data  )  [protected]

Set the pointer to the referenced data.

Referenced by Init().

void wxJSONValue::Ref ( const wxJSONValue clone  )  [protected]

Increments the referenced data counter.

Referenced by operator=(), and wxJSONValue().

void wxJSONValue::UnRef (  )  [protected]

Unreferences the shared data.

The function decrements the number of shares in wxJSONRefData::m_refCount and if it is ZERO, deletes the referenced data. It is called by the destructor.

References wxJSONRefData::m_refCount, and m_refData.

Referenced by Clear(), Init(), and ~wxJSONValue().

void wxJSONValue::UnShare (  )  [protected]

Makes an exclusive copy of shared data.

void wxJSONValue::AllocExclusive (  )  [protected]

Makes a private copy of the referenced data.

References CreateRefData(), and m_refData.


Friends And Related Function Documentation

friend class wxJSONReader [friend]


Member Data Documentation

the referenced data

Referenced by AllocExclusive(), UnRef(), and wxJSONValue().


The documentation for this class was generated from the following files:

Generated on Sun Jun 7 16:36:18 2009 for wxJSON by  doxygen 1.5.5