Loading...
Searching...
No Matches
rapidjson::GenericValue< Encoding, Allocator > Class Template Reference

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

`#include <document.h>`

Inheritance diagram for rapidjson::GenericValue< Encoding, Allocator >:

## 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.
typedef GenericArray< false, ValueType > | Array
typedef GenericArray< true, ValueType > | ConstArray
typedef GenericObject< false, ValueType > | Object
typedef GenericObject< true, ValueType > | ConstObject

## Public Member Functions

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
bool | IsLosslessDouble () const
bool | IsFloat () const
bool | IsLosslessFloat () 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.
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.
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.
template<typename SourceAllocator >
const GenericValue & | operator[] (const GenericValue< Encoding, SourceAllocator > &name) const
ConstMemberIterator | MemberBegin () const
| Const member iterator.
ConstMemberIterator | MemberEnd () const
| Const past-the-end member iterator.
MemberIterator | MemberBegin ()
| Member iterator.
MemberIterator | MemberEnd ()
| Past-the-end member iterator
bool | HasMember (const Ch *name) const
| Check whether a member exists in the object.
template<typename SourceAllocator >
bool | HasMember (const GenericValue< Encoding, SourceAllocator > &name) const
| Check whether a member exists in the object with GenericValue name.
MemberIterator | FindMember (const Ch *name)
| Find member by name.
ConstMemberIterator | FindMember (const Ch *name) const
template<typename SourceAllocator >
MemberIterator | FindMember (const GenericValue< Encoding, SourceAllocator > &name)
| Find member by name.
template<typename SourceAllocator >
ConstMemberIterator | FindMember (const GenericValue< Encoding, SourceAllocator > &name) const
GenericValue & | AddMember (GenericValue &name, GenericValue &value, Allocator &allocator)
| Add a member (name-value pair) to the object.
GenericValue & | AddMember (GenericValue &name, StringRefType value, Allocator &allocator)
| Add a constant string value as member (name-value pair) to the object.
template<typename T >
GenericValue & | AddMember (GenericValue &name, T value, Allocator &allocator)
| Add any primitive value as member (name-value pair) to the object.
GenericValue & | AddMember (StringRefType name, GenericValue &value, Allocator &allocator)
| Add a member (name-value pair) to the object.
GenericValue & | AddMember (StringRefType name, StringRefType value, Allocator &allocator)
| Add a constant string value as member (name-value pair) to the object.
template<typename T >
GenericValue & | AddMember (StringRefType name, T value, Allocator &allocator)
| Add any primitive value as member (name-value pair) to the object.
void | RemoveAllMembers ()
| Remove all members in the object.
bool | RemoveMember (const Ch *name)
| Remove a member in object by its name.
template<typename SourceAllocator >
bool | RemoveMember (const GenericValue< Encoding, SourceAllocator > &name)
MemberIterator | RemoveMember (MemberIterator m)
| Remove a member in object by iterator.
MemberIterator | EraseMember (ConstMemberIterator pos)
| Remove a member from an object by iterator.
MemberIterator | EraseMember (ConstMemberIterator first, ConstMemberIterator last)
| Remove members in the range [first, last) from an object.
bool | EraseMember (const Ch *name)
| Erase a member in object by its name.
template<typename SourceAllocator >
bool | EraseMember (const GenericValue< Encoding, SourceAllocator > &name)
Object | GetObject ()
ConstObject | GetObject () const
Number
int | GetInt () const
unsigned | GetUint () const
int64_t | GetInt64 () const
uint64_t | GetUint64 () const
double | GetDouble () const
| Get the value as double type.
float | GetFloat () const
| Get the value as float type.
GenericValue & | SetInt (int i)
GenericValue & | SetUint (unsigned u)
GenericValue & | SetInt64 (int64_t i64)
GenericValue & | SetUint64 (uint64_t u64)
GenericValue & | SetDouble (double d)
GenericValue & | SetFloat (float f)
String
const Ch * | GetString () const
SizeType | GetStringLength () const
| Get the length of string.
GenericValue & | SetString (const Ch *s, SizeType length)
| Set this value as a string without copying source string.
GenericValue & | SetString (StringRefType s)
| Set this value as a string without copying source string.
GenericValue & | SetString (const Ch *s, SizeType length, Allocator &allocator)
| Set this value as a string by copying from source string.
GenericValue & | SetString (const Ch *s, Allocator &allocator)
| Set this value as a string by copying from source string.

