TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GenericValue< Encoding, Allocator > Class Template Reference

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

#include <document.h>

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.

Member Typedef Documentation

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

Allocator type from template parameter.

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

Character type derived from Encoding.

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

Constant member iterator for iterating in object.

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

Constant value iterator for iterating in array.

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

Encoding type from template parameter.

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

Name-value pair in an object.

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

Member iterator for iterating in object.

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

Reference to a constant string.

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

Value iterator for iterating in array.

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

Value type of itself.

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 
1527  {
1528  kBoolFlag = 0x100,
1529  kNumberFlag = 0x200,
1530  kIntFlag = 0x400,
1531  kUintFlag = 0x800,
1532  kInt64Flag = 0x1000,
1533  kUint64Flag = 0x2000,
1534  kDoubleFlag = 0x4000,
1535  kStringFlag = 0x100000,
1536  kCopyFlag = 0x200000,
1537  kInlineStrFlag = 0x400000,
1538 
1539  // Initial flags of different types.
1540  kNullFlag = kNullType,
1554 
1555  kTypeMask = 0xFF // bitwise-and with mask of 0xFF can be optimized by compiler
1556  };
Definition: document.h:1536
Definition: document.h:1547
Definition: document.h:1532
Definition: document.h:1555
Definition: document.h:1548
object
Definition: rapidjson.h:646
array
Definition: rapidjson.h:647
Definition: document.h:1552
Definition: document.h:1549
false
Definition: rapidjson.h:644
Definition: document.h:1533
Definition: document.h:1541
Definition: document.h:1530
Definition: document.h:1551
Definition: document.h:1553
Definition: document.h:1531
Definition: document.h:1537
Definition: document.h:1534
Definition: document.h:1543
string
Definition: rapidjson.h:648
Definition: document.h:1550
number
Definition: rapidjson.h:649
Definition: document.h:1546
Definition: document.h:1545
Definition: document.h:1540
Definition: document.h:1529
Definition: document.h:1528
Definition: document.h:1542
Definition: document.h:1535
Definition: document.h:1544
true
Definition: rapidjson.h:645
null
Definition: rapidjson.h:643

Constructor & Destructor Documentation

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

Default constructor creates a null value.

436 : data_(), flags_(kNullFlag) {}
Data data_
Definition: document.h:1701
Definition: document.h:1540
unsigned flags_
Definition: document.h:1702
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.
456  : data_(), flags_() {
457  static const unsigned defaultFlags[7] = {
460  };
461  RAPIDJSON_ASSERT(type <= kNumberType);
462  flags_ = defaultFlags[type];
463 
464  // Use ShortString to store empty string.
465  if (type == kStringType)
466  data_.ss.SetLength(0);
467  }
void SetLength(SizeType len)
Definition: document.h:1580
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
Definition: document.h:1548
Definition: document.h:1552
Data data_
Definition: document.h:1701
Definition: document.h:1541
Definition: document.h:1551
Definition: document.h:1553
ShortString ss
Definition: document.h:1624
string
Definition: rapidjson.h:648
number
Definition: rapidjson.h:649
Definition: document.h:1540
Definition: document.h:1542
unsigned flags_
Definition: document.h:1702
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()
1985 {
1986  switch (rhs.GetType()) {
1987  case kObjectType:
1988  case kArrayType: { // perform deep copy via SAX Handler
1990  rhs.Accept(d);
1991  RawAssign(*d.stack_.template Pop<GenericValue>(1));
1992  }
1993  break;
1994  case kStringType:
1995  if (rhs.flags_ == kConstStringFlag) {
1996  flags_ = rhs.flags_;
1997  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
1998  } else {
1999  SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
2000  }
2001  break;
2002  default: // kNumberType, kTrueType, kFalseType, kNullType
2003  flags_ = rhs.flags_;
2004  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
2005  }
2006 }
object
Definition: rapidjson.h:646
void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment without calling destructor.
Definition: document.h:1679
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:1655
array
Definition: rapidjson.h:647
Data data_
Definition: document.h:1701
Definition: document.h:1549
A document for parsing JSON text as DOM.
Definition: document.h:1720
string
Definition: rapidjson.h:648
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:345
unsigned flags_
Definition: document.h:1702
Data
Definition: molten_core.h:69

+ 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.
491  : data_(), flags_(b ? kTrueFlag : kFalseFlag) {
492  // safe-guard against failing SFINAE
494  }
Data data_
Definition: document.h:1701
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:375
Definition: document.h:1541
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1706
Definition: document.h:1542
unsigned flags_
Definition: document.h:1702
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( int  i)
inlineexplicit

