Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
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 >:
GenericDocument< Encoding, Allocator, StackAllocator >

Classes

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

Public Types

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
}
 
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...
 
typedef GenericArray< false, ValueTypeArray
 
typedef GenericArray< true, ValueTypeConstArray
 
typedef GenericObject< false, ValueTypeObject
 
typedef GenericObject< true, ValueTypeConstObject
 

Public Member Functions

template<typename T >
 RAPIDJSON_DISABLEIF_RETURN ((internal::IsPointer< T >),(GenericValue &)) operator
 Assignment with primitive types. More...
 
RAPIDJSON_FORCEINLINE const ChGetStringPointer () const
 
RAPIDJSON_FORCEINLINE const ChSetStringPointer (const Ch *str)
 
RAPIDJSON_FORCEINLINE GenericValueGetElementsPointer () const
 
RAPIDJSON_FORCEINLINE GenericValueSetElementsPointer (GenericValue *elements)
 
RAPIDJSON_FORCEINLINE MemberGetMembersPointer () const
 
RAPIDJSON_FORCEINLINE MemberSetMembersPointer (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. 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_
 

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, bool copyConstStrings=false)
 Explicit copy constructor (with allocator) More...
 
template<typename T >
 GenericValue (T b, RAPIDJSON_ENABLEIF((internal::IsSame< bool, T >))) 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 (float f) RAPIDJSON_NOEXCEPT
 Constructor for float 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 (Array a) RAPIDJSON_NOEXCEPT
 Constructor for Array. More...
 
 GenericValue (Object o) RAPIDJSON_NOEXCEPT
 Constructor for Object. 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 57 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 580 of file document.h.

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

Definition at line 588 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 581 of file document.h.

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

Definition at line 589 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 584 of file document.h.

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

Definition at line 591 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 586 of file document.h.

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

Encoding type from template parameter.

Definition at line 579 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 578 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 583 of file document.h.

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

Definition at line 590 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 582 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 585 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 587 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 1907 of file document.h.

1907  {
1908  kBoolFlag = 0x0008,
1909  kNumberFlag = 0x0010,
1910  kIntFlag = 0x0020,
1911  kUintFlag = 0x0040,
1912  kInt64Flag = 0x0080,
1913  kUint64Flag = 0x0100,
1914  kDoubleFlag = 0x0200,
1915  kStringFlag = 0x0400,
1916  kCopyFlag = 0x0800,
1917  kInlineStrFlag = 0x1000,
1918 
1919  // Initial flags of different types.
1920  kNullFlag = kNullType,
1934 
1935  kTypeMask = 0x07
1936  };
object
Definition: rapidjson.h:622
array
Definition: rapidjson.h:623
false
Definition: rapidjson.h:620
string
Definition: rapidjson.h:624
number
Definition: rapidjson.h:625
true
Definition: rapidjson.h:621
null
Definition: rapidjson.h:619

Constructor & Destructor Documentation

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

Default constructor creates a null value.

Definition at line 597 of file document.h.

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 627 of file document.h.

627  : data_() {
628  static const uint16_t defaultFlags[7] = {
631  };
633  data_.f.flags = defaultFlags[type];
634 
635  // Use ShortString to store empty string.
636  if (type == kStringType)
637  data_.ss.SetLength(0);
638  }
void SetLength(SizeType len)
Definition: document.h:1971
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
unsigned short uint16_t
Definition: stdint.h:125
ShortString ss
Definition: document.h:2015
string
Definition: rapidjson.h:624
number
Definition: rapidjson.h:625
static QCString type
Definition: declinfo.cpp:672
null
Definition: rapidjson.h:619
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >
GenericValue< Encoding, Allocator >::GenericValue ( const GenericValue< Encoding, SourceAllocator > &  rhs,
Allocator &  allocator,
bool  copyConstStrings = false 
)
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().
copyConstStringsForce copying of constant strings (e.g. referencing an in-situ buffer)
See also
CopyFrom()

Definition at line 649 of file document.h.