## Array

template<typename , typename , typename >
class | GenericDocument
GenericValue & | SetArray ()
| 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.
GenericValue & | operator[] (SizeType index)
| Get an element from array by index.
const GenericValue & | operator[] (SizeType index) const
ValueIterator | Begin ()
| Element iterator.
ValueIterator | End ()
| Past-the-end element iterator
ConstValueIterator | Begin () const
| Constant element iterator.
ConstValueIterator | End () const
| Constant past-the-end element iterator.
GenericValue & | Reserve (SizeType newCapacity, Allocator &allocator)
| Request the array to have enough capacity to store elements.
GenericValue & | PushBack (GenericValue &value, Allocator &allocator)
| Append a GenericValue at the end of the array.
GenericValue & | PushBack (StringRefType value, Allocator &allocator)
| Append a constant string reference at the end of the array.
template<typename T >
GenericValue & | PushBack (T value, Allocator &allocator)
| Append a primitive value at the end of the array.
GenericValue & | PopBack ()
| Remove the last element in the array.
ValueIterator | Erase (ConstValueIterator pos)
| Remove an element of array by iterator.
ValueIterator | Erase (ConstValueIterator first, ConstValueIterator last)
| Remove elements in the range [first, last) of the array.
Array | GetArray ()
ConstArray | GetArray () const
template<typename T >
bool | Is () const
| Templated version for checking whether this value is type T.
template<typename T >
T | Get () const
template<typename T >
T | Get ()
template<typename T >
ValueType & | Set (const T &data)
template<typename T >
ValueType & | Set (const T &data, AllocatorType &allocator)
template<typename Handler >
bool | Accept (Handler &handler) const
| Generate events of this value to a Handler.

## Assignment operators

