All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 >:
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >

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< ChStringRefType
 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 GenericValueValueIterator
 Value iterator for iterating in array.
 
typedef const GenericValueConstValueIterator
 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

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
 
bool IsLosslessDouble () const
 
bool IsFloat () const
 
bool IsLosslessFloat () const
 
Null
GenericValueSetNull ()
 
Bool
bool GetBool () const
 Set boolean value.
 
GenericValueSetBool (bool b)
 
Object
GenericValueSetObject ()
 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 >
GenericValueoperator[] (T *name)
 Get a value from an object associated with the name. More...
 
template<typename T >
const GenericValueoperator[] (T *name) const
 
template<typename SourceAllocator >
GenericValueoperator[] (const GenericValue< Encoding, SourceAllocator > &name)
 Get a value from an object associated with the name. More...
 
template<typename SourceAllocator >
const GenericValueoperator[] (const GenericValue< Encoding, SourceAllocator > &name) const
 
GenericValueoperator[] (const std::basic_string< Ch > &name)
 Get a value from an object associated with name (string object).
 
const GenericValueoperator[] (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
 
GenericValueAddMember (GenericValue &name, GenericValue &value, Allocator &allocator)
 Add a member (name-value pair) to the object. More...
 
GenericValueAddMember (GenericValue &name, StringRefType value, Allocator &allocator)
 Add a constant string value as member (name-value pair) to the object. More...
 
GenericValueAddMember (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 >
GenericValueAddMember (GenericValue &name, T value, Allocator &allocator)
 Add any primitive value as member (name-value pair) to the object. More...
 
GenericValueAddMember (StringRefType name, GenericValue &value, Allocator &allocator)
 Add a member (name-value pair) to the object. More...
 
GenericValueAddMember (StringRefType name, StringRefType value, Allocator &allocator)
 Add a constant string value as member (name-value pair) to the object. More...
 
template<typename T >
GenericValueAddMember (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)
 
Object GetObject ()
 
ConstObject GetObject () const
 
Array
GenericValueSetArray ()
 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...
 
GenericValueoperator[] (SizeType index)
 Get an element from array by index. More...
 
const GenericValueoperator[] (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...
 
GenericValueReserve (SizeType newCapacity, Allocator &allocator)
 Request the array to have enough capacity to store elements. More...
 
GenericValuePushBack (GenericValue &value, Allocator &allocator)
 Append a GenericValue at the end of the array. More...
 
GenericValuePushBack (StringRefType value, Allocator &allocator)
 Append a constant string reference at the end of the array. More...
 
template<typename T >
GenericValuePushBack (T value, Allocator &allocator)
 Append a primitive value at the end of the array. More...
 
GenericValuePopBack ()
 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...
 
Array GetArray ()
 
ConstArray GetArray () const
 
template<typename T >
bool Is () const
 Templated version for checking whether this value is type T. More...
 
template<typename T >
Get () const
 
template<typename T >
Get ()
 
template<typename T >
ValueTypeSet (const T &data)
 
template<typename T >
ValueTypeSet (const T &data, AllocatorType &allocator)
 
Number
int GetInt () const
 
unsigned GetUint () const
 
int64_t GetInt64 () const
 
uint64_t GetUint64 () const
 
double GetDouble () const
 Get the value as double type. More...
 
float GetFloat () const
 Get the value as float type. More...
 
GenericValueSetInt (int i)
 
GenericValueSetUint (unsigned u)
 
GenericValueSetInt64 (int64_t i64)
 
GenericValueSetUint64 (uint64_t u64)
 
GenericValueSetDouble (double d)
 
GenericValueSetFloat (float f)
 
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 (StringRefType 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...
 
GenericValueSetString (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 (float f) RAPIDJSON_NOEXCEPT
 Constructor for float 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 (Array a) RAPIDJSON_NOEXCEPT
 Constructor for Array. More...
 
 GenericValue (Object o) RAPIDJSON_NOEXCEPT
 Constructor for Object. More...
 
 ~GenericValue ()
 Destructor. More...
 

Assignment operators

void swap (GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
 free-standing swap function helper More...
 
GenericValueoperator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment with move semantics. More...
 
GenericValueoperator= (StringRefType str) RAPIDJSON_NOEXCEPT
 Assignment of constant string reference (no copy) More...
 
template<typename T >
GenericValueoperator= (T value)
 Assignment with primitive types. More...
 
template<typename SourceAllocator >
GenericValueCopyFrom (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
 Deep-copy assignment from Value. More...
 
GenericValueSwap (GenericValue &other) RAPIDJSON_NOEXCEPT
 Exchange the contents of this value with those of other. More...
 
GenericValueMove () 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...
 

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)
inlineexplicit

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>
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
SourceAllocatorallocator of rhs
Parameters
rhsValue to copy from (read-only)
allocatorAllocator for allocating copied elements and buffers. Commonly use GenericDocument::GetAllocator().
See also
CopyFrom()
template<typename Encoding, typename Allocator>
rapidjson::GenericValue< Encoding, Allocator >::GenericValue ( bool  b)
inlineexplicit

Constructor for boolean value.

Parameters
bBoolean 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.
template<typename Encoding, typename Allocator>
rapidjson::GenericValue< Encoding, Allocator >::GenericValue ( const std::basic_string< Ch > &  s,
Allocator allocator 
)
inline

Constructor for copy-string from a string object (i.e. do make a copy of string)

Note
Requires the definition of the preprocessor symbol RAPIDJSON_HAS_STDSTRING.
template<typename Encoding, typename Allocator>
rapidjson::GenericValue< Encoding, Allocator >::GenericValue ( Array  a)
inline

Constructor for Array.

Parameters
aAn 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.
template<typename Encoding, typename Allocator>
rapidjson::GenericValue< Encoding, Allocator >::GenericValue ( Object  o)
inline

Constructor for Object.

Parameters
oAn 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.
template<typename Encoding, typename Allocator>
rapidjson::GenericValue< Encoding, Allocator >::~GenericValue ( )
inline

Destructor.

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

Member Function Documentation

template<typename Encoding, typename Allocator>
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
Handlertype of handler.
Parameters
handlerAn object implementing concept Handler.
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. 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.
template<typename Encoding, typename Allocator>
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
nameA string value as name of member.
valueconstant string reference as value of member.
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::AddMember ( GenericValue< Encoding, Allocator > &  name,
std::basic_string< Ch > &  value,
Allocator allocator 
)
inline

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

Parameters
nameA string value as name of member.
valueconstant string reference as value of member.
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
template<typename T >
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::AddMember ( GenericValue< Encoding, Allocator > &  name,
value,
Allocator allocator 
)
inline

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

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t
Parameters
nameA string value as name of member.
valueValue of primitive type T as value of member
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
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
nameA constant string reference as name of member.
valueValue of any type.
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
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
nameA constant string reference as name of member.
valueconstant string reference as value of member.
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
template<typename T >
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::AddMember ( StringRefType  name,
value,
Allocator allocator 
)
inline

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

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t
Parameters
nameA constant string reference as name of member.
valueValue of primitive type T as value of member
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
ValueIterator rapidjson::GenericValue< Encoding, Allocator >::Begin ( )
inline

Element iterator.

Precondition
IsArray() == true
template<typename Encoding, typename Allocator>
ConstValueIterator rapidjson::GenericValue< Encoding, Allocator >::Begin ( ) const
inline

Constant element iterator.

Precondition
IsArray() == true
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.

Note
Linear time complexity.
template<typename Encoding, typename Allocator>
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
SourceAllocatorAllocator type of rhs
Parameters
rhsValue to copy from (read-only)
allocatorAllocator to use for copying
template<typename Encoding, typename Allocator>
ValueIterator rapidjson::GenericValue< Encoding, Allocator >::End ( )
inline

Past-the-end element iterator

Precondition
IsArray() == true
template<typename Encoding, typename Allocator>
ConstValueIterator rapidjson::GenericValue< Encoding, Allocator >::End ( ) const
inline

Constant past-the-end element iterator.

Precondition
IsArray() == true
template<typename Encoding, typename Allocator>
ValueIterator rapidjson::GenericValue< Encoding, Allocator >::Erase ( ConstValueIterator  pos)
inline

Remove an element of array by iterator.

Parameters
positerator 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.
template<typename Encoding, typename Allocator>
ValueIterator rapidjson::GenericValue< Encoding, Allocator >::Erase ( ConstValueIterator  first,
ConstValueIterator  last 
)
inline

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

Parameters
firstiterator to the first element to remove
lastiterator following the last element to remove
Precondition
IsArray() == true && Begin() <= first <= last <= End()
Returns
Iterator following the last removed element.
Note
Linear time complexity.
template<typename Encoding, typename Allocator>
MemberIterator rapidjson::GenericValue< Encoding, Allocator >::EraseMember ( ConstMemberIterator  pos)
inline

Remove a member from an object by iterator.

Parameters
positerator 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.
template<typename Encoding, typename Allocator>
MemberIterator rapidjson::GenericValue< Encoding, Allocator >::EraseMember ( ConstMemberIterator  first,
ConstMemberIterator  last 
)
inline

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

Parameters
firstiterator to the first member to remove
lastiterator 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.
template<typename Encoding, typename Allocator>
bool rapidjson::GenericValue< Encoding, Allocator >::EraseMember ( const Ch name)
inline

Erase a member in object by its name.

Parameters
nameName of member to be removed.
Returns
Whether the member existed.
Note
Linear time complexity.
template<typename Encoding, typename Allocator>
MemberIterator rapidjson::GenericValue< Encoding, Allocator >::FindMember ( const Ch name)
inline

Find member by name.

Parameters
nameMember 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.
template<typename Encoding, typename Allocator>
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
nameMember 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.
template<typename Encoding, typename Allocator>
MemberIterator rapidjson::GenericValue< Encoding, Allocator >::FindMember ( const std::basic_string< Ch > &  name)
inline

Find member by string object name.

Parameters
nameMember name to be searched.
Precondition
IsObject() == true
Returns
Iterator to member, if it exists. Otherwise returns MemberEnd().
template<typename Encoding, typename Allocator>
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.
template<typename Encoding, typename Allocator>
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.
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.

Parameters
nameMember 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.
template<typename Encoding, typename Allocator>
bool rapidjson::GenericValue< Encoding, Allocator >::HasMember ( const std::basic_string< Ch > &  name) const
inline

Check whether a member exists in the object with string object.

Parameters
nameMember 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.
template<typename Encoding, typename Allocator>
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
nameMember 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.
template<typename Encoding, typename Allocator>
template<typename T >
bool rapidjson::GenericValue< Encoding, Allocator >::Is ( ) const
inline

Templated version for checking whether this value is type T.

Template Parameters
TEither bool, int, unsigned, int64_t, uint64_t, double, float, const char*, std::basic_string<Ch>
template<typename Encoding, typename Allocator>
ConstMemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberBegin ( ) const
inline

Const member iterator.

Precondition
IsObject() == true
template<typename Encoding, typename Allocator>
MemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberBegin ( )
inline

Member iterator.

Precondition
IsObject() == true
template<typename Encoding, typename Allocator>
ConstMemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberEnd ( ) const
inline

Const past-the-end member iterator.

Precondition
IsObject() == true
template<typename Encoding, typename Allocator>
MemberIterator rapidjson::GenericValue< Encoding, Allocator >::MemberEnd ( )
inline

Past-the-end member iterator

Precondition
IsObject() == true
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::Move ( )
inline

Prepare Value for move semantics.

Returns
*this
template<typename Encoding, typename Allocator>
template<typename SourceAllocator >
bool rapidjson::GenericValue< Encoding, Allocator >::operator!= ( const GenericValue< Encoding, SourceAllocator > &  rhs) const
inline

Not-equal-to operator.

Returns
!(*this == rhs)
template<typename Encoding, typename Allocator>
template<typename T >
bool rapidjson::GenericValue< Encoding, Allocator >::operator!= ( const T &  rhs) const
inline

Not-equal-to operator with arbitrary types.

Returns
!(*this == rhs)
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>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::operator= ( StringRefType  str)
inline

Assignment of constant string reference (no copy)

Parameters
strConstant 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)
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
Parameters
valueThe 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.
template<typename Encoding, typename Allocator>
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).
template<typename Encoding, typename Allocator>
bool rapidjson::GenericValue< Encoding, Allocator >::operator== ( const std::basic_string< Ch > &  rhs) const
inline

Equal-to operator with string object.

Note
Requires the definition of the preprocessor symbol RAPIDJSON_HAS_STDSTRING.
template<typename Encoding, typename Allocator>
template<typename T >
bool rapidjson::GenericValue< Encoding, Allocator >::operator== ( const T &  rhs) const
inline

Equal-to operator with primitive types.

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t, double, true, false
template<typename Encoding, typename Allocator>
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
TEither 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.
template<typename Encoding, typename Allocator>
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
SourceAllocatorAllocator 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.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::operator[] ( SizeType  index)
inline

Get an element from array by index.

Precondition
IsArray() == true
Parameters
indexZero-based index of element.
See also
operator[](T*)
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::PopBack ( )
inline

Remove the last element in the array.

Note
Constant time complexity.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::PushBack ( GenericValue< Encoding, Allocator > &  value,
Allocator allocator 
)
inline

Append a GenericValue at the end of the array.

Parameters
valueValue to be appended.
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::PushBack ( StringRefType  value,
Allocator allocator 
)
inline

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

Parameters
valueConstant string reference to be appended.
allocatorAllocator 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
template<typename Encoding, typename Allocator>
template<typename T >
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::PushBack ( value,
Allocator allocator 
)
inline

Append a primitive value at the end of the array.

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t
Parameters
valueValue of primitive type T to be appended.
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
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.
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
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.
template<typename Encoding, typename Allocator>
MemberIterator rapidjson::GenericValue< Encoding, Allocator >::RemoveMember ( MemberIterator  m)
inline

Remove a member in object by iterator.

Parameters
mmember 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.
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.
allocatorAllocator 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.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetArray ( )
inline

Set this value as an empty array.

Postcondition
IsArray == true
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetBool ( bool  b)
inline
Postcondition
IsBool() == true
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetObject ( )
inline

Set this value as an empty object.

Postcondition
IsObject() == true
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.
Postcondition
IsString() == true && GetString() == s && GetStringLength() == length
See also
SetString(StringRefType)
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetString ( StringRefType  s)
inline

Set this value as a string without copying source string.

Parameters
ssource string reference
Returns
The value itself for fluent API.
Postcondition
IsString() == true && GetString() == s && GetStringLength() == s.length
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 GenericDocument::GetAllocator().
Returns
The value itself for fluent API.
Postcondition
IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length
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 GenericDocument::GetAllocator().
Returns
The value itself for fluent API.
Postcondition
IsString() == true && GetString() != s && strcmp(GetString(),s) == 0 && GetStringLength() == length
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::SetString ( const std::basic_string< 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 GenericDocument::GetAllocator().
Returns
The value itself for fluent API.
Postcondition
IsString() == true && GetString() != s.data() && strcmp(GetString(),s.data() == 0 && GetStringLength() == s.size()
Note
Requires the definition of the preprocessor symbol RAPIDJSON_HAS_STDSTRING.
template<typename Encoding, typename Allocator>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::Swap ( GenericValue< Encoding, Allocator > &  other)
inline

Exchange the contents of this value with those of other.

Parameters
otherAnother value.
Note
Constant complexity.

Friends And Related Function Documentation

template<typename Encoding, typename Allocator>
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)
template<typename Encoding, typename Allocator>
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)
template<typename Encoding, typename Allocator>
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);
// ...
}
See also
Swap()

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