Torque3D Documentation / _generateds / rapidjson::GenericValue

rapidjson::GenericValue

Engine/source/persistence/rapidjson/document.h

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

More...

Classes:

String

enum
_Anonymous_ {
  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
}

Get the length of string.

SetString(const Ch * s, SizeType length)

Set this value as a string without copying source string.

Set this value as a string without copying source string.

SetString(const Ch * s, SizeType length, Allocator & allocator)

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

SetString(const Ch * s, Allocator & allocator)

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

Accept(Handler & handler)

Generate events of this value to a Handler.

SetArrayRaw(GenericValue * values, SizeType count, Allocator & alloctaor)
SetObjectRaw(Member * members, SizeType count, Allocator & alloctaor)

Initialize this value as object with initial data, without calling destructor.

Initialize this value as constant string, without calling destructor.

SetStringRaw(const Ch * s, SizeType length, Allocator & allocator)

Initialize this value as copy string with initial data, without calling destructor.

Assignment without calling destructor.

Constructors and destructor.

Default constructor creates a null value.

Constructor with JSON value type.

GenericValue(bool b)

Constructor for boolean value.

GenericValue(int i)

Constructor for int value.

GenericValue(unsigned u)

Constructor for unsigned value.

Constructor for int64_t value.

Constructor for uint64_t value.

GenericValue(double d)

Constructor for double value.

Constructor for constant string (i.e. do not make a copy of string)

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)

Destructor.

Copy constructor is not permitted.

Assignment operators

Assignment with move semantics.

operator=(T value)

Assignment with primitive types.

Type

bool
bool
bool
bool
bool
bool
bool
bool
bool
bool
bool
bool
bool

Bool

bool

Object

Set this value as an empty object.

Get the value associated with the name.

bool
HasMember(const Ch * name)

Check whether a member exists in the object.

Find member by name.

AddMember(GenericValue & name, GenericValue & value, Allocator & allocator)

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

AddMember(const Ch * name, Allocator & nameAllocator, GenericValue & value, Allocator & allocator)
AddMember(const Ch * name, GenericValue & value, Allocator & allocator)
AddMember(const Ch * name, T value, Allocator & allocator)
bool

Remove a member in object by its name.

Array

Set this value as an empty array.

Size()

Get the number of elements in array.

Get the capacity of array.

bool

Check whether the array is empty.

Remove all elements in the array.

Get an element from array by index.

Element iterator.

Reserve(SizeType newCapacity, Allocator & allocator)

Request the array to have enough capacity to store elements.

PushBack(GenericValue & value, Allocator & allocator)

Append a value at the end of the array.

PushBack(T value, Allocator & allocator)

Remove the last element in the array.

Public Types

AllocatorType 

Allocator type from template parameter.

Encoding::Ch
Ch 

Character type derived from Encoding.

ConstMemberIterator 

Constant member iterator for iterating in object.

ConstValueIterator 

Constant value iterator for iterating in array.

EncodingType 

Encoding type from template parameter.

MemberIterator 

Member iterator for iterating in object.

ValueIterator 

Value iterator for iterating in array.

Detailed Description

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

Parameters:

Encoding of the value. (Even non-string values need to have the same encoding in a document)

Allocator type for allocating memory of object, array and string.

String

@82

Enumerator

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
GetString()

GetStringLength()

Get the length of string.

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

SetString(const Ch * s, SizeType length)

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:

s

source string pointer.

length

The length of source string, excluding the trailing null terminator.

return:

The value itself for fluent API.

SetString(const Ch * s)

Set this value as a string without copying source string.

Parameters:

s

source string pointer.

return:

The value itself for fluent API.

SetString(const Ch * s, SizeType length, Allocator & allocator)

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:

s

source string.

length

The length of source string, excluding the trailing null terminator.

allocator

Allocator for allocating copied buffer. Commonly use document.GetAllocator().

return:

The value itself for fluent API.

SetString(const Ch * s, Allocator & allocator)

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

Parameters:

s

source string.

allocator

Allocator for allocating copied buffer. Commonly use document.GetAllocator().

return:

The value itself for fluent API.

Accept(Handler & handler)

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. Parameters:

type of handler.

Parameters:
handler

An object implementing concept Handler.

SetArrayRaw(GenericValue * values, SizeType count, Allocator & alloctaor)

SetObjectRaw(Member * members, SizeType count, Allocator & alloctaor)

Initialize this value as object with initial data, without calling destructor.