void | swap (GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
| free-standing swap function helper
GenericValue & | operator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT
| Assignment with move semantics.
GenericValue & | operator= (StringRefType str) RAPIDJSON_NOEXCEPT
| Assignment of constant string reference (no copy)
template<typename T >
GenericValue & | operator= (T value)
| Assignment with primitive types.
template<typename SourceAllocator >
GenericValue & | CopyFrom (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
| Deep-copy assignment from Value.
GenericValue & | Swap (GenericValue &other) RAPIDJSON_NOEXCEPT
| Exchange the contents of this value with those of other.
GenericValue & | Move () RAPIDJSON_NOEXCEPT
| Prepare Value for move semantics.

## 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)
template<typename T >
bool | operator!= (const T &lhs, const GenericValue &rhs)
| Not-Equal-to operator with arbitrary types (symmetric version)
template<typename SourceAllocator >
bool | operator== (const GenericValue< Encoding, SourceAllocator > &rhs) const
| Equal-to operator.
bool | operator== (const Ch *rhs) const
| Equal-to operator with const C-string pointer.
template<typename T >
bool | operator== (const T &rhs) const
| Equal-to operator with primitive types.
template<typename SourceAllocator >
bool | operator!= (const GenericValue< Encoding, SourceAllocator > &rhs) const
| Not-equal-to operator.
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.

## Constructors and destructor.

| GenericValue () RAPIDJSON_NOEXCEPT
| Default constructor creates a null value.
| GenericValue (Type type) RAPIDJSON_NOEXCEPT
| Constructor with JSON value type.
template<typename SourceAllocator >
| GenericValue (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
| Explicit copy constructor (with allocator)
| GenericValue (bool b) RAPIDJSON_NOEXCEPT
| Constructor for boolean value.
| 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 (Array a) RAPIDJSON_NOEXCEPT
| Constructor for Array.
| GenericValue (Object o) RAPIDJSON_NOEXCEPT
| Constructor for Object.
| ~GenericValue ()
| Destructor.

## Detailed Description

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
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

  Encoding | Encoding of the value. (Even non-string values need to have the same encoding in a document)
  Allocator | Allocator type for allocating memory of object, array and string.

## Constructor & Destructor Documentation

## GenericValue() [1/5]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

rapidjson::GenericValue< Encoding, Allocator >::GenericValue | ( | Type | type | ) |

inline explicit

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() [2/5]

template<typename Encoding , typename Allocator >
template<typename SourceAllocator >

rapidjson::GenericValue< Encoding, Allocator >::GenericValue | ( | const GenericValue< Encoding, SourceAllocator > & | rhs,
|  | Allocator & | allocator
| ) |  |

inline

Explicit copy constructor (with allocator)

Creates a copy of a Value by using the given Allocator

Template Parameters

  SourceAllocator | allocator of `rhs`

Parameters

  rhs | Value to copy from (read-only)
  allocator | Allocator for allocating copied elements and buffers. Commonly use GenericDocument::GetAllocator().

See also
  CopyFrom()

## GenericValue() [3/5]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

rapidjson::GenericValue< Encoding, Allocator >::GenericValue | ( | bool | b | ) |

inline explicit

Constructor for boolean value.

Parameters

  b | Boolean value

Note
  This constructor is limited to real boolean values and rejects implicitly converted types like arbitrary pointers. Use an explicit cast to `bool`, if you want to construct a boolean JSON value in such cases.

## GenericValue() [4/5]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

rapidjson::GenericValue< Encoding, Allocator >::GenericValue | ( | Array | a | ) |

inline

Constructor for Array.

Parameters

  a | An array obtained by `GetArray()`.

Note
  `Array` is always pass-by-value.
  the source array is moved into this value and the sourec array becomes empty.

## GenericValue() [5/5]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

rapidjson::GenericValue< Encoding, Allocator >::GenericValue | ( | Object | o | ) |

inline

Constructor for Object.

Parameters

  o | An object obtained by `GetObject()`.

Note
  `Object` is always pass-by-value.
  the source object is moved into this value and the sourec object becomes empty.

## ~GenericValue()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

rapidjson::GenericValue< Encoding, Allocator >::~GenericValue | ( |  | ) |

inline

Destructor.

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

## Member Function Documentation

## Accept()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename Handler >

bool 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

  Handler | type of handler.

Parameters

  handler | An object implementing concept Handler.

## AddMember() [1/6]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

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

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

Returns
  The value itself for fluent API.

Note
  The ownership of `name` and `value` will be transferred to this object on success.

Precondition
  IsObject() && name.IsString()

Postcondition
  name.IsNull() && value.IsNull()

Note
  Amortized Constant time complexity.

## AddMember() [2/6]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::AddMember | ( | GenericValue< Encoding, Allocator > & | name,
|  | StringRefType | value,
|  | Allocator & | allocator
| ) |  |

inline

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

Parameters

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

Returns
  The value itself for fluent API.

Precondition
  IsObject()

Note
  This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below.
  Amortized Constant time complexity.

## AddMember() [3/6]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::AddMember | ( | GenericValue< Encoding, Allocator > & | name,
|  | T | value,
|  | Allocator & | allocator
| ) |  |

inline

Add any primitive value as member (name-value pair) to the object.

Template Parameters

  T | Either Type, `int`, `unsigned`, `int64_t`, `uint64_t`

Parameters

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

Returns
  The value itself for fluent API.

Precondition
  IsObject()

Note
  The source type `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.
  Amortized Constant time complexity.

## AddMember() [4/6]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::AddMember | ( | StringRefType | name,
|  | GenericValue< Encoding, Allocator > & | value,
|  | Allocator & | allocator
| ) |  |

inline

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

Parameters

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

Returns
  The value itself for fluent API.

Note
  The ownership of `value` will be transferred to this object on success.

Precondition
  IsObject()

Postcondition
  value.IsNull()

Note
  Amortized Constant time complexity.

## AddMember() [5/6]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::AddMember | ( | StringRefType | name,
|  | StringRefType | value,
|  | Allocator & | allocator
| ) |  |

inline

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

Parameters

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

Returns
  The value itself for fluent API.

Precondition
  IsObject()

Note
  This overload is needed to avoid clashes with the generic primitive type AddMember(StringRefType,T,Allocator&) overload below.
  Amortized Constant time complexity.

## AddMember() [6/6]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::AddMember | ( | StringRefType | name,
|  | T | value,
|  | Allocator & | allocator
| ) |  |

inline

Add any primitive value as member (name-value pair) to the object.

Template Parameters

  T | Either Type, `int`, `unsigned`, `int64_t`, `uint64_t`

Parameters

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

Returns
  The value itself for fluent API.

Precondition
  IsObject()

Note
  The source type `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.
  Amortized Constant time complexity.

## Begin() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ValueIterator rapidjson::GenericValue< Encoding, Allocator >::Begin | ( |  | ) |

inline

Element iterator.

Precondition
  IsArray() == true

## Begin() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ConstValueIterator rapidjson::GenericValue< Encoding, Allocator >::Begin | ( |  | ) | const

inline

Constant element iterator.

Precondition
  IsArray() == true

## Clear()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

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.

Note
  Linear time complexity.

## CopyFrom()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::CopyFrom | ( | const GenericValue< Encoding, SourceAllocator > & | rhs,
|  | Allocator & | allocator
| ) |  |

