NGL  6.5
The NCCA Graphics Library
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 GenericValue< Encoding, Allocator >:
+ Collaboration diagram for GenericValue< Encoding, Allocator >:

Classes

struct  Array
 
union  Data
 
union  Number
 
struct  Object
 
struct  ShortString
 
struct  String
 

Public Types

enum  {
  kBoolFlag = 0x100, kNumberFlag = 0x200, kIntFlag = 0x400, kUintFlag = 0x800,
  kInt64Flag = 0x1000, kUint64Flag = 0x2000, kDoubleFlag = 0x4000, kStringFlag = 0x100000,
  kCopyFlag = 0x200000, kInlineStrFlag = 0x400000, 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 = 0xFF
}
 
typedef GenericMember< Encoding, Allocator > Member
 Name-value pair in an object. More...
 
typedef Encoding EncodingType
 Encoding type from template parameter. More...
 
typedef Allocator AllocatorType
 Allocator type from template parameter. More...
 
typedef Encoding::Ch Ch
 Character type derived from Encoding. More...
 
typedef GenericStringRef< ChStringRefType
 Reference to a constant string. More...
 
typedef GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
 Member iterator for iterating in object. More...
 
typedef GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
 Constant member iterator for iterating in object. More...
 
typedef GenericValueValueIterator
 Value iterator for iterating in array. More...
 
typedef const GenericValueConstValueIterator
 Constant value iterator for iterating in array. More...
 
typedef GenericValue< Encoding, Allocator > ValueType
 Value type of itself. More...
 

Public Member Functions

template<typename T >
 RAPIDJSON_DISABLEIF_RETURN ((internal::IsPointer< T >),(GenericValue &)) operator
 Assignment with primitive types. More...
 
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. More...
 
void SetStringRaw (StringRefType s) RAPIDJSON_NOEXCEPT
 Initialize this value as constant string, without calling destructor. More...
 
void SetStringRaw (StringRefType s, Allocator &allocator)
 Initialize this value as copy string with initial data, without calling destructor. More...
 