SetStringRaw(const Ch * s, SizeType length)

Initialize this value as constant string, without calling destructor.

SetStringRaw(const Ch * s, SizeType length, Allocator & allocator)

Initialize this value as copy string with initial data, without calling destructor.

RawAssign(GenericValue & rhs)

Assignment without calling destructor.

const SizeType kDefaultArrayCapacity 
const SizeType kDefaultObjectCapacity 
Data data_ 
unsigned flags_ 

Constructors and destructor.

GenericValue()

Default constructor creates a null value.

GenericValue(Type type)

Constructor with JSON value type.

This creates a Value of specified type with default content. Parameters:

type

Type of the value.

note:

Default content for number is zero.

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.

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

GenericValue(const GenericValue & rhs)

Copy constructor is not permitted.

Assignment operators

operator=(GenericValue & rhs)

Assignment with move semantics.

Parameters:

rhs

Source of the assignment. It will become a null value after assignment.

operator=(T value)

Assignment with primitive types.

Parameters:

T

Either Type, int, unsigned, int64_t, uint64_t, const Ch*

Parameters:
value

The value to be assigned.

Type

GetType()

IsNull()

IsFalse()

IsTrue()

IsBool()

IsObject()

IsArray()

IsNumber()

IsInt()

IsUint()

IsInt64()

IsUint64()

IsDouble()

IsString()

Null

SetNull()

Bool

GetBool()

SetBool(bool b)

Object

SetObject()

Set this value as an empty object.

operator[](const Ch * name)

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().

operator[](const Ch * name)

MemberBegin()

Member iterators.

MemberEnd()

MemberBegin()

MemberEnd()

HasMember(const Ch * name)

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.

FindMember(const Ch * name)

Find member by name.

return:

Return the member if exists. Otherwise returns null pointer.

FindMember(const Ch * name)

AddMember(GenericValue & name, GenericValue & value, Allocator & allocator)

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

Parameters:

name

A string value as name of member.

value

Value of any type.

allocator

Allocator for reallocating memory.

return:

The value itself for fluent API.

note:

The ownership of name and value will be transfered to this object if success.

AddMember(const Ch * name, Allocator & nameAllocator, GenericValue & value, Allocator & allocator)

AddMember(const Ch * name, GenericValue & value, Allocator & allocator)

AddMember(const Ch * name, T value, Allocator & allocator)

RemoveMember(const Ch * name)

Remove a member in object by its name.

Parameters:

name

Name of member to be removed.

return:

Whether the member existed.

note:

Removing member is implemented by moving the last member. So the ordering of members is changed.

Array

SetArray()

Set this value as an empty array.

Size()

Get the number of elements in array.

Capacity()

Get the capacity of array.

Empty()

Check whether the array is empty.

Clear()

Remove all elements in the array.

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

operator[](SizeType index)

Get an element from array by index.

Parameters:

index

Zero-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.

operator[](SizeType index)

Begin()

Element iterator.

End()

Begin()

End()

Reserve(SizeType newCapacity, Allocator & allocator)

Request the array to have enough capacity to store elements.

Parameters:

newCapacity

The capacity that the array at least need to have.

allocator

The allocator for allocating memory. It must be the same one use previously.

return:

The value itself for fluent API.

PushBack(GenericValue & value, Allocator & allocator)

Append a value at the end of the array.

Parameters:

value

The value to be appended.

allocator

The allocator for allocating memory. It must be the same one use previously.

return:

The value itself for fluent API.

note:

The ownership of the value will be transfered to this object if success.

note:

If the number of elements to be appended is known, calls Reserve() once first may be more efficient.

PushBack(T value, Allocator & allocator)

PopBack()

Remove the last element in the array.

Number

GetInt()

GetUint()

GetInt64()

GetUint64()

GetDouble()

SetInt(int i)

SetUint(unsigned u)

SetInt64(int64_t i64)

SetUint64(uint64_t u64)

SetDouble(double d)

Public Types

typedef Allocator AllocatorType 

Allocator type from template parameter.

typedef Encoding::Ch Ch 

Character type derived from Encoding.

typedef const Member * ConstMemberIterator 

Constant member iterator for iterating in object.

typedef const GenericValue * ConstValueIterator 

Constant value iterator for iterating in array.

typedef Encoding EncodingType 

Encoding type from template parameter.

typedef Member * MemberIterator 

Member iterator for iterating in object.

typedef GenericValue * ValueIterator 

Value iterator for iterating in array.