inline

Deep-copy assignment from Value.

Assigns a copy of the Value to the current Value object

Template Parameters

  SourceAllocator | Allocator type of `rhs`

Parameters

  rhs | Value to copy from (read-only)
  allocator | Allocator to use for copying

## End() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ValueIterator rapidjson::GenericValue< Encoding, Allocator >::End | ( |  | ) |

inline

Past-the-end element iterator

Precondition
  IsArray() == true

## End() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ConstValueIterator rapidjson::GenericValue< Encoding, Allocator >::End | ( |  | ) | const

inline

Constant past-the-end element iterator.

Precondition
  IsArray() == true

## Erase() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ValueIterator rapidjson::GenericValue< Encoding, Allocator >::Erase | ( | ConstValueIterator | first,
|  | ConstValueIterator | last
| ) |  |

inline

Remove elements in the range [first, last) of the array.

Parameters

  first | iterator to the first element to remove
  last | iterator following the last element to remove

Precondition
  IsArray() == true && Begin() <= `first` <= `last` <= End()

Returns
  Iterator following the last removed element.

Note
  Linear time complexity.

## Erase() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ValueIterator rapidjson::GenericValue< Encoding, Allocator >::Erase | ( | ConstValueIterator | pos | ) |

inline

Remove an element of array by iterator.

Parameters

  pos | iterator to the element to remove

Precondition
  IsArray() == true && Begin() <= `pos` < End()

Returns
  Iterator following the removed element. If the iterator pos refers to the last element, the End() iterator is returned.

Note
  Linear time complexity.

## EraseMember() [1/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

bool rapidjson::GenericValue< Encoding, Allocator >::EraseMember | ( | const Ch * | name | ) |

inline

Erase a member in object by its name.

Parameters

  name | Name of member to be removed.

Returns
  Whether the member existed.

Note
  Linear time complexity.

## EraseMember() [2/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

MemberIterator rapidjson::GenericValue< Encoding, Allocator >::EraseMember | ( | ConstMemberIterator | first,
|  | ConstMemberIterator | last
| ) |  |

inline

Remove members in the range [first, last) from an object.

Parameters

  first | iterator to the first member to remove
  last | iterator following the last member to remove

Precondition
  IsObject() == true && MemberBegin() <= `first` <= `last` <= MemberEnd()

Returns
  Iterator following the last removed element.

Note
  This function preserves the relative order of the remaining object members.
  Linear time complexity.

## EraseMember() [3/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

MemberIterator rapidjson::GenericValue< Encoding, Allocator >::EraseMember | ( | ConstMemberIterator | pos | ) |

inline

Remove a member from an object by iterator.

Parameters

  pos | iterator to the member to remove

Precondition
  IsObject() == true && MemberBegin() <= `pos` < MemberEnd()

