Represents a JSON value. Use Value for UTF8 encoding and default allocator. More...

#include <document.h>

Inheritance diagram for rapidjson::GenericValue< Encoding, Allocator >:
[legend]
Collaboration diagram for rapidjson::GenericValue< Encoding, Allocator >:
[legend]

Classes

struct  Array
 
union  Data
 
struct  Member
 Name-value pair in an object. More...
 
union  Number
 
struct  Object
 
struct  String
 

Public Types

typedef Encoding EncodingType
 Encoding type from template parameter.
 
typedef Allocator AllocatorType
 Allocator type from template parameter.
 
typedef Encoding::Ch Ch
 Character type derived from Encoding.
 
typedef MemberMemberIterator
 Member iterator for iterating in object.
 
typedef const MemberConstMemberIterator
 Constant member iterator for iterating in object.
 
typedef GenericValueValueIterator
 Value iterator for iterating in array.
 
typedef const GenericValueConstValueIterator
 Constant value iterator for iterating in array.
 

Public Member Functions

template<typename Handler >
const GenericValueAccept (Handler &handler) const
 Generate events of this value to a Handler. More...
 
Assignment operators
GenericValueoperator= (GenericValue &rhs)
 Assignment with move semantics. More...
 
template<typename T >
GenericValueoperator= (T value)
 Assignment with primitive types. More...
 
Type
Type GetType () const
 
bool IsNull () const
 
bool IsFalse () const
 
bool IsTrue () const
 
bool IsBool () const
 
bool IsObject () const
 
bool IsArray () const
 
bool IsNumber () const
 
bool IsInt () const
 
bool IsUint () const
 
bool IsInt64 () const
 
bool IsUint64 () const
 
bool IsDouble () const
 
bool IsString () const
 
Null
GenericValueSetNull ()
 
Bool
bool GetBool () const
 
GenericValueSetBool (bool b)
 
Object
GenericValueSetObject ()
 Set this value as an empty object.
 
GenericValueoperator[] (const Ch *name)
 Get the value associated with the name. More...
 
const GenericValueoperator[] (const Ch *name) const
 
ConstMemberIterator MemberBegin () const
 Member iterators.
 
ConstMemberIterator MemberEnd () const
 
MemberIterator MemberBegin ()
 
MemberIterator MemberEnd ()
 
bool HasMember (const Ch *name) const
 Check whether a member exists in the object. More...
 
MemberFindMember (const Ch *name)
 Find member by name. More...
 
const MemberFindMember (const Ch *name) const
 
GenericValueAddMember (GenericValue &name, GenericValue &value, Allocator &allocator)
 Add a member (name-value pair) to the object. More...
 
GenericValueAddMember (const Ch *name, Allocator &nameAllocator, GenericValue &value, Allocator &allocator)
 
GenericValueAddMember (const Ch *name, GenericValue &value, Allocator &allocator)
 
template<typename T >
GenericValueAddMember (const Ch *name, T value, Allocator &allocator)
 
bool RemoveMember (const Ch *name)
 Remove a member in object by its name. More...
 
Array
GenericValueSetArray ()
 Set this value as an empty array.
 
SizeType Size () const
 Get the number of elements in array.
 
SizeType Capacity () const
 Get the capacity of array.
 
bool Empty () const
 Check whether the array is empty.
 
void Clear ()
 Remove all elements in the array. More...
 
GenericValueoperator[] (SizeType index)
 Get an element from array by index. More...
 
const GenericValueoperator[] (SizeType index) const
 
ValueIterator Begin ()
 Element iterator.
 
ValueIterator End ()
 
ConstValueIterator Begin () const
 
ConstValueIterator End () const
 
GenericValueReserve (SizeType newCapacity, Allocator &allocator)
 Request the array to have enough capacity to store elements. More...
 
GenericValuePushBack (GenericValue &value, Allocator &allocator)
 Append a value at the end of the array. More...
 
template<typename T >
GenericValuePushBack (T value, Allocator &allocator)
 
GenericValuePopBack ()
 Remove the last element in the array.
 
Number
int GetInt () const
 
unsigned GetUint () const
 
int64_t GetInt64 () const
 
uint64_t GetUint64 () const
 
double GetDouble () const
 
GenericValueSetInt (int i)
 
GenericValueSetUint (unsigned u)
 
GenericValueSetInt64 (int64_t i64)
 
GenericValueSetUint64 (uint64_t u64)
 
GenericValueSetDouble (double d)
 
String
const ChGetString () const
 
SizeType GetStringLength () const
 Get the length of string. More...
 
GenericValueSetString (const Ch *s, SizeType length)
 Set this value as a string without copying source string. More...
 