Constructor for int value.

497  : data_(), flags_(kNumberIntFlag) {
498  data_.n.i64 = i;
499  if (i >= 0)
501  }
Data data_
Definition: document.h:1701
Definition: document.h:1533
Definition: document.h:1531
Definition: document.h:1543
Number n
Definition: document.h:1625
int64_t i64
Definition: document.h:1605
unsigned flags_
Definition: document.h:1702
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( unsigned  u)
inlineexplicit

Constructor for unsigned value.

505  data_.n.u64 = u;
506  if (!(u & 0x80000000))
508  }
Definition: document.h:1532
Data data_
Definition: document.h:1701
Definition: document.h:1530
Number n
Definition: document.h:1625
uint64_t u64
Definition: document.h:1606
Definition: document.h:1544
unsigned flags_
Definition: document.h:1702
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( int64_t  i64)
inlineexplicit

Constructor for int64_t value.

512  data_.n.i64 = i64;
513  if (i64 >= 0) {
515  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
516  flags_ |= kUintFlag;
517  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
518  flags_ |= kIntFlag;
519  }
520  else if (i64 >= static_cast<int64_t>(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
521  flags_ |= kIntFlag;
522  }
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:261
Data data_
Definition: document.h:1701
Definition: document.h:1530
Definition: document.h:1531
Number n
Definition: document.h:1625
Definition: document.h:1546
Definition: document.h:1545
int64_t i64
Definition: document.h:1605
unsigned flags_
Definition: document.h:1702
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( uint64_t  u64)
inlineexplicit

Constructor for uint64_t value.

526  data_.n.u64 = u64;
527  if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000)))
528  flags_ |= kInt64Flag;
529  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
530  flags_ |= kUintFlag;
531  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
532  flags_ |= kIntFlag;
533  }
Definition: document.h:1532
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:261
Data data_
Definition: document.h:1701
Definition: document.h:1530
Definition: document.h:1531
Number n
Definition: document.h:1625
Definition: document.h:1546
uint64_t u64
Definition: document.h:1606
unsigned flags_
Definition: document.h:1702
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( double  d)
inlineexplicit

Constructor for double value.

536 : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; }
Definition: document.h:1547
Data data_
Definition: document.h:1701
Number n
Definition: document.h:1625
double d
Definition: document.h:1607
unsigned flags_
Definition: document.h:1702
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)

539 : data_(), flags_() { SetStringRaw(StringRef(s, length)); }
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:1655
Data data_
Definition: document.h:1701
float length(float v)
Definition: vectorMath.h:208
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:345
unsigned flags_
Definition: document.h:1702
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)

542 : data_(), flags_() { SetStringRaw(s); }
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:1655
Data data_
Definition: document.h:1701
unsigned flags_
Definition: document.h:1702
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)

545 : data_(), flags_() { SetStringRaw(StringRef(s, length), allocator); }
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:1655
Data data_
Definition: document.h:1701
float length(float v)
Definition: vectorMath.h:208
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:345
unsigned flags_
Definition: document.h:1702
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)

548 : data_(), flags_() { SetStringRaw(StringRef(s), allocator); }
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:1655
Data data_
Definition: document.h:1701
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:345
unsigned flags_
Definition: document.h:1702
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::~GenericValue ( )
inline

Destructor.

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

560  {
561  if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
562  switch(flags_) {
563  case kArrayFlag:
564  for (GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
565  v->~GenericValue();
566  Allocator::Free(data_.a.elements);
567  break;
568 
569  case kObjectFlag:
570  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
571  m->~Member();
572  Allocator::Free(data_.o.members);
573  break;
574 
575  case kCopyStringFlag:
576  Allocator::Free(const_cast<Ch*>(data_.s.str));
577  break;
578 
579  default:
580  break; // Do nothing for other types.
581  }
582  }
583  }
Member * members
Definition: document.h:1611
const Ch * str
Definition: document.h:1562
Definition: document.h:1552
Data data_
Definition: document.h:1701
SizeType size
Definition: document.h:1618
Definition: document.h:1553
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:70
Array a
Definition: document.h:1627
Definition: document.h:1550
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:426
String s
Definition: document.h:1623
unsigned flags_
Definition: document.h:1702
GenericValue * elements
Definition: document.h:1617
Object o
Definition: document.h:1626