Returns
  Iterator following the removed element. If the iterator `pos` refers to the last element, the MemberEnd() iterator is returned.

Note
  This function preserves the relative order of the remaining object members. If you do not need this, use the more efficient RemoveMember(MemberIterator).
  Linear time complexity.

## FindMember() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

MemberIterator rapidjson::GenericValue< Encoding, Allocator >::FindMember | ( | const Ch * | name | ) |

inline

Find member by name.

Parameters

  name | Member name to be searched.

Precondition
  IsObject() == true

Returns
  Iterator to member, if it exists. Otherwise returns MemberEnd().

Note
  Earlier versions of Rapidjson returned a `NULL` pointer, in case the requested member doesn't exist. For consistency with e.g. `std::map`, this has been changed to MemberEnd() now.
  Linear time complexity.

## FindMember() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >

MemberIterator rapidjson::GenericValue< Encoding, Allocator >::FindMember | ( | const GenericValue< Encoding, SourceAllocator > & | name | ) |

inline

Find member by name.

This version is faster because it does not need a StrLen(). It can also handle string with null character.

Parameters

  name | Member name to be searched.

Precondition
  IsObject() == true

Returns
  Iterator to member, if it exists. Otherwise returns MemberEnd().

Note
  Earlier versions of Rapidjson returned a `NULL` pointer, in case the requested member doesn't exist. For consistency with e.g. `std::map`, this has been changed to MemberEnd() now.
  Linear time complexity.

## GetDouble()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

double rapidjson::GenericValue< Encoding, Allocator >::GetDouble | ( |  | ) | const

inline

Get the value as double type.

Note
  If the value is 64-bit integer type, it may lose precision. Use `IsLosslessDouble()` to check whether the converison is lossless.

## GetFloat()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

float rapidjson::GenericValue< Encoding, Allocator >::GetFloat | ( |  | ) | const

inline

Get the value as float type.

Note
  If the value is 64-bit integer type, it may lose precision. Use `IsLosslessFloat()` to check whether the converison is lossless.

## GetStringLength()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

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

## HasMember() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

bool rapidjson::GenericValue< Encoding, Allocator >::HasMember | ( | const Ch * | name | ) | const

inline

Check whether a member exists in the object.

Parameters

  name | Member name to be searched.

Precondition
  IsObject() == true

Returns
  Whether a member with that name exists.

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

## HasMember() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >

bool rapidjson::GenericValue< Encoding, Allocator >::HasMember | ( | const GenericValue< Encoding, SourceAllocator > & | name | ) | const

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.

Parameters

  name | Member name to be searched.

Precondition
  IsObject() == true

Returns
  Whether a member with that name exists.

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

## Is()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

bool rapidjson::GenericValue< Encoding, Allocator >::Is | ( |  | ) | const

inline

Templated version for checking whether this value is type T.

Template Parameters

  T | Either `bool`, `int`, `unsigned`, `int64_t`, `uint64_t`, `double`, `float`, `const` `char*`, `std::basic_string<Ch>`

## MemberBegin() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

MemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberBegin | ( |  | ) |

inline

Member iterator.

Precondition
  IsObject() == true

## MemberBegin() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ConstMemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberBegin | ( |  | ) | const

inline

Const member iterator.

Precondition
  IsObject() == true

## MemberEnd() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

MemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberEnd | ( |  | ) |

inline

Past-the-end member iterator

Precondition
  IsObject() == true

## MemberEnd() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

ConstMemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberEnd | ( |  | ) | const

inline

Const past-the-end member iterator.

Precondition
  IsObject() == true

## Move()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::Move | ( |  | ) |

inline

Prepare Value for move semantics.

Returns
  *this

## operator!=() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >

bool rapidjson::GenericValue< Encoding, Allocator >::operator!= | ( | const GenericValue< Encoding, SourceAllocator > & | rhs | ) | const

inline

Not-equal-to operator.

Returns
  !(*this == rhs)

## operator!=() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

bool rapidjson::GenericValue< Encoding, Allocator >::operator!= | ( | const T & | rhs | ) | const

inline

Not-equal-to operator with arbitrary types.