GenericValueSetString (const Ch *s)
 Set this value as a string without copying source string. More...
 
GenericValueSetString (const Ch *s, SizeType length, Allocator &allocator)
 Set this value as a string by copying from source string. More...
 
GenericValueSetString (const Ch *s, Allocator &allocator)
 Set this value as a string by copying from source string. More...
 

Private Types

enum  {
  kBoolFlag = 0x100, kNumberFlag = 0x200, kIntFlag = 0x400, kUintFlag = 0x800,
  kInt64Flag = 0x1000, kUint64Flag = 0x2000, kDoubleFlag = 0x4000, kStringFlag = 0x100000,
  kCopyFlag = 0x200000, kNullFlag = kNullType, kTrueFlag = kTrueType | kBoolFlag, kFalseFlag = kFalseType | kBoolFlag,
  kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag, kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag, kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag, kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag,
  kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag, kConstStringFlag = kStringType | kStringFlag, kCopyStringFlag = kStringType | kStringFlag | kCopyFlag, kObjectFlag = kObjectType,
  kArrayFlag = kArrayType, kTypeMask = 0xFF
}
 

Private Member Functions

void SetArrayRaw (GenericValue *values, SizeType count, Allocator &alloctaor)
 
void SetObjectRaw (Member *members, SizeType count, Allocator &alloctaor)
 Initialize this value as object with initial data, without calling destructor.
 
void SetStringRaw (const Ch *s, SizeType length)
 Initialize this value as constant string, without calling destructor.
 
void SetStringRaw (const Ch *s, SizeType length, Allocator &allocator)
 Initialize this value as copy string with initial data, without calling destructor.
 
void RawAssign (GenericValue &rhs)
 Assignment without calling destructor.
 

Private Attributes

Data data_
 
unsigned flags_
 

Static Private Attributes

static const SizeType kDefaultArrayCapacity = 16
 
static const SizeType kDefaultObjectCapacity = 16
 

Friends

template<typename , typename >
class GenericDocument
 

Constructors and destructor.

 GenericValue ()
 Default constructor creates a null value.
 
 GenericValue (Type type)
 Constructor with JSON value type. More...
 
 GenericValue (bool b)
 Constructor for boolean value.
 
 GenericValue (int i)
 Constructor for int value.
 
 GenericValue (unsigned u)
 Constructor for unsigned value.
 
 GenericValue (int64_t i64)
 Constructor for int64_t value.
 
 GenericValue (uint64_t u64)
 Constructor for uint64_t value.
 
 GenericValue (double d)
 Constructor for double value.
 
 GenericValue (const Ch *s, SizeType length)
 Constructor for constant string (i.e. do not make a copy of string)
 
 GenericValue (const Ch *s)
 Constructor for constant string (i.e. do not make a copy of string)
 
 GenericValue (const Ch *s, SizeType length, Allocator &allocator)
 Constructor for copy-string (i.e. do make a copy of string)
 
 GenericValue (const Ch *s, Allocator &allocator)
 Constructor for copy-string (i.e. do make a copy of string)
 
 ~GenericValue ()
 Destructor. More...
 
 GenericValue (const GenericValue &rhs)
 Copy constructor is not permitted.
 

Detailed Description

template<typename Encoding, typename Allocator>
class rapidjson::GenericValue< Encoding, Allocator >

Represents a JSON value. Use Value for UTF8 encoding and default allocator.

A JSON value can be one of 7 types. This class is a variant type supporting these types.

Use the Value if UTF8 and default allocator

Template Parameters
EncodingEncoding of the value. (Even non-string values need to have the same encoding in a document)
AllocatorAllocator type for allocating memory of object, array and string.

Constructor & Destructor Documentation

template<typename Encoding, typename Allocator>
rapidjson::GenericValue< Encoding, Allocator >::GenericValue ( Type  type)
inline

Constructor with JSON value type.

This creates a Value of specified type with default content.

Parameters
typeType of the value.
Note
Default content for number is zero.
template<typename Encoding, typename Allocator>
rapidjson::GenericValue< Encoding, Allocator >::~GenericValue ( )
inline

Destructor.

Need to destruct elements of array, members of object, or copy-string.

Here is the caller graph for this function:

Member Function Documentation

template<typename Encoding, typename Allocator>
template<typename Handler >
const GenericValue& rapidjson::GenericValue< Encoding, Allocator >::Accept ( Handler handler) const
inline

Generate events of this value to a Handler.

This function adopts the GoF visitor pattern. Typical usage is to output this JSON value as JSON text via Writer, which is a Handler. It can also be used to deep clone this value via GenericDocument, which is also a Handler.

