Represents a JSON value. Use Value for UTF8 encoding and default allocator. More...
#include <document.h>
Public Types | |
typedef GenericMember < Encoding, Allocator > | Member |
Name-value pair in an object. | |
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 GenericStringRef< Ch > | StringRefType |
Reference to a constant string. | |
typedef GenericMemberIterator < false, Encoding, Allocator > ::Iterator | MemberIterator |
Member iterator for iterating in object. | |
typedef GenericMemberIterator < true, Encoding, Allocator > ::Iterator | ConstMemberIterator |
Constant member iterator for iterating in object. | |
typedef GenericValue * | ValueIterator |
Value iterator for iterating in array. | |
typedef const GenericValue * | ConstValueIterator |
Constant value iterator for iterating in array. | |
typedef GenericValue< Encoding, Allocator > | ValueType |
Value type of itself. | |
Public Member Functions | |
template<typename Handler > | |
bool | Accept (Handler &handler) const |
Generate events of this value to a Handler. 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 | |
GenericValue & | SetNull () |
Bool | |
bool | GetBool () const |
Set boolean value. | |
GenericValue & | SetBool (bool b) |
Object | |
GenericValue & | SetObject () |
Set this value as an empty object. More... | |
SizeType | MemberCount () const |
Get the number of members in the object. | |
bool | ObjectEmpty () const |
Check whether the object is empty. | |
template<typename T > | |
GenericValue & | operator[] (T *name) |
Get a value from an object associated with the name. More... | |
template<typename T > | |
const GenericValue & | operator[] (T *name) const |
template<typename SourceAllocator > | |
GenericValue & | operator[] (const GenericValue< Encoding, SourceAllocator > &name) |
Get a value from an object associated with the name. More... | |
template<typename SourceAllocator > | |
const GenericValue & | operator[] (const GenericValue< Encoding, SourceAllocator > &name) const |
GenericValue & | operator[] (const std::basic_string< Ch > &name) |
Get a value from an object associated with name (string object). | |
const GenericValue & | operator[] (const std::basic_string< Ch > &name) const |
ConstMemberIterator | MemberBegin () const |
Const member iterator. More... | |
ConstMemberIterator | MemberEnd () const |
Const past-the-end member iterator. More... | |
MemberIterator | MemberBegin () |
Member iterator. More... | |
MemberIterator | MemberEnd () |
Past-the-end member iterator More... | |
bool | HasMember (const Ch *name) const |
Check whether a member exists in the object. More... | |
bool | HasMember (const std::basic_string< Ch > &name) const |
Check whether a member exists in the object with string object. More... | |
template<typename SourceAllocator > | |
bool | HasMember (const GenericValue< Encoding, SourceAllocator > &name) const |
Check whether a member exists in the object with GenericValue name. More... | |
MemberIterator | FindMember (const Ch *name) |
Find member by name. More... | |
ConstMemberIterator | FindMember (const Ch *name) const |
template<typename SourceAllocator > | |
MemberIterator | FindMember (const GenericValue< Encoding, SourceAllocator > &name) |
Find member by name. More... | |
template<typename SourceAllocator > | |
ConstMemberIterator | FindMember (const GenericValue< Encoding, SourceAllocator > &name) const |
MemberIterator | FindMember (const std::basic_string< Ch > &name) |
Find member by string object name. More... | |
ConstMemberIterator | FindMember (const std::basic_string< Ch > &name) const |
GenericValue & | AddMember (GenericValue &name, GenericValue &value, Allocator &allocator) |
Add a member (name-value pair) to the object. More... | |
GenericValue & | AddMember (GenericValue &name, StringRefType value, Allocator &allocator) |
Add a constant string value as member (name-value pair) to the object. More... | |
GenericValue & | AddMember (GenericValue &name, std::basic_string< Ch > &value, Allocator &allocator) |
Add a string object as member (name-value pair) to the object. More... | |
template<typename T > | |
GenericValue & | AddMember (GenericValue &name, T value, Allocator &allocator) |
Add any primitive value as member (name-value pair) to the object. More... | |
GenericValue & | AddMember (StringRefType name, GenericValue &value, Allocator &allocator) |
Add a member (name-value pair) to the object. More... | |
GenericValue & | AddMember (StringRefType name, StringRefType value, Allocator &allocator) |
Add a constant string value as member (name-value pair) to the object. More... | |
template<typename T > | |
GenericValue & | AddMember (StringRefType name, T value, Allocator &allocator) |
Add any primitive value as member (name-value pair) to the object. More... | |
void | RemoveAllMembers () |
Remove all members in the object. More... | |
bool | RemoveMember (const Ch *name) |
Remove a member in object by its name. More... | |
bool | RemoveMember (const std::basic_string< Ch > &name) |
template<typename SourceAllocator > | |
bool | RemoveMember (const GenericValue< Encoding, SourceAllocator > &name) |
MemberIterator | RemoveMember (MemberIterator m) |
Remove a member in object by iterator. More... | |
MemberIterator | EraseMember (ConstMemberIterator pos) |
Remove a member from an object by iterator. More... | |
MemberIterator | EraseMember (ConstMemberIterator first, ConstMemberIterator last) |
Remove members in the range [first, last) from an object. More... | |
bool | EraseMember (const Ch *name) |
Erase a member in object by its name. More... | |
bool | EraseMember (const std::basic_string< Ch > &name) |
template<typename SourceAllocator > | |
bool | EraseMember (const GenericValue< Encoding, SourceAllocator > &name) |
Array | |
GenericValue & | SetArray () |
Set this value as an empty array. More... | |
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... | |
GenericValue & | operator[] (SizeType index) |
Get an element from array by index. More... | |
const GenericValue & | operator[] (SizeType index) const |
ValueIterator | Begin () |
Element iterator. More... | |
ValueIterator | End () |
Past-the-end element iterator More... | |
ConstValueIterator | Begin () const |
Constant element iterator. More... | |
ConstValueIterator | End () const |
Constant past-the-end element iterator. More... | |
GenericValue & | Reserve (SizeType newCapacity, Allocator &allocator) |
Request the array to have enough capacity to store elements. More... | |
GenericValue & | PushBack (GenericValue &value, Allocator &allocator) |
Append a GenericValue at the end of the array. More... | |
GenericValue & | PushBack (StringRefType value, Allocator &allocator) |
Append a constant string reference at the end of the array. More... | |
template<typename T > | |
GenericValue & | PushBack (T value, Allocator &allocator) |
Append a primitive value at the end of the array. More... | |
GenericValue & | PopBack () |
Remove the last element in the array. More... | |
ValueIterator | Erase (ConstValueIterator pos) |
Remove an element of array by iterator. More... | |
ValueIterator | Erase (ConstValueIterator first, ConstValueIterator last) |
Remove elements in the range [first, last) of the array. More... | |
Number | |
int | GetInt () const |
unsigned | GetUint () const |
int64_t | GetInt64 () const |
uint64_t | GetUint64 () const |
double | GetDouble () const |
GenericValue & | SetInt (int i) |
GenericValue & | SetUint (unsigned u) |
GenericValue & | SetInt64 (int64_t i64) |
GenericValue & | SetUint64 (uint64_t u64) |
GenericValue & | SetDouble (double d) |
String | |
const Ch * | GetString () const |
SizeType | GetStringLength () const |
Get the length of string. More... | |
GenericValue & | SetString (const Ch *s, SizeType length) |
Set this value as a string without copying source string. More... | |
GenericValue & | SetString (StringRefType s) |
Set this value as a string without copying source string. More... | |
GenericValue & | SetString (const Ch *s, SizeType length, Allocator &allocator) |
Set this value as a string by copying from source string. More... | |
GenericValue & | SetString (const Ch *s, Allocator &allocator) |
Set this value as a string by copying from source string. More... | |
GenericValue & | SetString (const std::basic_string< Ch > &s, Allocator &allocator) |
Set this value as a string by copying from source string. More... | |
Friends | |
template<typename , typename > | |
class | GenericValue |
template<typename , typename , typename > | |
class | GenericDocument |
Constructors and destructor. | |
GenericValue () RAPIDJSON_NOEXCEPT | |
Default constructor creates a null value. | |
GenericValue (Type type) RAPIDJSON_NOEXCEPT | |
Constructor with JSON value type. More... | |
template<typename SourceAllocator > | |
GenericValue (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator) | |
Explicit copy constructor (with allocator) More... | |
GenericValue (bool b) RAPIDJSON_NOEXCEPT | |
Constructor for boolean value. More... | |
GenericValue (int i) RAPIDJSON_NOEXCEPT | |
Constructor for int value. | |
GenericValue (unsigned u) RAPIDJSON_NOEXCEPT | |
Constructor for unsigned value. | |
GenericValue (int64_t i64) RAPIDJSON_NOEXCEPT | |
Constructor for int64_t value. | |
GenericValue (uint64_t u64) RAPIDJSON_NOEXCEPT | |
Constructor for uint64_t value. | |
GenericValue (double d) RAPIDJSON_NOEXCEPT | |
Constructor for double value. | |
GenericValue (const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT | |
Constructor for constant string (i.e. do not make a copy of string) | |
GenericValue (StringRefType s) RAPIDJSON_NOEXCEPT | |
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 (const std::basic_string< Ch > &s, Allocator &allocator) | |
Constructor for copy-string from a string object (i.e. do make a copy of string) More... | |
~GenericValue () | |
Destructor. More... | |
Assignment operators | |
void | swap (GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT |
free-standing swap function helper More... | |
GenericValue & | operator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT |
Assignment with move semantics. More... | |
GenericValue & | operator= (StringRefType str) RAPIDJSON_NOEXCEPT |
Assignment of constant string reference (no copy) More... | |
template<typename T > | |
GenericValue & | operator= (T value) |
Assignment with primitive types. More... | |
template<typename SourceAllocator > | |
GenericValue & | CopyFrom (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator) |
Deep-copy assignment from Value. More... | |
GenericValue & | Swap (GenericValue &other) RAPIDJSON_NOEXCEPT |
Exchange the contents of this value with those of other. More... | |
GenericValue & | Move () RAPIDJSON_NOEXCEPT |
Prepare Value for move semantics. More... | |
Equal-to and not-equal-to operators | |
template<typename T > | |
bool | operator== (const T &lhs, const GenericValue &rhs) |
Equal-to operator with arbitrary types (symmetric version) More... | |
template<typename T > | |
bool | operator!= (const T &lhs, const GenericValue &rhs) |
Not-Equal-to operator with arbitrary types (symmetric version) More... | |
template<typename SourceAllocator > | |
bool | operator== (const GenericValue< Encoding, SourceAllocator > &rhs) const |
Equal-to operator. More... | |
bool | operator== (const Ch *rhs) const |
Equal-to operator with const C-string pointer. | |
bool | operator== (const std::basic_string< Ch > &rhs) const |
Equal-to operator with string object. More... | |
template<typename T > | |
bool | operator== (const T &rhs) const |
Equal-to operator with primitive types. More... | |
template<typename SourceAllocator > | |
bool | operator!= (const GenericValue< Encoding, SourceAllocator > &rhs) const |
Not-equal-to operator. More... | |
bool | operator!= (const Ch *rhs) const |
Not-equal-to operator with const C-string pointer. | |
template<typename T > | |
bool | operator!= (const T &rhs) const |
Not-equal-to operator with arbitrary types. More... | |
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
|
inlineexplicit |
Constructor with JSON value type.
This creates a Value of specified type with default content.
type | Type of the value. |
|
inline |
Explicit copy constructor (with allocator)
Creates a copy of a Value by using the given Allocator
SourceAllocator | allocator of rhs |
rhs | Value to copy from (read-only) |
allocator | Allocator for allocating copied elements and buffers. Commonly use GenericDocument::GetAllocator(). |
|
inlineexplicit |
Constructor for boolean value.
b | Boolean value |
bool
, if you want to construct a boolean JSON value in such cases.
|
inline |
Constructor for copy-string from a string object (i.e. do make a copy of string)
|
inline |
Destructor.
Need to destruct elements of array, members of object, or copy-string.
|
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.
Handler | type of handler. |
handler | An object implementing concept Handler. |
|
inline |
Add a member (name-value pair) to the object.
name | A string value as name of member. |
value | Value of any type. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
name
and value
will be transferred to this object on success.
|
inline |
Add a constant string value as member (name-value pair) to the object.
name | A string value as name of member. |
value | constant string reference as value of member. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Add a string object as member (name-value pair) to the object.
name | A string value as name of member. |
value | constant string reference as value of member. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Add any primitive value as member (name-value pair) to the object.
T | Either Type, int , unsigned , int64_t , uint64_t |
name | A string value as name of member. |
value | Value of primitive type T as value of member |
allocator | Allocator for reallocating memory. Commonly use GenericDocument::GetAllocator(). |
T
explicitly disallows all pointer types, especially (const
) Ch*. This helps avoiding implicitly referencing character strings with insufficient lifetime, use AddMember(StringRefType, GenericValue&, Allocator&) or AddMember(StringRefType, StringRefType, Allocator&). All other pointer types would implicitly convert to bool
, use an explicit cast instead, if needed.
|
inline |
Add a member (name-value pair) to the object.
name | A constant string reference as name of member. |
value | Value of any type. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
value
will be transferred to this object on success.
|
inline |
Add a constant string value as member (name-value pair) to the object.
name | A constant string reference as name of member. |
value | constant string reference as value of member. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Add any primitive value as member (name-value pair) to the object.
T | Either Type, int , unsigned , int64_t , uint64_t |
name | A constant string reference as name of member. |
value | Value of primitive type T as value of member |
allocator | Allocator for reallocating memory. Commonly use GenericDocument::GetAllocator(). |
T
explicitly disallows all pointer types, especially (const
) Ch*. This helps avoiding implicitly referencing character strings with insufficient lifetime, use AddMember(StringRefType, GenericValue&, Allocator&) or AddMember(StringRefType, StringRefType, Allocator&). All other pointer types would implicitly convert to bool
, use an explicit cast instead, if needed.
|
inline |
Element iterator.
|
inline |
Constant element iterator.
|
inline |
Remove all elements in the array.
This function do not deallocate memory in the array, i.e. the capacity is unchanged.
|
inline |
|
inline |
Past-the-end element iterator
|
inline |
Constant past-the-end element iterator.
|
inline |
|
inline |
Remove elements in the range [first, last) of the array.
first | iterator to the first element to remove |
last | iterator following the last element to remove |
|
inline |
Remove a member from an object by iterator.
pos | iterator to the member to remove |
pos
< MemberEnd() pos
refers to the last element, the MemberEnd() iterator is returned.
|
inline |
Remove members in the range [first, last) from an object.
first | iterator to the first member to remove |
last | iterator following the last member to remove |
first
<= last
<= MemberEnd()
|
inline |
Erase a member in object by its name.
name | Name of member to be removed. |
|
inline |
Find member by name.
name | Member name to be searched. |
NULL
pointer, in case the requested member doesn't exist. For consistency with e.g. std::map
, this has been changed to MemberEnd() now.
|
inline |
Find member by name.
This version is faster because it does not need a StrLen(). It can also handle string with null character.
name | Member name to be searched. |
NULL
pointer, in case the requested member doesn't exist. For consistency with e.g. std::map
, this has been changed to MemberEnd() now.
|
inline |
Find member by string object name.
name | Member name to be searched. |
|
inline |
Get the length of string.
Since rapidjson permits "\\u0000" in the json string, strlen(v.GetString()) may not equal to v.GetStringLength().
|
inline |
Check whether a member exists in the object.
name | Member name to be searched. |
|
inline |
Check whether a member exists in the object with string object.
name | Member name to be searched. |
|
inline |
Check whether a member exists in the object with GenericValue name.
This version is faster because it does not need a StrLen(). It can also handle string with null character.
name | Member name to be searched. |
|
inline |
Const member iterator.
|
inline |
Member iterator.
|
inline |
Const past-the-end member iterator.
|
inline |
Past-the-end member iterator
|
inline |
Prepare Value for move semantics.
|
inline |
Not-equal-to operator.
|
inline |
Not-equal-to operator with arbitrary types.
|
inline |
Assignment with move semantics.
rhs | Source of the assignment. It will become a null value after assignment. |
|
inline |
Assignment of constant string reference (no copy)
str | Constant string reference to be assigned |
|
inline |
Assignment with primitive types.
T | Either Type, int , unsigned , int64_t , uint64_t |
value | The value to be assigned. |
T
explicitly disallows all pointer types, especially (const
) Ch*. This helps avoiding implicitly referencing character strings with insufficient lifetime, use SetString(const Ch*, Allocator&) (for copying) or StringRef() (to explicitly mark the pointer as constant) instead. All other pointer types would implicitly convert to bool
, use SetBool() instead.
|
inline |
Equal-to operator.
false
.
|
inline |
Equal-to operator with string object.
|
inline |
Equal-to operator with primitive types.
T | Either Type, int , unsigned , int64_t , uint64_t , double , true , false |
|
inline |
Get a value from an object associated with the name.
T | Either Ch or const Ch (template used for disambiguation with operator[](SizeType)) |
|
inline |
Get a value from an object associated with the name.
SourceAllocator | Allocator of the name value |
|
inline |
Get an element from array by index.
index | Zero-based index of element. |
|
inline |
Remove the last element in the array.
|
inline |
Append a GenericValue at the end of the array.
value | Value to be appended. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
value
will be transferred to this array on success.
|
inline |
Append a constant string reference at the end of the array.
value | Constant string reference to be appended. |
allocator | Allocator for reallocating memory. It must be the same one used previously. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Append a primitive value at the end of the array.
T | Either Type, int , unsigned , int64_t , uint64_t |
value | Value of primitive type T to be appended. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
T
explicitly disallows all pointer types, especially (const
) Ch*. This helps avoiding implicitly referencing character strings with insufficient lifetime, use PushBack(GenericValue&, Allocator&) or PushBack(StringRefType, Allocator&). All other pointer types would implicitly convert to bool
, use an explicit cast instead, if needed.
|
inline |
Remove all members in the object.
This function do not deallocate memory in the object, i.e. the capacity is unchanged.
|
inline |
Remove a member in object by its name.
name | Name of member to be removed. |
|
inline |
Remove a member in object by iterator.
m | member iterator (obtained by FindMember() or MemberBegin()). |
|
inline |
Request the array to have enough capacity to store elements.
newCapacity | The capacity that the array at least need to have. |
allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Set this value as an empty array.
|
inline |
|
inline |
Set this value as an empty object.
|
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.
s | source string pointer. |
length | The length of source string, excluding the trailing null terminator. |
|
inline |
Set this value as a string without copying source string.
s | source string reference |
|
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.
s | source string. |
length | The length of source string, excluding the trailing null terminator. |
allocator | Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Set this value as a string by copying from source string.
s | source string. |
allocator | Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Set this value as a string by copying from source string.
s | source string. |
allocator | Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator(). |
|
inline |
Exchange the contents of this value with those of other.
other | Another value. |
|
friend |
Not-Equal-to operator with arbitrary types (symmetric version)
|
friend |
Equal-to operator with arbitrary types (symmetric version)
|
friend |