1 #ifndef RAPIDJSON_DOCUMENT_H_
2 #define RAPIDJSON_DOCUMENT_H_
10 #pragma warning(disable : 4127)
28 #pragma pack (push, 4)
29 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
40 typedef typename Encoding::Ch
Ch;
64 static const unsigned defaultFlags[7] = {
86 if (!(u & 0x80000000))
95 if (!(i64 & 0xFFFFFFFF00000000LL))
97 if (!(i64 & 0xFFFFFFFF80000000LL))
100 else if (i64 >= -2147483648LL)
107 if (!(u64 & 0x8000000000000000ULL))
109 if (!(u64 & 0xFFFFFFFF00000000ULL))
111 if (!(u64 & 0xFFFFFFFF80000000ULL))
139 if (Allocator::kNeedFree) {
149 m->name.~GenericValue();
150 m->value.~GenericValue();
182 template <
typename T>
234 return member->value;
289 template <
typename T>
310 m->name =
last->name;
311 m->value =
last->value;
315 m->name.~GenericValue();
316 m->value.~GenericValue();
404 template <
typename T>
493 template <
typename Handler>
498 case kTrueType: handler.Bool_(
true);
break;
501 handler.StartObject();
503 handler.String(
m->name.data_.s.str,
m->name.data_.s.length,
false);
504 m->value.Accept(handler);
510 handler.StartArray();
525 else handler.Double(
data_.
n.
d);
532 template <
typename,
typename>
574 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
626 if (length == member->name.data_.s.length && memcmp(member->name.data_.s.str,
name, length *
sizeof(
Ch)) == 0)
661 data_.
s.
str = (
Ch *)allocator.Malloc((length + 1) *
sizeof(
Ch));
690 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
693 typedef typename Encoding::Ch
Ch;
708 template <
unsigned parseFlags,
typename Stream>
712 if (reader.template Parse<parseFlags>(stream, *
this)) {
731 template <
unsigned parseFlags>
734 return ParseStream<parseFlags | kParseInsituFlag>(
s);
741 template <
unsigned parseFlags>
745 return ParseStream<parseFlags>(
s);
796 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount,
GetAllocator());
800 if (Allocator::kNeedFree)
801 while (
stack_.GetSize() > 0)
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Scalar * b
Definition: benchVecAdd.cpp:17
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:691
void EndArray(SizeType elementCount)
Definition: document.h:794
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:761
void String(const Ch *str, SizeType length, bool copy)
Definition: document.h:778
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:732
internal::Stack< Allocator > stack_
Definition: document.h:808
void ClearStack()
Definition: document.h:799
void Uint(unsigned i)
Definition: document.h:773
const char * parseError_
Definition: document.h:809
size_t GetErrorOffset() const
Get the offset in character of the parsing error.
Definition: document.h:755
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:695
bool HasParseError() const
Whether a parse error was occured in the last parsing.
Definition: document.h:749
const char * GetParseError() const
Get the message of parsing error.
Definition: document.h:752
void Int(int i)
Definition: document.h:772
size_t errorOffset_
Definition: document.h:810
void Bool_(bool b)
Definition: document.h:771
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:742
void EndObject(SizeType memberCount)
Definition: document.h:787
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:693
static const size_t kDefaultStackCapacity
Definition: document.h:807
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:694
void Double(double d)
Definition: document.h:776
void Null_()
Definition: document.h:770
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:758
void StartObject()
Definition: document.h:785
void Int64(int64_t i)
Definition: document.h:774
GenericDocument & ParseStream(Stream &stream)
Parse JSON text from an input stream.
Definition: document.h:709
GenericDocument & operator=(const GenericDocument &)
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity)
Constructor.
Definition: document.h:701
void StartArray()
Definition: document.h:792
void Uint64(uint64_t i)
Definition: document.h:775
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:206
const char * GetParseError() const
Definition: reader.h:261
size_t GetErrorOffset() const
Definition: reader.h:262
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:30
int64_t GetInt64() const
Definition: document.h:424
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:38
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:43
ConstValueIterator Begin() const
Definition: document.h:372
const GenericValue & operator[](const Ch *name) const
Definition: document.h:240
bool IsString() const
Definition: document.h:206
GenericValue & SetUint(unsigned u)
Definition: document.h:437
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a value at the end of the array.
Definition: document.h:396
GenericValue()
Default constructor creates a null value.
Definition: document.h:50
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:380
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:452
bool IsTrue() const
Definition: document.h:196
const GenericValue & operator[](SizeType index) const
Definition: document.h:367
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:330
GenericValue & SetInt64(int64_t i64)
Definition: document.h:438
bool GetBool_() const
Definition: document.h:220
Member * FindMember(const Ch *name)
Find member by name.
Definition: document.h:618
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &alloctaor)
Definition: document.h:634
ConstMemberIterator MemberEnd() const
Definition: document.h:244
GenericValue(int i)
Constructor for int value.
Definition: document.h:77
const Member * ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:42
void SetStringRaw(const Ch *s, SizeType length)
Initialize this value as constant string, without calling destructor.
Definition: document.h:650
GenericValue & operator=(GenericValue &rhs)
Assignment with move semantics.
Definition: document.h:170
~GenericValue()
Destructor.
Definition: document.h:138
GenericValue & AddMember(const Ch *name, T value, Allocator &allocator)
Definition: document.h:290
GenericValue(unsigned u)
Constructor for unsigned value.
Definition: document.h:84
bool IsUint64() const
Definition: document.h:204
GenericValue(Type type)
Constructor with JSON value type.
Definition: document.h:63
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:39
bool IsFalse() const
Definition: document.h:195
int GetInt() const
Definition: document.h:422
void SetObjectRaw(Member *members, SizeType count, Allocator &alloctaor)
Initialize this value as object with initial data, without calling destructor.
Definition: document.h:642
GenericValue(const Ch *s, SizeType length)
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:119
void RawAssign(GenericValue &rhs)
Assignment without calling destructor.
Definition: document.h:668
unsigned flags_
Definition: document.h:674
bool IsBool_() const
Definition: document.h:197
SizeType Size() const
Get the number of elements in array.
Definition: document.h:333
bool IsNull_() const
Definition: document.h:194
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:229
Data data_
Definition: document.h:673
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:336
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:133
const Member * FindMember(const Ch *name) const
Definition: document.h:631
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:44
GenericValue & SetUint64(uint64_t u64)
Definition: document.h:439
ValueIterator Begin()
Element iterator.
Definition: document.h:370
bool IsArray() const
Definition: document.h:199
MemberIterator MemberBegin()
Definition: document.h:245
const Ch * GetString() const
Definition: document.h:447
unsigned GetUint() const
Definition: document.h:423
double GetDouble() const
Definition: document.h:427
void Clear()
Remove all elements in the array.
Definition: document.h:344
GenericValue & PushBack(T value, Allocator &allocator)
Definition: document.h:405
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:301
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:249
GenericValue(double d)
Constructor for double value.
Definition: document.h:116
uint64_t GetUint64() const
Definition: document.h:425
GenericValue(const Ch *s)
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:127
ValueIterator End()
Definition: document.h:371
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:258
GenericValue & AddMember(const Ch *name, GenericValue &value, Allocator &allocator)
Definition: document.h:284
static const SizeType kDefaultArrayCapacity
Definition: document.h:563
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:482
bool IsObject() const
Definition: document.h:198
GenericValue & operator=(T value)
Assignment with primitive types.
Definition: document.h:183
GenericValue & SetString(const Ch *s)
Set this value as a string without copying source string.
Definition: document.h:466
ConstValueIterator End() const
Definition: document.h:373
GenericValue & AddMember(const Ch *name, Allocator &nameAllocator, GenericValue &value, Allocator &allocator)
Definition: document.h:279
static const SizeType kDefaultObjectCapacity
Definition: document.h:564
GenericValue(const GenericValue &rhs)
Copy constructor is not permitted.
bool IsInt() const
Definition: document.h:201
bool IsNumber() const
Definition: document.h:200
GenericValue & SetInt(int i)
Definition: document.h:436
GenericValue(int64_t i64)
Constructor for int64_t value.
Definition: document.h:91
Member * MemberIterator
Member iterator for iterating in object.
Definition: document.h:41
bool Empty() const
Check whether the array is empty.
Definition: document.h:339
GenericValue & SetNull_()
Definition: document.h:213
Type GetType() const
Definition: document.h:193
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:130
GenericValue(bool b)
Constructor for boolean value.
Definition: document.h:74
MemberIterator MemberEnd()
Definition: document.h:246
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:362
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:40
bool IsDouble() const
Definition: document.h:205
GenericValue & operator[](const Ch *name)
Get the value associated with the object's name.
Definition: document.h:232
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:411
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:475
bool IsUint() const
Definition: document.h:202
GenericValue & SetBool_(bool b)
Definition: document.h:221
ConstMemberIterator MemberBegin() const
Member iterators.
Definition: document.h:243
const GenericValue & Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:494
GenericValue(uint64_t u64)
Constructor for uint64_t value.
Definition: document.h:105
@ kStringFlag
Definition: document.h:543
@ kTrueFlag
Definition: document.h:548
@ kNumberDoubleFlag
Definition: document.h:554
@ kNumberUint64Flag
Definition: document.h:553
@ kFalseFlag
Definition: document.h:549
@ kDoubleFlag
Definition: document.h:542
@ kBool_Flag
Definition: document.h:536
@ kArrayFlag
Definition: document.h:558
@ kConstStringFlag
Definition: document.h:555
@ kTypeMask
Definition: document.h:560
@ kIntFlag
Definition: document.h:538
@ kObjectFlag
Definition: document.h:557
@ kCopyFlag
Definition: document.h:544
@ kNumberUintFlag
Definition: document.h:551
@ kUint64Flag
Definition: document.h:541
@ kNumberInt64Flag
Definition: document.h:552
@ kNull_Flag
Definition: document.h:547
@ kCopyStringFlag
Definition: document.h:556
@ kNumberIntFlag
Definition: document.h:550
@ kUintFlag
Definition: document.h:539
@ kNumberFlag
Definition: document.h:537
@ kInt64Flag
Definition: document.h:540
GenericValue & SetDouble(double d)
Definition: document.h:440
void SetStringRaw(const Ch *s, SizeType length, Allocator &allocator)
Initialize this value as copy string with initial data, without calling destructor.
Definition: document.h:658
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:460
bool IsInt64() const
Definition: document.h:203
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:14
static constexpr const last_t last
Definition: IndexedViewHelper.h:48
RealScalar s
Definition: level1_cplx_impl.h:130
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
#define I
Definition: main.h:127
std::int64_t int64_t
Definition: Meta.h:43
std::uint64_t uint64_t
Definition: Meta.h:42
squared absolute value
Definition: GlobalFunctions.h:87
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
type
Definition: compute_granudrum_aor.py:141
str
Definition: compute_granudrum_aor.py:141
string name
Definition: plotDoE.py:33
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:14
Definition: document.h:13
GenericDocument< UTF8<> > Document
Definition: document.h:813
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:44
Type
Type of JSON value.
Definition: rapidjson.h:513
@ kArrayType
array
Definition: rapidjson.h:518
@ kNull_Type
null
Definition: rapidjson.h:514
@ kTrueType
true
Definition: rapidjson.h:516
@ kFalseType
false
Definition: rapidjson.h:515
@ kNumberType
number
Definition: rapidjson.h:520
@ kObjectType
object
Definition: rapidjson.h:517
@ kStringType
string
Definition: rapidjson.h:519
GenericValue< UTF8<> > Value
Value with UTF8 encoding.
Definition: document.h:679
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:80
A read-write string stream.
Definition: rapidjson.h:487
Read-only string stream.
Definition: rapidjson.h:460
Definition: document.h:604
SizeType capacity
Definition: document.h:607
SizeType size
Definition: document.h:606
GenericValue< Encoding, Allocator > * elements
Definition: document.h:605
Name-value pair in an object.
Definition: document.h:33
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:34
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:35
Definition: document.h:575
char padding[4]
Definition: document.h:577
int i
Definition: document.h:576
Definition: document.h:579
char padding2[4]
Definition: document.h:581
unsigned u
Definition: document.h:580
Definition: document.h:598
SizeType capacity
Definition: document.h:601
SizeType size
Definition: document.h:600
Member * members
Definition: document.h:599
Definition: document.h:566
SizeType length
Definition: document.h:568
const Ch * str
Definition: document.h:567
unsigned hashcode
reserved
Definition: document.h:569
Definition: document.h:610
Number n
Definition: document.h:612
Array a
Definition: document.h:614
Object o
Definition: document.h:613
String s
Definition: document.h:611
Definition: document.h:573
uint64_t u64
Definition: document.h:594
int64_t i64
Definition: document.h:593
struct rapidjson::GenericValue::Number::I i
double d
Definition: document.h:595
struct rapidjson::GenericValue::Number::U u