Returns
  !(*this == rhs)

## operator=() [1/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::operator= | ( | GenericValue< Encoding, Allocator > & | rhs | ) |

inline

Assignment with move semantics.

Parameters

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

## operator=() [2/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::operator= | ( | StringRefType | str | ) |

inline

Assignment of constant string reference (no copy)

Parameters

  str | Constant string reference to be assigned

Note
  This overload is needed to avoid clashes with the generic primitive type assignment overload below.

See also
  GenericStringRef, operator=(T)

## operator=() [3/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::operator= | ( | T | value | ) |

inline

Assignment with primitive types.

Template Parameters

  T | Either Type, `int`, `unsigned`, `int64_t`, `uint64_t`

Parameters

  value | The value to be assigned.

Note
  The source type `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.

## operator==() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >

bool rapidjson::GenericValue< Encoding, Allocator >::operator== | ( | const GenericValue< Encoding, SourceAllocator > & | rhs | ) | const

inline

Equal-to operator.

Note
  If an object contains duplicated named member, comparing equality with any object is always `false`.
  Linear time complexity (number of all values in the subtree and total lengths of all strings).

## operator==() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

bool rapidjson::GenericValue< Encoding, Allocator >::operator== | ( | const T & | rhs | ) | const

inline

Equal-to operator with primitive types.

Template Parameters

  T | Either Type, `int`, `unsigned`, `int64_t`, `uint64_t`, `double`, `true`, `false`

## operator[]() [1/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::operator[] | ( | const GenericValue< Encoding, SourceAllocator > & | name | ) |

inline

Get a value from an object associated with the name.

Precondition
  IsObject() == true

Template Parameters

  SourceAllocator | Allocator of the `name` value

Note
  Compared to operator[](T*), this version is faster because it does not need a StrLen(). And it can also handle strings with embedded null characters.
  Linear time complexity.

## operator[]() [2/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::operator[] | ( | SizeType | index | ) |

inline

Get an element from array by index.

Precondition
  IsArray() == true

Parameters

  index | Zero-based index of element.

See also
  operator[](T*)

## operator[]() [3/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::operator[] | ( | T * | name | ) |

inline

Get a value from an object associated with the name.

Precondition
  IsObject() == true

Template Parameters

  T | Either `Ch` or `const` `Ch` (template used for disambiguation with operator[](SizeType))

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 FindMember().
  Linear time complexity.

## PopBack()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::PopBack | ( |  | ) |

inline

Remove the last element in the array.

Note
  Constant time complexity.

## PushBack() [1/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::PushBack | ( | GenericValue< Encoding, Allocator > & | value,
|  | Allocator & | allocator
| ) |  |

inline

Append a GenericValue at the end of the array.

Parameters

  value | Value to be appended.
  allocator | Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().

Precondition
  IsArray() == true

Postcondition
  value.IsNull() == true

Returns
  The value itself for fluent API.

Note
  The ownership of `value` will be transferred to this array on success.
  If the number of elements to be appended is known, calls Reserve() once first may be more efficient.
  Amortized constant time complexity.

## PushBack() [2/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::PushBack | ( | StringRefType | value,
|  | Allocator & | allocator
| ) |  |

inline

Append a constant string reference at the end of the array.

Parameters

  value | Constant string reference to be appended.
  allocator | Allocator for reallocating memory. It must be the same one used previously. Commonly use GenericDocument::GetAllocator().

Precondition
  IsArray() == true

Returns
  The value itself for fluent API.

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

See also
  GenericStringRef

## PushBack() [3/3]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::PushBack | ( | T | value,
|  | Allocator & | allocator
| ) |  |

inline

Append a primitive value at the end of the array.

Template Parameters

  T | Either Type, `int`, `unsigned`, `int64_t`, `uint64_t`

Parameters

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

Precondition
  IsArray() == true

Returns
  The value itself for fluent API.

Note
  If the number of elements to be appended is known, calls Reserve() once first may be more efficient.
  The source type `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.
  Amortized constant time complexity.

## RemoveAllMembers()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

void rapidjson::GenericValue< Encoding, Allocator >::RemoveAllMembers | ( |  | ) |