Template Parameters
Handlertype of handler.
Parameters
handlerAn object implementing concept Handler.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::AddMember ( GenericValue< Encoding, Allocator > &  name,
GenericValue< Encoding, Allocator > &  value,
Allocator allocator 
)
inline

Add a member (name-value pair) to the object.

Parameters
nameA string value as name of member.
valueValue of any type.
allocatorAllocator for reallocating memory.
Returns
The value itself for fluent API.
Note
The ownership of name and value will be transfered to this object if success.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
void rapidjson::GenericValue< Encoding, Allocator >::Clear ( )
inline

Remove all elements in the array.

This function do not deallocate memory in the array, i.e. the capacity is unchanged.

template<typename Encoding, typename Allocator>
Member* rapidjson::GenericValue< Encoding, Allocator >::FindMember ( const Ch name)
inline

Find member by name.

Returns
Return the member if exists. Otherwise returns null pointer.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
SizeType rapidjson::GenericValue< Encoding, Allocator >::GetStringLength ( ) const
inline

Get the length of string.

Since rapidjson permits "\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength().

template<typename Encoding, typename Allocator>
bool rapidjson::GenericValue< Encoding, Allocator >::HasMember ( const Ch name) const
inline

Check whether a member exists in the object.

Note
It is better to use FindMember() directly if you need the obtain the value as well.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::operator= ( GenericValue< Encoding, Allocator > &  rhs)
inline

Assignment with move semantics.

Parameters
rhsSource of the assignment. It will become a null value after assignment.
template<typename Encoding, typename Allocator>
template<typename T >
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::operator= ( value)
inline

Assignment with primitive types.

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t, const Ch*
Parameters
valueThe value to be assigned.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::operator[] ( const Ch name)
inline

Get the value associated with the name.

Note
In version 0.1x, if the member is not found, this function returns a null value. This makes issue 7. Since 0.2, if the name is not correct, it will assert. If user is unsure whether a member exists, user should use HasMember() first. A better approach is to use the now public FindMember().
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::operator[] ( SizeType  index)
inline

Get an element from array by index.

Parameters
indexZero-based index of element.
Note
Value a(kArrayType);
a.PushBack(123);
int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type.
int y = a[SizeType(0)].GetInt(); // Cast to SizeType will work.
int z = a[0u].GetInt(); // This works too.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::PushBack ( GenericValue< Encoding, Allocator > &  value,
Allocator allocator 
)
inline

Append a value at the end of the array.

Parameters
valueThe value to be appended.
allocatorThe allocator for allocating memory. It must be the same one use previously.
Returns
The value itself for fluent API.
Note
The ownership of the value will be transfered to this object if success.
If the number of elements to be appended is known, calls Reserve() once first may be more efficient.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
bool rapidjson::GenericValue< Encoding, Allocator >::RemoveMember ( const Ch name)
inline

Remove a member in object by its name.

Parameters
nameName of member to be removed.
Returns
Whether the member existed.
Note
Removing member is implemented by moving the last member. So the ordering of members is changed.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::Reserve ( SizeType  newCapacity,
Allocator allocator 
)
inline

Request the array to have enough capacity to store elements.

Parameters
newCapacityThe capacity that the array at least need to have.
allocatorThe allocator for allocating memory. It must be the same one use previously.
Returns
The value itself for fluent API.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetString ( const Ch s,
SizeType  length 
)
inline

Set this value as a string without copying source string.

This version has better performance with supplied length, and also support string containing null character.

Parameters
ssource string pointer.
lengthThe length of source string, excluding the trailing null terminator.
Returns
The value itself for fluent API.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetString ( const Ch s)
inline

Set this value as a string without copying source string.

Parameters
ssource string pointer.
Returns
The value itself for fluent API.

Here is the caller graph for this function:

template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetString ( const Ch s,
SizeType  length,
Allocator allocator 
)
inline

Set this value as a string by copying from source string.

This version has better performance with supplied length, and also support string containing null character.

Parameters
ssource string.
lengthThe length of source string, excluding the trailing null terminator.
allocatorAllocator for allocating copied buffer. Commonly use document.GetAllocator().
Returns
The value itself for fluent API.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetString ( const Ch s,
Allocator allocator 
)
inline

Set this value as a string by copying from source string.

Parameters
ssource string.
allocatorAllocator for allocating copied buffer. Commonly use document.GetAllocator().
Returns
The value itself for fluent API.

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
  • /home/travis/build/urho3d/Urho3D/Source/Urho3D/Resource/JSONValue.h
  • /home/travis/build/urho3d/Urho3D/Source/ThirdParty/rapidjson/include/rapidjson/document.h