+ 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.
593  {
594  RAPIDJSON_ASSERT(this != &rhs);
595  this->~GenericValue();
596  RawAssign(rhs);
597  return *this;
598  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment without calling destructor.
Definition: document.h:1679
~GenericValue()
Destructor.
Definition: document.h:560
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)
612  {
613  GenericValue s(str);
614  return *this = s;
615  }
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:70
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.

1679  {
1680  data_ = rhs.data_;
1681  flags_ = rhs.flags_;
1682  rhs.flags_ = kNullFlag;
1683  }
Data data_
Definition: document.h:1701
Definition: document.h:1540
unsigned flags_
Definition: document.h:1702

+ 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
1631  {
1632  flags_ = kArrayFlag;
1633  if (count) {
1634  data_.a.elements = (GenericValue*)allocator.Malloc(count * sizeof(GenericValue));
1635  std::memcpy(data_.a.elements, values, count * sizeof(GenericValue));
1636  }
1637  else
1638  data_.a.elements = NULL;
1639  data_.a.size = data_.a.capacity = count;
1640  }
Data data_
Definition: document.h:1701
arena_t NULL
Definition: jemalloc_internal.h:624
SizeType size
Definition: document.h:1618
Definition: document.h:1553
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:70
Array a
Definition: document.h:1627
SizeType capacity
Definition: document.h:1619
unsigned flags_
Definition: document.h:1702
GenericValue * elements
Definition: document.h:1617

+ 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.

1643  {
1644  flags_ = kObjectFlag;
1645  if (count) {
1646  data_.o.members = (Member*)allocator.Malloc(count * sizeof(Member));
1647  std::memcpy(data_.o.members, members, count * sizeof(Member));
1648  }
1649  else
1650  data_.o.members = NULL;
1651  data_.o.size = data_.o.capacity = count;
1652  }
Member * members
Definition: document.h:1611
Definition: document.h:1552
Data data_
Definition: document.h:1701
SizeType capacity
Definition: document.h:1613
arena_t NULL
Definition: jemalloc_internal.h:624
SizeType size
Definition: document.h:1612
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:421
unsigned flags_
Definition: document.h:1702
Object o
Definition: document.h:1626

+ 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.

1655  {
1657  data_.s.str = s;
1658  data_.s.length = s.length;
1659  }
const Ch * str
Definition: document.h:1562
Data data_
Definition: document.h:1701
Definition: document.h:1549
String s
Definition: document.h:1623
unsigned flags_
Definition: document.h:1702
SizeType length
Definition: document.h:1563

+ 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.

1662  {
1663  Ch* str = NULL;
1664  if(ShortString::Usable(s.length)) {
1666  data_.ss.SetLength(s.length);
1667  str = data_.ss.str;
1668  } else {
1670  data_.s.length = s.length;
1671  str = (Ch *)allocator.Malloc((s.length + 1) * sizeof(Ch));
1672  data_.s.str = str;
1673  }
1674  std::memcpy(str, s, s.length * sizeof(Ch));
1675  str[s.length] = '\0';
1676  }
void SetLength(SizeType len)
Definition: document.h:1580
const Ch * str
Definition: document.h:1562
Data data_
Definition: document.h:1701
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: document.h:1551
ShortString ss
Definition: document.h:1624
Ch str[MaxChars]
Definition: document.h:1577
Definition: document.h:1550
static bool Usable(SizeType len)
Definition: document.h:1579
String s
Definition: document.h:1623
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:424
unsigned flags_
Definition: document.h:1702
SizeType length
Definition: document.h:1563
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >
bool GenericValue< Encoding, Allocator >::StringEqual ( const GenericValue< Encoding, SourceAllocator > &  rhs) const
inline
1686  {
1687  RAPIDJSON_ASSERT(IsString());
1688  RAPIDJSON_ASSERT(rhs.IsString());
1689 
1690  const SizeType len1 = GetStringLength();
1691  const SizeType len2 = rhs.GetStringLength();
1692  if(len1 != len2) { return false; }
1693 
1694  const Ch* const str1 = GetString();
1695  const Ch* const str2 = rhs.GetString();
1696  if(str1 == str2) { return true; } // fast path for constant string
1697 
1698  return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
1699  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:322
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:424

Friends And Related Function Documentation

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

Member Data Documentation

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
Data GenericValue< Encoding, Allocator >::data_
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
unsigned GenericValue< Encoding, Allocator >::flags_
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
const SizeType GenericValue< Encoding, Allocator >::kDefaultArrayCapacity = 16
static
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
const SizeType GenericValue< Encoding, Allocator >::kDefaultObjectCapacity = 16
static

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