649  {
650  switch (rhs.GetType()) {
651  case kObjectType: {
652  SizeType count = rhs.data_.o.size;
653  Member* lm = reinterpret_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
655  for (SizeType i = 0; i < count; i++) {
656  new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings);
657  new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings);
658  }
660  data_.o.size = data_.o.capacity = count;
661  SetMembersPointer(lm);
662  }
663  break;
664  case kArrayType: {
665  SizeType count = rhs.data_.a.size;
666  GenericValue* le = reinterpret_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
668  for (SizeType i = 0; i < count; i++)
669  new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
671  data_.a.size = data_.a.capacity = count;
672  SetElementsPointer(le);
673  }
674  break;
675  case kStringType:
676  if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
677  data_.f.flags = rhs.data_.f.flags;
678  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
679  }
680  else
681  SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
682  break;
683  default:
684  data_.f.flags = rhs.data_.f.flags;
685  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
686  break;
687  }
688  }
static QCString name
Definition: declinfo.cpp:673
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
object
Definition: rapidjson.h:622
array
Definition: rapidjson.h:623
RAPIDJSON_FORCEINLINE GenericValue * SetElementsPointer(GenericValue *elements)
Definition: document.h:2025
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:578
ObjectData o
Definition: document.h:2017
string
Definition: rapidjson.h:624
RAPIDJSON_FORCEINLINE GenericValue * GetElementsPointer() const
Definition: document.h:2024
Name-value pair in a JSON object value.
Definition: document.h:69
RAPIDJSON_FORCEINLINE Member * SetMembersPointer(Member *members)
Definition: document.h:2027
RAPIDJSON_FORCEINLINE Member * GetMembersPointer() const
Definition: document.h:2026
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:361
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2056
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:597
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename T >
GenericValue< Encoding, Allocator >::GenericValue ( b,
RAPIDJSON_ENABLEIF((internal::IsSame< bool, T >))   
)
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 698 of file document.h.

702  : data_() {
703  // safe-guard against failing SFINAE
706  }
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:445
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2106
static bool * b
Definition: config.cpp:1043
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( int  i)
inlineexplicit

Constructor for int value.

Definition at line 709 of file document.h.

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

Constructor for unsigned value.

Definition at line 715 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 721 of file document.h.

721  : data_() {
722  data_.n.i64 = i64;
724  if (i64 >= 0) {
726  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
727  data_.f.flags |= kUintFlag;
728  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
729  data_.f.flags |= kIntFlag;
730  }
731  else if (i64 >= static_cast<int64_t>(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
732  data_.f.flags |= kIntFlag;
733  }
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:289
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( uint64_t  u64)
inlineexplicit

Constructor for uint64_t value.

Definition at line 736 of file document.h.

736  : data_() {
737  data_.n.u64 = u64;
739  if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000)))
740  data_.f.flags |= kInt64Flag;
741  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
742  data_.f.flags |= kUintFlag;
743  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
744  data_.f.flags |= kIntFlag;
745  }
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:289
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( double  d)
inlineexplicit

Constructor for double value.

Definition at line 748 of file document.h.

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
GenericValue< Encoding, Allocator >::GenericValue ( float  f)
inlineexplicit

Constructor for float value.

Definition at line 751 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 754 of file document.h.

754 : data_() { SetStringRaw(StringRef(s, length)); }
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:361
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2056
static QCString * s
Definition: config.cpp:1042
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 757 of file document.h.

757 : data_() { SetStringRaw(s); }
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2056
static QCString * s
Definition: config.cpp:1042
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 760 of file document.h.

760 : data_() { SetStringRaw(StringRef(s, length), allocator); }
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:361
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2056
static QCString * s
Definition: config.cpp:1042
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 763 of file document.h.

763 : data_() { SetStringRaw(StringRef(s), allocator); }
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:361
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2056
static QCString * s
Definition: config.cpp:1042
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
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.

Definition at line 778 of file document.h.

778  : data_(a.value_.data_) {
779  a.value_.data_ = Data();
780  a.value_.data_.f.flags = kArrayFlag;
781  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
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.

Definition at line 789 of file document.h.

789  : data_(o.value_.data_) {
790  o.value_.data_ = Data();
791  o.value_.data_.f.flags = kObjectFlag;
792  }
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 797 of file document.h.

797  {
798  if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
799  switch(data_.f.flags) {
800  case kArrayFlag:
801  {
803  for (GenericValue* v = e; v != e + data_.a.size; ++v)
804  v->~GenericValue();
805  Allocator::Free(e);
806  }
807  break;
808 
809  case kObjectFlag:
810  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
811  m->~Member();
812  Allocator::Free(GetMembersPointer());
813  break;
814 
815  case kCopyStringFlag:
816  Allocator::Free(const_cast<Ch*>(GetStringPointer()));
817  break;
818 
819  default:
820  break; // Do nothing for other types.
821  }
822  }
823  }
RAPIDJSON_FORCEINLINE const Ch * GetStringPointer() const
Definition: document.h:2022
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
const double e
RAPIDJSON_FORCEINLINE GenericValue * GetElementsPointer() const
Definition: document.h:2024
RAPIDJSON_FORCEINLINE Member * GetMembersPointer() const
Definition: document.h:2026

Member Function Documentation

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
RAPIDJSON_FORCEINLINE GenericValue* GenericValue< Encoding, Allocator >::GetElementsPointer ( ) const
inline

Definition at line 2024 of file document.h.

Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:319
GenericValue * elements
Definition: document.h:2010
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
RAPIDJSON_FORCEINLINE Member* GenericValue< Encoding, Allocator >::GetMembersPointer ( ) const
inline

Definition at line 2026 of file document.h.

GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:578
ObjectData o
Definition: document.h:2017
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:319
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
RAPIDJSON_FORCEINLINE const Ch* GenericValue< Encoding, Allocator >::GetStringPointer ( ) const
inline

Definition at line 2022 of file document.h.

2022 { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:581
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:319
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 833 of file document.h.

833  {
834  RAPIDJSON_ASSERT(this != &rhs);
835  this->~GenericValue();
836  RawAssign(rhs);
837  return *this;
838  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
~GenericValue()
Destructor.
Definition: document.h:797
void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment without calling destructor.
Definition: document.h:2080
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 852 of file document.h.

852  {
853  GenericValue s(str);
854  return *this = s;
855  }
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
static QCString * s
Definition: config.cpp:1042
static QCString str
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 2080 of file document.h.

2080  {
2081  data_ = rhs.data_;
2082  // data_.f.flags = rhs.data_.f.flags;
2083  rhs.data_.f.flags = kNullFlag;
2084  }
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
void GenericValue< Encoding, Allocator >::SetArrayRaw ( GenericValue< Encoding, Allocator > *  values,
SizeType  count,
Allocator &  allocator 
)
inline

Definition at line 2030 of file document.h.

2030  {
2031  data_.f.flags = kArrayFlag;
2032  if (count) {
2033  GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
2034  SetElementsPointer(e);
2035  std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
2036  }
2037  else
2038  SetElementsPointer(0);
2039  data_.a.size = data_.a.capacity = count;
2040  }
RAPIDJSON_FORCEINLINE GenericValue * SetElementsPointer(GenericValue *elements)
Definition: document.h:2025
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
const double e
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
RAPIDJSON_FORCEINLINE GenericValue* GenericValue< Encoding, Allocator >::SetElementsPointer ( GenericValue< Encoding, Allocator > *  elements)
inline

Definition at line 2025 of file document.h.

2025 { return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:318
GenericValue * elements
Definition: document.h:2010
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
RAPIDJSON_FORCEINLINE Member* GenericValue< Encoding, Allocator >::SetMembersPointer ( Member members)
inline

Definition at line 2027 of file document.h.

2027 { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:578
ObjectData o
Definition: document.h:2017
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:318
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 2043 of file document.h.

2043  {
2045  if (count) {
2046  Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
2047  SetMembersPointer(m);
2048  std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
2049  }
2050  else
2051  SetMembersPointer(0);
2052  data_.o.size = data_.o.capacity = count;
2053  }
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:578
ObjectData o
Definition: document.h:2017
RAPIDJSON_FORCEINLINE Member * SetMembersPointer(Member *members)
Definition: document.h:2027
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
RAPIDJSON_FORCEINLINE const Ch* GenericValue< Encoding, Allocator >::SetStringPointer ( const Ch str)
inline

Definition at line 2023 of file document.h.

2023 { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:581
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:318
static QCString str
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 2056 of file document.h.

2056  {
2059  data_.s.length = s.length;
2060  }
uint length() const
Definition: qcstring.h:195
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition: document.h:2023
static QCString * s
Definition: config.cpp:1042
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 2063 of file document.h.

2063  {
2064  Ch* str = 0;
2065  if (ShortString::Usable(s.length)) {
2068  str = data_.ss.str;
2069  } else {
2071  data_.s.length = s.length;
2072  str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
2073  SetStringPointer(str);
2074  }
2075  std::memcpy(str, s, s.length * sizeof(Ch));
2076  str[s.length] = '\0';
2077  }
void SetLength(SizeType len)
Definition: document.h:1971
uint length() const
Definition: qcstring.h:195
ShortString ss
Definition: document.h:2015
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:581
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition: document.h:2023
static bool Usable(SizeType len)
Definition: document.h:1970
static QCString * s
Definition: config.cpp:1042
static QCString str
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
template<typename SourceAllocator >
bool GenericValue< Encoding, Allocator >::StringEqual ( const GenericValue< Encoding, SourceAllocator > &  rhs) const
inline

Definition at line 2087 of file document.h.

2087  {
2088  RAPIDJSON_ASSERT(IsString());
2089  RAPIDJSON_ASSERT(rhs.IsString());
2090 
2091  const SizeType len1 = GetStringLength();
2092  const SizeType len2 = rhs.GetStringLength();
2093  if(len1 != len2) { return false; }
2094 
2095  const Ch* const str1 = GetString();
2096  const Ch* const str2 = rhs.GetString();
2097  if(str1 == str2) { return true; } // fast path for constant string
2098 
2099  return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
2100  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
#define GetString
Definition: config.cpp:1232
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:581

Friends And Related Function Documentation

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

Definition at line 1905 of file document.h.

Member Data Documentation

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

Definition at line 2102 of file document.h.

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

Definition at line 1938 of file document.h.

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

Definition at line 1939 of file document.h.


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