rapidjson::GenericValue< Encoding, Allocator > 模板类 参考

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

`#include <document.h>`

## 类

struct | ArrayData
union | Data
struct | Flag
union | Number
struct | ObjectData
struct | ShortString
struct | String

## Public 类型

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 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 属性

const typedef GenericValue * | ConstValueIterator
| Constant value iterator for iterating in array.

## 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 (const std::basic_string< Ch > &s, Allocator &allocator)
| Constructor for copy-string from a string object (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. 更多...

## Assignment operators

enum

{
kBoolFlag = 0x0008, kNumberFlag = 0x0010, kIntFlag = 0x0020, kUintFlag = 0x0040,
kInt64Flag = 0x0080, kUint64Flag = 0x0100, kDoubleFlag = 0x0200, kStringFlag = 0x0400,
kCopyFlag = 0x0800, kInlineStrFlag = 0x1000, kNullFlag = kNullType, kTrueFlag = kTrueType | kBoolFlag,
kFalseFlag = kFalseType | kBoolFlag, kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag, kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag, kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag,
kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag, kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag, kNumberAnyFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag, kConstStringFlag = kStringType | kStringFlag,
kCopyStringFlag = kStringType | kStringFlag | kCopyFlag, kShortStringFlag = kStringType | kStringFlag | kCopyFlag | kInlineStrFlag, kObjectFlag = kObjectType, kArrayFlag = kArrayType,
kTypeMask = 0x07
}

Data | data_
template<typename , typename , typename >
class | GenericDocument
static const SizeType | kDefaultArrayCapacity = 16
static const SizeType | kDefaultObjectCapacity = 16
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 >
| RAPIDJSON_DISABLEIF_RETURN ((internal::IsPointer< T >),(GenericValue &)) operator
| Assignment with primitive types. 更多...
const RAPIDJSON_FORCEINLINE Ch * | GetStringPointer () const
const RAPIDJSON_FORCEINLINE Ch * | SetStringPointer (const Ch *str)
RAPIDJSON_FORCEINLINE GenericValue * | GetElementsPointer () const
RAPIDJSON_FORCEINLINE GenericValue * | SetElementsPointer (GenericValue *elements)
RAPIDJSON_FORCEINLINE Member * | GetMembersPointer () const
RAPIDJSON_FORCEINLINE Member * | SetMembersPointer (Member *members)
void | SetArrayRaw (GenericValue *values, SizeType count, Allocator &allocator)
void | SetObjectRaw (Member *members, SizeType count, Allocator &allocator)
| Initialize this value as object with initial data, without calling destructor.
void | SetStringRaw (StringRefType s) RAPIDJSON_NOEXCEPT
| Initialize this value as constant string, without calling destructor.
void | SetStringRaw (StringRefType s, Allocator &allocator)
| Initialize this value as copy string with initial data, without calling destructor.
void | RawAssign (GenericValue &rhs) RAPIDJSON_NOEXCEPT
| Assignment without calling destructor
template<typename SourceAllocator >
bool | StringEqual (const GenericValue< Encoding, SourceAllocator > &rhs) const

## 详细描述

### 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

模板参数

  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.

## 构造及析构函数说明

## GenericValue() [1/6]

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.

参数

  type | Type of the value.

注解
  Default content for number is zero.

## GenericValue() [2/6]

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

模板参数

  SourceAllocator | allocator of `rhs`

参数

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

参见
  CopyFrom()

## GenericValue() [3/6]

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

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

inline explicit

Constructor for boolean value.

参数

  b | Boolean value

注解
  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/6]

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

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)

注解
  Requires the definition of the preprocessor symbol RAPIDJSON_HAS_STDSTRING.

## GenericValue() [5/6]

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

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

inline

Constructor for Array.

参数

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

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

## GenericValue() [6/6]

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

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

inline

Constructor for Object.

参数

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

注解
  `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.

## 成员函数说明

## operator=() [1/2]

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

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

inline

Assignment with move semantics.

参数

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

## operator=() [2/2]

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

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

inline

Assignment of constant string reference (no copy)

参数

  str | Constant string reference to be assigned

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

参见
  GenericStringRef, operator=(T)

## RAPIDJSON_DISABLEIF_RETURN()

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

rapidjson::GenericValue< Encoding, Allocator >::RAPIDJSON_DISABLEIF_RETURN | ( | (internal::IsPointer< T >) | ,
|  | (GenericValue< Encoding, Allocator > &) |
| ) |  |

Assignment with primitive types.

模板参数

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

参数

  value | The value to be assigned.

注解
  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. Set boolean value

该类的文档由以下文件生成:

- include/rapidjson/document.h