26 #ifndef RAPIDJSON_DOCUMENT_H_
27 #define RAPIDJSON_DOCUMENT_H_
35 #pragma warning(disable : 4127)
53 #pragma pack (push, 4)
54 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
65 typedef typename Encoding::Ch
Ch;
89 static const unsigned defaultFlags[7] = {
94 flags_ = defaultFlags[type];
111 if (!(u & 0x80000000))
120 if (!(i64 & 0xFFFFFFFF00000000LL))
122 if (!(i64 & 0xFFFFFFFF80000000LL))
125 else if (i64 >= -2147483648LL)
132 if (!(u64 & 0x8000000000000000ULL))
134 if (!(u64 & 0xFFFFFFFF00000000ULL))
136 if (!(u64 & 0xFFFFFFFF80000000ULL))
164 if (Allocator::kNeedFree) {
174 m->name.~GenericValue();
175 m->value.~GenericValue();
207 template <
typename T>
259 return member->value;
314 template <
typename T>
336 m->value = last->
value;
340 m->name.~GenericValue();
341 m->value.~GenericValue();
429 template <
typename T>
518 template <
typename Handler>
523 case kTrueType: handler.Bool_(
true);
break;
526 handler.StartObject();
528 handler.String(m->name.data_.s.str, m->name.data_.s.length,
false);
529 m->value.Accept(handler);
535 handler.StartArray();
550 else handler.Double(
data_.
n.
d);
557 template <
typename,
typename>
599 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
651 if (length == member->name.data_.s.length && memcmp(member->name.data_.s.str,
name, length *
sizeof(
Ch)) == 0)
686 data_.
s.
str = (
Ch *)allocator.Malloc((length + 1) *
sizeof(
Ch));
688 memcpy(
const_cast<Ch*
>(
data_.
s.
str), s, length *
sizeof(
Ch));
715 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
718 typedef typename Encoding::Ch
Ch;
733 template <
unsigned parseFlags,
typename Stream>
737 if (reader.template Parse<parseFlags>(stream, *
this)) {
756 template <
unsigned parseFlags>
759 return ParseStream<parseFlags | kParseInsituFlag>(s);
766 template <
unsigned parseFlags>
770 return ParseStream<parseFlags>(s);
821 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount,
GetAllocator());
825 if (Allocator::kNeedFree)
826 while (
stack_.GetSize() > 0)
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
A document for parsing JSON text as DOM.
Definition: document.h:716
void EndArray(SizeType elementCount)
Definition: document.h:819
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:786
void String(const Ch *str, SizeType length, bool copy)
Definition: document.h:803
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:757
internal::Stack< Allocator > stack_
Definition: document.h:833
void ClearStack()
Definition: document.h:824
void Uint(unsigned i)
Definition: document.h:798
const char * parseError_
Definition: document.h:834
size_t GetErrorOffset() const
Get the offset in character of the parsing error.
Definition: document.h:780
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:720
bool HasParseError() const
Whether a parse error was occured in the last parsing.
Definition: document.h:774
const char * GetParseError() const
Get the message of parsing error.
Definition: document.h:777
void Int(int i)
Definition: document.h:797
size_t errorOffset_
Definition: document.h:835
void Bool_(bool b)
Definition: document.h:796
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:767
void EndObject(SizeType memberCount)
Definition: document.h:812
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:718
static const size_t kDefaultStackCapacity
Definition: document.h:832
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:719
void Double(double d)
Definition: document.h:801
void Null_()
Definition: document.h:795
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:783
void StartObject()
Definition: document.h:810
void Int64(int64_t i)
Definition: document.h:799
GenericDocument & ParseStream(Stream &stream)
Parse JSON text from an input stream.
Definition: document.h:734
GenericDocument & operator=(const GenericDocument &)
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity)
Constructor.
Definition: document.h:726
void StartArray()
Definition: document.h:817
void Uint64(uint64_t i)
Definition: document.h:800
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:231
const char * GetParseError() const
Definition: reader.h:286
size_t GetErrorOffset() const
Definition: reader.h:287
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:55
int64_t GetInt64() const
Definition: document.h:449
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:63
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:68
ConstValueIterator Begin() const
Definition: document.h:397
const GenericValue & operator[](const Ch *name) const
Definition: document.h:265
bool IsString() const
Definition: document.h:231
GenericValue & SetUint(unsigned u)
Definition: document.h:462
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a value at the end of the array.
Definition: document.h:421
GenericValue()
Default constructor creates a null value.
Definition: document.h:75
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:405
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:477
bool IsTrue() const
Definition: document.h:221
const GenericValue & operator[](SizeType index) const
Definition: document.h:392
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:355
GenericValue & SetInt64(int64_t i64)
Definition: document.h:463
bool GetBool_() const
Definition: document.h:245
Member * FindMember(const Ch *name)
Find member by name.
Definition: document.h:643
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &alloctaor)
Definition: document.h:659
ConstMemberIterator MemberEnd() const
Definition: document.h:269
GenericValue(int i)
Constructor for int value.
Definition: document.h:102
const Member * ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:67
void SetStringRaw(const Ch *s, SizeType length)
Initialize this value as constant string, without calling destructor.
Definition: document.h:675
GenericValue & operator=(GenericValue &rhs)
Assignment with move semantics.
Definition: document.h:195
~GenericValue()
Destructor.
Definition: document.h:163
GenericValue & AddMember(const Ch *name, T value, Allocator &allocator)
Definition: document.h:315
GenericValue(unsigned u)
Constructor for unsigned value.
Definition: document.h:109
bool IsUint64() const
Definition: document.h:229
GenericValue(Type type)
Constructor with JSON value type.
Definition: document.h:88
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:64
bool IsFalse() const
Definition: document.h:220
int GetInt() const
Definition: document.h:447
void SetObjectRaw(Member *members, SizeType count, Allocator &alloctaor)
Initialize this value as object with initial data, without calling destructor.
Definition: document.h:667
GenericValue(const Ch *s, SizeType length)
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:144
void RawAssign(GenericValue &rhs)
Assignment without calling destructor.
Definition: document.h:693
unsigned flags_
Definition: document.h:699
bool IsBool_() const
Definition: document.h:222
SizeType Size() const
Get the number of elements in array.
Definition: document.h:358
bool IsNull_() const
Definition: document.h:219
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:254
Data data_
Definition: document.h:698
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:361
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:158
const Member * FindMember(const Ch *name) const
Definition: document.h:656
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:69
GenericValue & SetUint64(uint64_t u64)
Definition: document.h:464
ValueIterator Begin()
Element iterator.
Definition: document.h:395
bool IsArray() const
Definition: document.h:224
MemberIterator MemberBegin()
Definition: document.h:270
const Ch * GetString() const
Definition: document.h:472
unsigned GetUint() const
Definition: document.h:448
double GetDouble() const
Definition: document.h:452
void Clear()
Remove all elements in the array.
Definition: document.h:369
GenericValue & PushBack(T value, Allocator &allocator)
Definition: document.h:430
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:326
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:274
GenericValue(double d)
Constructor for double value.
Definition: document.h:141
uint64_t GetUint64() const
Definition: document.h:450
GenericValue(const Ch *s)
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:152
ValueIterator End()
Definition: document.h:396
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:283
GenericValue & AddMember(const Ch *name, GenericValue &value, Allocator &allocator)
Definition: document.h:309
static const SizeType kDefaultArrayCapacity
Definition: document.h:588
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:507
bool IsObject() const
Definition: document.h:223
GenericValue & operator=(T value)
Assignment with primitive types.
Definition: document.h:208
GenericValue & SetString(const Ch *s)
Set this value as a string without copying source string.
Definition: document.h:491
ConstValueIterator End() const
Definition: document.h:398
GenericValue & AddMember(const Ch *name, Allocator &nameAllocator, GenericValue &value, Allocator &allocator)
Definition: document.h:304
static const SizeType kDefaultObjectCapacity
Definition: document.h:589
GenericValue(const GenericValue &rhs)
Copy constructor is not permitted.
bool IsInt() const
Definition: document.h:226
bool IsNumber() const
Definition: document.h:225
GenericValue & SetInt(int i)
Definition: document.h:461
GenericValue(int64_t i64)
Constructor for int64_t value.
Definition: document.h:116
Member * MemberIterator
Member iterator for iterating in object.
Definition: document.h:66
bool Empty() const
Check whether the array is empty.
Definition: document.h:364
GenericValue & SetNull_()
Definition: document.h:238
Type GetType() const
Definition: document.h:218
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:155
GenericValue(bool b)
Constructor for boolean value.
Definition: document.h:99
MemberIterator MemberEnd()
Definition: document.h:271
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:387
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:65
bool IsDouble() const
Definition: document.h:230
GenericValue & operator[](const Ch *name)
Get the value associated with the object's name.
Definition: document.h:257
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:436
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:500
bool IsUint() const
Definition: document.h:227
GenericValue & SetBool_(bool b)
Definition: document.h:246
ConstMemberIterator MemberBegin() const
Member iterators.
Definition: document.h:268
const GenericValue & Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:519
GenericValue(uint64_t u64)
Constructor for uint64_t value.
Definition: document.h:130
@ kStringFlag
Definition: document.h:568
@ kTrueFlag
Definition: document.h:573
@ kNumberDoubleFlag
Definition: document.h:579
@ kNumberUint64Flag
Definition: document.h:578
@ kFalseFlag
Definition: document.h:574
@ kDoubleFlag
Definition: document.h:567
@ kBool_Flag
Definition: document.h:561
@ kArrayFlag
Definition: document.h:583
@ kConstStringFlag
Definition: document.h:580
@ kTypeMask
Definition: document.h:585
@ kIntFlag
Definition: document.h:563
@ kObjectFlag
Definition: document.h:582
@ kCopyFlag
Definition: document.h:569
@ kNumberUintFlag
Definition: document.h:576
@ kUint64Flag
Definition: document.h:566
@ kNumberInt64Flag
Definition: document.h:577
@ kNull_Flag
Definition: document.h:572
@ kCopyStringFlag
Definition: document.h:581
@ kNumberIntFlag
Definition: document.h:575
@ kUintFlag
Definition: document.h:564
@ kNumberFlag
Definition: document.h:562
@ kInt64Flag
Definition: document.h:565
GenericValue & SetDouble(double d)
Definition: document.h:465
void SetStringRaw(const Ch *s, SizeType length, Allocator &allocator)
Initialize this value as copy string with initial data, without calling destructor.
Definition: document.h:683
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:485
bool IsInt64() const
Definition: document.h:228
Concept for receiving events from GenericReader upon parsing.
Concept for reading and writing characters.
A type-unsafe stack for storing different types of data.
Definition: stack.h:39
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:39
Definition: document.h:38
unsigned SizeType
Use 32-bit array/string indices even for 64-bit platform, instead of using size_t.
Definition: rapidjson.h:92
GenericDocument< UTF8<> > Document
Definition: document.h:838
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:69
Type
Type of JSON value.
Definition: rapidjson.h:538
@ kArrayType
array
Definition: rapidjson.h:543
@ kNull_Type
null
Definition: rapidjson.h:539
@ kTrueType
true
Definition: rapidjson.h:541
@ kFalseType
false
Definition: rapidjson.h:540
@ kNumberType
number
Definition: rapidjson.h:545
@ kObjectType
object
Definition: rapidjson.h:542
@ kStringType
string
Definition: rapidjson.h:544
GenericValue< UTF8<> > Value
Value with UTF8 encoding.
Definition: document.h:704
std::string name
Definition: MercuryProb.h:48
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:105
A read-write string stream.
Definition: rapidjson.h:512
Read-only string stream.
Definition: rapidjson.h:485
Definition: document.h:629
SizeType capacity
Definition: document.h:632
SizeType size
Definition: document.h:631
GenericValue< Encoding, Allocator > * elements
Definition: document.h:630
Name-value pair in an object.
Definition: document.h:58
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:59
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:60
Definition: document.h:600
char padding[4]
Definition: document.h:602
int i
Definition: document.h:601
Definition: document.h:604
char padding2[4]
Definition: document.h:606
unsigned u
Definition: document.h:605
Definition: document.h:623
SizeType capacity
Definition: document.h:626
SizeType size
Definition: document.h:625
Member * members
Definition: document.h:624
Definition: document.h:591
SizeType length
Definition: document.h:593
const Ch * str
Definition: document.h:592
unsigned hashcode
reserved
Definition: document.h:594
Definition: document.h:635
Number n
Definition: document.h:637
Array a
Definition: document.h:639
Object o
Definition: document.h:638
String s
Definition: document.h:636
Definition: document.h:598
uint64_t u64
Definition: document.h:619
int64_t i64
Definition: document.h:618
struct rapidjson::GenericValue::Number::I i
double d
Definition: document.h:620
struct rapidjson::GenericValue::Number::U u