15 #ifndef RAPIDJSON_POINTER_H_ 16 #define RAPIDJSON_POINTER_H_ 23 RAPIDJSON_DIAG_OFF(
switch-
enum)
28 RAPIDJSON_DIAG_OFF(4512)
80 template <
typename ValueType,
typename Allocator = CrtAllocator>
84 typedef typename ValueType::Ch
Ch;
120 #if RAPIDJSON_HAS_STDSTRING 214 Ch *
p =
r.CopyFromRaw(*
this, 1, token.
length + 1);
240 template <
typename T>
246 #if RAPIDJSON_HAS_STDSTRING 270 if (
sizeof(
Ch) == 1) {
276 for (
size_t i = 0; i <=
length; i++)
290 if (token.IsString())
314 Allocator& GetAllocator() {
return *
allocator_; }
323 size_t GetTokenCount()
const {
return tokenCount_; }
354 bool operator!=(
const GenericPointer& rhs)
const {
return !(*
this == rhs); }
366 template<
typename OutputStream>
368 return Stringify<false, OutputStream>(os);
376 template<
typename OutputStream>
377 bool StringifyUriFragment(OutputStream& os)
const {
378 return Stringify<true, OutputStream>(os);
401 ValueType& Create(ValueType& root,
typename ValueType::AllocatorType&
allocator,
bool* alreadyExist = 0)
const {
403 ValueType*
v = &root;
406 if (
v->IsArray() &&
t->name[0] ==
'-' &&
t->length == 1) {
408 v = &((*v)[
v->Size() - 1]);
417 if (!
v->IsArray() && !
v->IsObject())
422 if (
t->index >=
v->Size()) {
424 while (
t->index >=
v->Size())
428 v = &((*v)[
t->index]);
432 if (
m ==
v->MemberEnd()) {
434 v = &(--
v->MemberEnd())->
value;
444 *alreadyExist = exist;
455 template <
typename stackAllocator>
479 ValueType* Get(ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
481 ValueType*
v = &root;
483 switch (
v->GetType()) {
487 if (
m ==
v->MemberEnd())
495 v = &((*v)[
t->index]);
502 if (unresolvedTokenIndex)
503 *unresolvedTokenIndex =
static_cast<size_t>(
t -
tokens_);
514 const ValueType* Get(
const ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
515 return Get(const_cast<ValueType&>(root), unresolvedTokenIndex);
533 ValueType& GetWithDefault(ValueType& root,
const ValueType&
defaultValue,
typename ValueType::AllocatorType&
allocator)
const {
540 ValueType& GetWithDefault(ValueType& root,
const Ch*
defaultValue,
typename ValueType::AllocatorType&
allocator)
const {
546 #if RAPIDJSON_HAS_STDSTRING 547 ValueType& GetWithDefault(ValueType& root,
const std::basic_string<Ch>&
defaultValue,
typename ValueType::AllocatorType&
allocator)
const {
559 template <
typename T>
566 template <
typename stackAllocator>
572 template <
typename stackAllocator>
577 #if RAPIDJSON_HAS_STDSTRING 578 template <
typename stackAllocator>
589 template <
typename T,
typename stackAllocator>
610 ValueType&
Set(ValueType& root, ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
615 ValueType&
Set(ValueType& root,
const ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
624 #if RAPIDJSON_HAS_STDSTRING 625 ValueType&
Set(ValueType& root,
const std::basic_string<Ch>&
value,
typename ValueType::AllocatorType&
allocator)
const {
635 template <
typename T>
642 template <
typename stackAllocator>
648 template <
typename stackAllocator>
654 template <
typename stackAllocator>
659 #if RAPIDJSON_HAS_STDSTRING 660 template <
typename stackAllocator>
671 template <
typename T,
typename stackAllocator>
692 ValueType&
Swap(ValueType& root, ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
697 template <
typename stackAllocator>
716 ValueType*
v = &root;
719 switch (
v->GetType()) {
723 if (
m ==
v->MemberEnd())
731 v = &((*v)[
t->index]);
738 switch (
v->GetType()) {
744 v->Erase(
v->Begin() + last->
index);
765 nameBufferSize +=
t->length;
773 if (nameBufferSize > 0) {
791 return !((
c >=
'0' &&
c <=
'9') || (
c >=
'A' &&
c <=
'Z') || (
c >=
'a' &&
c <=
'z') ||
c ==
'-' ||
c ==
'.' ||
c ==
'_' ||
c ==
'~');
795 #ifndef __clang__ // -Wdocumentation 822 bool uriFragment =
false;
838 bool isNumber =
true;
875 if (
c ==
'0')
c =
'~';
876 else if (
c ==
'1')
c =
'/';
901 if (isNumber && token->
length > 1 && token->
name[0] ==
'0')
907 for (
size_t j = 0;
j < token->
length;
j++) {
940 template<
bool uriFragment,
typename OutputStream>
949 for (
size_t j = 0;
j <
t->length;
j++) {
982 typedef typename ValueType::Ch
Ch;
998 for (
int j = 0;
j < 2;
j++) {
999 c =
static_cast<Ch>(
c << 4);
1001 if (
h >=
'0' &&
h <=
'9')
c =
static_cast<Ch>(
c +
h -
'0');
1002 else if (
h >=
'A' &&
h <=
'F')
c =
static_cast<Ch>(
c +
h -
'A' + 10);
1003 else if (
h >=
'a' &&
h <=
'f')
c =
static_cast<Ch>(
c +
h -
'a' + 10);
1024 template <
typename OutputStream>
1029 unsigned char u =
static_cast<unsigned char>(
c);
1030 static const char hexDigits[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
1032 os_.Put(hexDigits[u >> 4]);
1033 os_.Put(hexDigits[u & 15]);
1056 template <
typename T>
1061 template <
typename T,
typename CharType,
size_t N>
1068 template <
typename DocumentType>
1070 return pointer.Create(document);
1073 template <
typename DocumentType,
typename CharType,
size_t N>
1080 template <
typename T>
1082 return pointer.Get(root, unresolvedTokenIndex);
1085 template <
typename T>
1087 return pointer.Get(root, unresolvedTokenIndex);
1090 template <
typename T,
typename CharType,
size_t N>
1095 template <
typename T,
typename CharType,
size_t N>
1102 template <
typename T>
1107 template <
typename T>
1112 #if RAPIDJSON_HAS_STDSTRING 1113 template <
typename T>
1119 template <
typename T,
typename T2>
1125 template <
typename T,
typename CharType,
size_t N>
1130 template <
typename T,
typename CharType,
size_t N>
1135 #if RAPIDJSON_HAS_STDSTRING 1136 template <
typename T,
typename CharType,
size_t N>
1142 template <
typename T,
typename CharType,
size_t N,
typename T2>
1150 template <
typename DocumentType>
1155 template <
typename DocumentType>
1160 #if RAPIDJSON_HAS_STDSTRING 1161 template <
typename DocumentType>
1167 template <
typename DocumentType,
typename T2>
1173 template <
typename DocumentType,
typename CharType,
size_t N>
1178 template <
typename DocumentType,
typename CharType,
size_t N>
1183 #if RAPIDJSON_HAS_STDSTRING 1184 template <
typename DocumentType,
typename CharType,
size_t N>
1190 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1198 template <
typename T>
1203 template <
typename T>
1208 template <
typename T>
1213 #if RAPIDJSON_HAS_STDSTRING 1214 template <
typename T>
1220 template <
typename T,
typename T2>
1226 template <
typename T,
typename CharType,
size_t N>
1231 template <
typename T,
typename CharType,
size_t N>
1236 template <
typename T,
typename CharType,
size_t N>
1241 #if RAPIDJSON_HAS_STDSTRING 1242 template <
typename T,
typename CharType,
size_t N>
1243 typename T::ValueType&
SetValueByPointer(
T& root,
const CharType(&
source)[N],
const std::basic_string<typename T::Ch>&
value,
typename T::AllocatorType&
a) {
1248 template <
typename T,
typename CharType,
size_t N,
typename T2>
1256 template <
typename DocumentType>
1261 template <
typename DocumentType>
1266 template <
typename DocumentType>
1271 #if RAPIDJSON_HAS_STDSTRING 1272 template <
typename DocumentType>
1278 template <
typename DocumentType,
typename T2>
1284 template <
typename DocumentType,
typename CharType,
size_t N>
1289 template <
typename DocumentType,
typename CharType,
size_t N>
1294 template <
typename DocumentType,
typename CharType,
size_t N>
1299 #if RAPIDJSON_HAS_STDSTRING 1300 template <
typename DocumentType,
typename CharType,
size_t N>
1301 typename DocumentType::ValueType&
SetValueByPointer(DocumentType& document,
const CharType(&
source)[N],
const std::basic_string<typename DocumentType::Ch>&
value) {
1306 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1314 template <
typename T>
1319 template <
typename T,
typename CharType,
size_t N>
1324 template <
typename DocumentType>
1329 template <
typename DocumentType,
typename CharType,
size_t N>
1336 template <
typename T>
1341 template <
typename T,
typename CharType,
size_t N>
1358 #endif // RAPIDJSON_POINTER_H_
bool EraseValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer)
Definition: pointer.h:1337
OutputStream & os_
Definition: pointer.h:1036
GLuint const GLchar * name
Definition: glext.h:6671
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
#define const
Definition: zconf.h:217
~GenericPointer()
Destructor.
Definition: pointer.h:173
ValueType::EncodingType EncodingType
Encoding type from Value.
Definition: pointer.h:83
Invalid percent encoding in URI fragment.
Definition: pointer.h:44
PointerParseErrorCode
Error code of parsing.
Definition: pointer.h:39
bool Stringify(OutputStream &os) const
Stringify to string or URI fragment representation.
Definition: pointer.h:941
ValueType & Swap(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Swap a value with a value in a subtree.
Definition: pointer.h:692
A token must begin with a '/'.
Definition: pointer.h:42
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1040
GLuint buffer
Definition: glext.h:6555
array
Definition: rapidjson.h:608
GLenum target
Definition: glext.h:7982
SizeType length
Length of the name.
Definition: pointer.h:101
#define RAPIDJSON_NEW(x)
! customization point for global new
Definition: rapidjson.h:586
GenericPointer(Allocator *allocator=0)
Default constructor.
Definition: pointer.h:109
A token is the basic units of internal representation.
Definition: pointer.h:99
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
A read-write string stream.
Definition: fwd.h:52
GLdouble GLdouble t
Definition: glext.h:6398
Token * tokens_
A list of tokens.
Definition: pointer.h:1042
GLenum GLsizei len
Definition: glext.h:7389
T::ValueType * GetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, size_t *unresolvedTokenIndex=0)
Definition: pointer.h:1081
object
Definition: rapidjson.h:607
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1039
Encoding conversion.
Definition: encodings.h:658
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:123
void Put(char c)
Definition: pointer.h:1028
int memcmp(const void *s1, const void *s2, unsigned int length)
Definition: compat_ctype.c:51
GLdouble s
Definition: glext.h:6390
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39
A character must percent encoded in URI fragment.
Definition: pointer.h:45
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:30
GLsizei const GLvoid * pointer
Definition: glext.h:6488
T::ValueType & GetValueByPointerWithDefault(T &root, const GenericPointer< typename T::ValueType > &pointer, const typename T::ValueType &defaultValue, typename T::AllocatorType &a)
Definition: pointer.h:1103
ValueType & Set(ValueType &root, const ValueType &value, typename ValueType::AllocatorType &allocator) const
Set a value in a subtree, with copy semantics.
Definition: pointer.h:615
ValueType & Set(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Set a value in a subtree, with move semantics.
Definition: pointer.h:610
bool NeedPercentEncode(Ch c) const
Check whether a character should be percent-encoded.
Definition: pointer.h:790
Allocator stackAllocator stackAllocator & document
Definition: pointer.h:591
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
Read-only string stream.
Definition: fwd.h:47
GenericPointer(const Ch *source, Allocator *allocator=0)
Constructor that parses a string or URI fragment representation.
Definition: pointer.h:116
bool valid_
Whether the parsing is valid.
Definition: pointer.h:1020
const GLubyte * c
Definition: glext.h:9812
Allocator * allocator
Definition: pointer.h:242
unsigned StrLen(const Ch *s)
Definition: unittest.h:60
ValueType::Ch Ch
Character type from Value.
Definition: pointer.h:84
const Ch * head_
Original head of the string.
Definition: pointer.h:1018
Ch Take()
Definition: pointer.h:991
T::ValueType & CreateValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::AllocatorType &a)
Definition: pointer.h:1057
Ch * PutBegin()
Definition: stream.h:157
size_t Tell() const
Definition: pointer.h:1013
#define NULL
Pointer to 0.
Definition: gctypes.h:65
RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr< internal::IsSame< typename internal::RemoveConst< T >::Type, Ch > >),(GenericPointer)) Append(T *name
Append a name token without length, and return a new Pointer.
T::ValueType & SetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
Definition: pointer.h:1199
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1041
PercentEncodeStream(OutputStream &os)
Definition: pointer.h:1027
GenericPointer & operator=(const GenericPointer &rhs)
Assignment operator.
Definition: pointer.h:180
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Append a token and return a new Pointer.
Definition: pointer.h:211
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const ValueType &value) const
Set a value in a document, with copy semantics.
Definition: pointer.h:649
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
Set a value in a document, with move semantics.
Definition: pointer.h:643
static l_noret error(LoadState *S, const char *why)
Definition: lundump.c:39
GenericPointer(const Token *tokens, size_t tokenCount)
Constructor with user-supplied tokens.
Definition: pointer.h:165
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:402
Ch * CopyFromRaw(const GenericPointer &rhs, size_t extraToken=0, size_t extraNameBufferSize=0)
Clone the content from rhs to this.
Definition: pointer.h:759
const CharType(& source)[N]
Definition: pointer.h:1144
The parse is successful.
Definition: pointer.h:40
GenericPointer< Value > Pointer
GenericPointer for Value (UTF-8, default allocator).
Definition: pointer.h:1049
GLfloat GLfloat p
Definition: glext.h:9809
size_t PutEnd(Ch *begin)
Definition: stream.h:158
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:590
Invalid escape.
Definition: pointer.h:43
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1045
GLuint index
Definition: glext.h:6671
GLsizei GLsizei GLchar * source
Definition: glext.h:6688
const Ch * end_
Past-the-end position.
Definition: pointer.h:1019
Definition: lobject.h:100
bool operator==(const FloatProxy< T > &first, const FloatProxy< T > &second)
Definition: hex_float.h:162
const GLdouble * v
Definition: glext.h:6391
static RAPIDJSON_NAMESPACE_BEGIN const SizeType kPointerInvalidIndex
Represents an invalid index in GenericPointer::Token.
Definition: pointer.h:33
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
ValueType::Ch Ch
Definition: pointer.h:982
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1043
ValueType & Set(ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const
Set a null-terminated string in a subtree.
Definition: pointer.h:620
GLint j
Definition: nx_glsym.h:307
Definition: ffmpeg_fft.c:36
SizeType index
A valid array index, if it is not equal to kPointerInvalidIndex.
Definition: pointer.h:102
void Parse(const Ch *source, size_t length)
Parse a JSON String or its URI fragment representation into tokens.
Definition: pointer.h:802
A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence.
Definition: pointer.h:1025
GLsizei const GLfloat * value
Definition: glext.h:6709
PercentDecodeStream(const Ch *source, const Ch *end)
Constructor.
Definition: pointer.h:989
GenericPointer Append(const Ch *name, SizeType length, Allocator *allocator=0) const
Append a name token with length, and return a new Pointer.
Definition: pointer.h:229
Type
Type of JSON value.
Definition: rapidjson.h:603
T value
Definition: pointer.h:637
GLuint GLuint end
Definition: glext.h:6292
UTF-8 encoding.
Definition: encodings.h:96
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:8390
Definition: video4linux2.c:51
A document for parsing JSON text as DOM.
Definition: document.h:62
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: fwd.h:126
#define true
Definition: ordinals.h:82
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *value) const
Set a null-terminated string in a document.
Definition: pointer.h:655
T::ValueType & SwapValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
Definition: pointer.h:1315
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T2 >, internal::IsGenericValue< T2 > >),(typename T::ValueType &)) GetValueByPointerWithDefault(T &root
Definition: document.h:401
GenericPointer(const GenericPointer &rhs, Allocator *allocator=0)
Copy constructor.
Definition: pointer.h:168
const GenericPointer< typename T::ValueType > T2 defaultValue
Definition: pointer.h:1121
const Ch * src_
Current read position.
Definition: pointer.h:1017
Reference to a constant string (not taking a copy)
Definition: document.h:249
GLenum GLuint GLenum GLsizei length
Definition: glext.h:6233
GLdouble n
Definition: glext.h:8396
GenericPointer(const Ch *source, size_t length, Allocator *allocator=0)
Constructor that parses a string or URI fragment representation, with length of the source string.
Definition: pointer.h:139
bool IsValid() const
Definition: pointer.h:1014
A helper stream for decoding a percent-encoded sequence into code unit.
Definition: pointer.h:980
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1044
const GLfloat * m
Definition: glext.h:11755
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:380
bool Erase(ValueType &root) const
Erase a value in a subtree.
Definition: pointer.h:711
const Ch * name
Name of the token. It has null character at the end but it can contain null character.
Definition: pointer.h:100
ValueType & Swap(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
Swap a value with a value in a document.
Definition: pointer.h:698
void * memcpy(void *dst, const void *src, size_t len)
Definition: string.c:26