inline

Remove all members in the object.

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

Note
  Linear time complexity.

## RemoveMember() [1/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

bool rapidjson::GenericValue< Encoding, Allocator >::RemoveMember | ( | const Ch * | name | ) |

inline

Remove a member in object by its name.

Parameters

  name | Name of member to be removed.

Returns
  Whether the member existed.

Note
  This function may reorder the object members. Use EraseMember(ConstMemberIterator) if you need to preserve the relative order of the remaining members.
  Linear time complexity.

## RemoveMember() [2/2]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

MemberIterator rapidjson::GenericValue< Encoding, Allocator >::RemoveMember | ( | MemberIterator | m | ) |

inline

Remove a member in object by iterator.

Parameters

  m | member iterator (obtained by FindMember() or MemberBegin()).

Returns
  the new iterator after removal.

Note
  This function may reorder the object members. Use EraseMember(ConstMemberIterator) if you need to preserve the relative order of the remaining members.
  Constant time complexity.

## Reserve()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::Reserve | ( | SizeType | newCapacity,
|  | Allocator & | allocator
| ) |  |

inline

Request the array to have enough capacity to store elements.

Parameters

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

Returns
  The value itself for fluent API.

Note
  Linear time complexity.

## SetArray()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::SetArray | ( |  | ) |

inline

Set this value as an empty array.

Postcondition
  IsArray == true

## SetBool()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::SetBool | ( | bool | b | ) |

inline

Postcondition
  IsBool() == true

## SetObject()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::SetObject | ( |  | ) |

inline

Set this value as an empty object.

Postcondition
  IsObject() == true

## SetString() [1/4]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::SetString | ( | const Ch * | s,
|  | Allocator & | allocator
| ) |  |

inline

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

Parameters

  s | source string.
  allocator | Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator().

Returns
  The value itself for fluent API.

Postcondition
  IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length

## SetString() [2/4]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

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

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

Returns
  The value itself for fluent API.

Postcondition
  IsString() == true && GetString() == s && GetStringLength() == length

See also
  SetString(StringRefType)

## SetString() [3/4]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

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

  s | source string.
  length | The length of source string, excluding the trailing null terminator.
  allocator | Allocator for allocating copied buffer. Commonly use GenericDocument::GetAllocator().

Returns
  The value itself for fluent API.

Postcondition
  IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length

## SetString() [4/4]

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::SetString | ( | StringRefType | s | ) |

inline

Set this value as a string without copying source string.

Parameters

  s | source string reference

Returns
  The value itself for fluent API.

Postcondition
  IsString() == true && GetString() == s && GetStringLength() == s.length

## Swap()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

GenericValue & rapidjson::GenericValue< Encoding, Allocator >::Swap | ( | GenericValue< Encoding, Allocator > & | other | ) |

inline

Exchange the contents of this value with those of other.

Parameters

  other | Another value.

Note
  Constant complexity.

## Friends And Related Symbol Documentation

## operator!=

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

bool operator!= | ( | const T & | lhs,
|  | const GenericValue< Encoding, Allocator > & | rhs
| ) |  |

friend

Not-Equal-to operator with arbitrary types (symmetric version)

Returns
  !(rhs == lhs)

## operator==

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<typename T >

bool operator== | ( | const T & | lhs,
|  | const GenericValue< Encoding, Allocator > & | rhs
| ) |  |

friend

Equal-to operator with arbitrary types (symmetric version)

Returns
  (rhs == lhs)

## swap

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>

void swap | ( | GenericValue< Encoding, Allocator > & | a,
|  | GenericValue< Encoding, Allocator > & | b
| ) |  |

friend

free-standing swap function helper

Helper function to enable support for common swap implementation pattern based on `std::swap:`

void swap(MyClass& a, MyClass& b) {
using std::swap;
swap(a.value, b.value);
// ...
}
rapidjson::GenericMemberIterator
(Constant) member iterator for a JSON object value
Definition document.h:104
rapidjson::GenericValue::swap
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:850

See also
  Swap()

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

- include/rapidjson/document.h