void RawAssign (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment without calling destructor. More...
 
template<typename SourceAllocator >
bool StringEqual (const GenericValue< Encoding, SourceAllocator > &rhs) const
 
Assignment operators
GenericValueoperator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment with move semantics. More...
 
GenericValueoperator= (StringRefType str) RAPIDJSON_NOEXCEPT
 Assignment of constant string reference (no copy) More...
 

Public Attributes

Data data_
 
unsigned flags_
 

Static Public Attributes

static const SizeType kDefaultArrayCapacity = 16
 
static const SizeType kDefaultObjectCapacity = 16
 

Friends

template<typename , typename , typename >
class GenericDocument
 

Constructors and destructor.

 GenericValue () RAPIDJSON_NOEXCEPT
 Default constructor creates a null value. More...
 
 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...
 
template<typename T >
 GenericValue (T b, RAPIDJSON_ENABLEIF((internal::IsSame< T, bool >))) RAPIDJSON_NOEXCEPT
 Constructor for boolean value. More...
 
 GenericValue (int i) RAPIDJSON_NOEXCEPT
 Constructor for int value. More...
 
 GenericValue (unsigned u) RAPIDJSON_NOEXCEPT
 Constructor for unsigned value. More...
 
 GenericValue (int64_t i64) RAPIDJSON_NOEXCEPT
 Constructor for int64_t value. More...
 
 GenericValue (uint64_t u64) RAPIDJSON_NOEXCEPT
 Constructor for uint64_t value. More...
 
 GenericValue (double d) RAPIDJSON_NOEXCEPT
 Constructor for double value. More...
 
 GenericValue (const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
 Constructor for constant string (i.e. do not make a copy of string) More...
 
 GenericValue (StringRefType s) RAPIDJSON_NOEXCEPT
 Constructor for constant string (i.e. do not make a copy of string) More...
 
 GenericValue (const Ch *s, SizeType length, Allocator &allocator)
 Constructor for copy-string (i.e. do make a copy of string) More...
 
 GenericValue (const Ch *s, Allocator &allocator)
 Constructor for copy-string (i.e. do make a copy of string) More...
 
 ~GenericValue ()
 Destructor. More...
 
 GenericValue (const GenericValue &rhs)
 Copy constructor is not permitted. More...
 

Detailed Description

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

Definition at line 70 of file document.h.

Member Typedef Documentation

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef Allocator GenericValue< Encoding, Allocator >::AllocatorType

Allocator type from template parameter.

Definition at line 426 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef Encoding::Ch GenericValue< Encoding, Allocator >::Ch

Character type derived from Encoding.

Definition at line 427 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef GenericMemberIterator<true,Encoding,Allocator>::Iterator GenericValue< Encoding, Allocator >::ConstMemberIterator

Constant member iterator for iterating in object.

Definition at line 430 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef const GenericValue* GenericValue< Encoding, Allocator >::ConstValueIterator

Constant value iterator for iterating in array.

Definition at line 432 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef Encoding GenericValue< Encoding, Allocator >::EncodingType

Encoding type from template parameter.

Definition at line 425 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef GenericMember<Encoding, Allocator> GenericValue< Encoding, Allocator >::Member

Name-value pair in an object.

Definition at line 424 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef GenericMemberIterator<false,Encoding,Allocator>::Iterator GenericValue< Encoding, Allocator >::MemberIterator

Member iterator for iterating in object.

Definition at line 429 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef GenericStringRef<Ch> GenericValue< Encoding, Allocator >::StringRefType

Reference to a constant string.

Definition at line 428 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef GenericValue* GenericValue< Encoding, Allocator >::ValueIterator

Value iterator for iterating in array.

Definition at line 431 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
typedef GenericValue<Encoding, Allocator> GenericValue< Encoding, Allocator >::ValueType

Value type of itself.

Definition at line 433 of file document.h.

Member Enumeration Documentation

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
anonymous enum
Enumerator
kBoolFlag 
kNumberFlag 
kIntFlag 
kUintFlag 
kInt64Flag 
kUint64Flag 
kDoubleFlag 
kStringFlag 
kCopyFlag 
kInlineStrFlag 
kNullFlag 
kTrueFlag 
kFalseFlag 
kNumberIntFlag 
kNumberUintFlag 
kNumberInt64Flag 
kNumberUint64Flag 
kNumberDoubleFlag 
kNumberAnyFlag 
kConstStringFlag 
kCopyStringFlag 
kShortStringFlag 
kObjectFlag 
kArrayFlag 
kTypeMask 

Definition at line 1579 of file document.h.

Constructor & Destructor Documentation

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( )
inline

Default constructor creates a null value.

Definition at line 439 of file document.h.

References GenericValue< Encoding, Allocator >::flags_.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( const GenericValue< Encoding, Allocator > &  rhs)
private

Copy constructor is not permitted.

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

Definition at line 469 of file document.h.

References kNumberType, kStringType, and RAPIDJSON_ASSERT.

template<typename Encoding , typename Allocator >
template<typename SourceAllocator >
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()

Definition at line 2083 of file document.h.

References GenericValue< Encoding, Allocator >::data_, GenericValue< Encoding, Allocator >::flags_, kArrayType, GenericValue< Encoding, Allocator >::kConstStringFlag, kObjectType, kStringType, RAPIDJSON_NAMESPACE_END, GenericValue< Encoding, Allocator >::RawAssign(), GenericValue< Encoding, Allocator >::SetStringRaw(), GenericDocument< Encoding, Allocator, StackAllocator >::stack_, and StringRef().

+ Here is the call graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename T >
GenericValue< Encoding, Allocator >::GenericValue ( b,
RAPIDJSON_ENABLEIF((internal::IsSame< T, bool >))   
)
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.

Definition at line 500 of file document.h.

References RAPIDJSON_STATIC_ASSERT.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( int  i)
inlineexplicit

Constructor for int value.

Definition at line 510 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( unsigned  u)
inlineexplicit

Constructor for unsigned value.

Definition at line 517 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( int64_t  i64)
inlineexplicit

Constructor for int64_t value.

Definition at line 524 of file document.h.

References RAPIDJSON_UINT64_C2.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( uint64_t  u64)
inlineexplicit

Constructor for uint64_t value.

Definition at line 538 of file document.h.

References RAPIDJSON_UINT64_C2.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( double  d)
inlineexplicit

Constructor for double value.

Definition at line 549 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( const Ch s,
SizeType  length 
)
inline

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

Definition at line 552 of file document.h.

References StringRef().

+ Here is the call graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( StringRefType  s)
inlineexplicit

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

Definition at line 555 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( const Ch s,
SizeType  length,
Allocator &  allocator 
)
inline

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

Definition at line 558 of file document.h.

References StringRef().

+ Here is the call graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( const Ch s,
Allocator &  allocator 
)
inline

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

Definition at line 561 of file document.h.

References StringRef().

+ Here is the call graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::~GenericValue ( )
inline

Destructor.

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

Definition at line 573 of file document.h.

+ Here is the caller graph for this function:

Member Function Documentation

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

Definition at line 606 of file document.h.

References RAPIDJSON_ASSERT.

+ Here is the caller graph for this function:

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

Definition at line 625 of file document.h.

References GenericValue< Encoding, Allocator >::Object::capacity, GenericValue< Encoding, Allocator >::data_, kArrayType, kFalseType, kNullType, kNumberType, kObjectType, kStringType, kTrueType, GenericMember< Encoding, Allocator >::name, ngl::operator==(), RAPIDJSON_ASSERT, RAPIDJSON_DISABLEIF_RETURN(), GenericValue< Encoding, Allocator >::RawAssign(), SizeType, GenericValue< Encoding, Allocator >::StringEqual(), StringRef(), internal::StrLen(), internal::Swap(), and GenericValue< Encoding, Allocator >::~GenericValue().

+ Here is the call graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename T >
GenericValue< Encoding, Allocator >::RAPIDJSON_DISABLEIF_RETURN ( (internal::IsPointer< T >)  ,
(GenericValue< Encoding, Allocator > &)   
)

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.Set boolean value
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
void GenericValue< Encoding, Allocator >::RawAssign ( GenericValue< Encoding, Allocator > &  rhs)
inline

Assignment without calling destructor.

Definition at line 1731 of file document.h.

References GenericValue< Encoding, Allocator >::data_, and GenericValue< Encoding, Allocator >::flags_.

+ Here is the caller graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
void GenericValue< Encoding, Allocator >::SetArrayRaw ( GenericValue< Encoding, Allocator > *  values,
SizeType  count,
Allocator &  allocator 
)
inline

Definition at line 1683 of file document.h.

+ Here is the caller graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
void GenericValue< Encoding, Allocator >::SetObjectRaw ( Member members,
SizeType  count,
Allocator &  allocator 
)
inline

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

Definition at line 1695 of file document.h.

+ Here is the caller graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
void GenericValue< Encoding, Allocator >::SetStringRaw ( StringRefType  s)
inline

Initialize this value as constant string, without calling destructor.

Definition at line 1707 of file document.h.

+ Here is the caller graph for this function:

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
void GenericValue< Encoding, Allocator >::SetStringRaw ( StringRefType  s,
Allocator &  allocator 
)
inline

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

Definition at line 1714 of file document.h.

References GenericStringRef< CharType >::length.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >
bool GenericValue< Encoding, Allocator >::StringEqual ( const GenericValue< Encoding, SourceAllocator > &  rhs) const
inline

Definition at line 1738 of file document.h.

References RAPIDJSON_ASSERT, and SizeType.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename , typename , typename >
friend class GenericDocument
friend

Definition at line 1577 of file document.h.

Member Data Documentation

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
Data GenericValue< Encoding, Allocator >::data_

Definition at line 1753 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
unsigned GenericValue< Encoding, Allocator >::flags_

Definition at line 1754 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
const SizeType GenericValue< Encoding, Allocator >::kDefaultArrayCapacity = 16
static

Definition at line 1610 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
const SizeType GenericValue< Encoding, Allocator >::kDefaultObjectCapacity = 16
static

Definition at line 1611 of file document.h.


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