15 #ifndef RAPIDJSON_POINTER_H_
16 #define RAPIDJSON_POINTER_H_
19 #include "internal/itoa.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;
117 Parse(source, internal::StrLen(source));
120 #if RAPIDJSON_HAS_STDSTRING
127 explicit GenericPointer(
const std::basic_string<Ch>& source,
Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(
kPointerParseErrorNone) {
128 Parse(source.c_str(), source.size());
140 Parse(source, length);
175 Allocator::Free(tokens_);
184 Allocator::Free(tokens_);
186 tokenCount_ = rhs.tokenCount_;
187 parseErrorOffset_ = rhs.parseErrorOffset_;
188 parseErrorCode_ = rhs.parseErrorCode_;
193 tokens_ = rhs.tokens_;
213 r.allocator_ = allocator;
214 Ch *p = r.CopyFromRaw(*
this, 1, token.
length + 1);
215 std::memcpy(p, token.
name, (token.
length + 1) *
sizeof(
Ch));
216 r.tokens_[tokenCount_].
name = p;
230 Token token = { name, length, kPointerInvalidIndex };
231 return Append(token, allocator);
240 template <
typename T>
243 return Append(name, StrLen(name), allocator);
246 #if RAPIDJSON_HAS_STDSTRING
254 return Append(name.c_str(),
static_cast<SizeType>(name.size()), allocator);
266 char* end =
sizeof(
SizeType) == 4 ? internal::u32toa(index, buffer) : internal::u64toa(index, buffer);
268 buffer[length] =
'\0';
270 if (
sizeof(
Ch) == 1) {
271 Token token = {
reinterpret_cast<Ch*
>(buffer), length, index };
272 return Append(token, allocator);
276 for (
size_t i = 0; i <= length; i++)
278 Token token = { name, length, index };
279 return Append(token, allocator);
290 if (token.IsString())
291 return Append(token.GetString(), token.GetStringLength(), allocator);
295 return Append(
static_cast<SizeType>(token.GetUint64()), allocator);
306 size_t GetParseErrorOffset()
const {
return parseErrorOffset_; }
314 Allocator& GetAllocator() {
return *allocator_; }
320 const Token* GetTokens()
const {
return tokens_; }
323 size_t GetTokenCount()
const {
return tokenCount_; }
335 if (!IsValid() || !rhs.IsValid() || tokenCount_ != rhs.tokenCount_)
338 for (
size_t i = 0; i < tokenCount_; i++) {
339 if (tokens_[i].index != rhs.tokens_[i].
index ||
340 tokens_[i].length != rhs.tokens_[i].
length ||
341 (tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].
name,
sizeof(
Ch)* tokens_[i].length) != 0))
354 bool operator!=(
const GenericPointer& rhs)
const {
return !(*
this == rhs); }
366 template<
typename OutputStream>
367 bool Stringify(OutputStream& os)
const {
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;
405 for (
const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
406 if (v->IsArray() && t->name[0] ==
'-' && t->length == 1) {
407 v->PushBack(ValueType().Move(), allocator);
408 v = &((*v)[v->Size() - 1]);
412 if (t->index == kPointerInvalidIndex) {
417 if (!v->IsArray() && !v->IsObject())
422 if (t->index >= v->Size()) {
423 v->Reserve(t->index + 1, allocator);
424 while (t->index >= v->Size())
425 v->PushBack(ValueType().Move(), allocator);
428 v = &((*v)[t->index]);
432 if (m == v->MemberEnd()) {
433 v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator);
434 v = &(--v->MemberEnd())->value;
444 *alreadyExist = exist;
455 template <
typename stackAllocator>
457 return Create(document, document.
GetAllocator(), alreadyExist);
479 ValueType* Get(ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
481 ValueType* v = &root;
482 for (
const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
483 switch (v->GetType()) {
487 if (m == v->MemberEnd())
493 if (t->index == kPointerInvalidIndex || t->index >= v->Size())
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 {
535 Value& v = Create(root, allocator, &alreadyExist);
536 return alreadyExist ? v : v.CopyFrom(defaultValue, allocator);
540 ValueType& GetWithDefault(ValueType& root,
const Ch* defaultValue,
typename ValueType::AllocatorType& allocator)
const {
542 Value& v = Create(root, allocator, &alreadyExist);
543 return alreadyExist ? v : v.SetString(defaultValue, allocator);
546 #if RAPIDJSON_HAS_STDSTRING
548 ValueType& GetWithDefault(ValueType& root,
const std::basic_string<Ch>& defaultValue,
typename ValueType::AllocatorType& allocator)
const {
550 Value& v = Create(root, allocator, &alreadyExist);
551 return alreadyExist ? v : v.SetString(defaultValue, allocator);
559 template <
typename T>
561 GetWithDefault(ValueType& root, T defaultValue,
typename ValueType::AllocatorType& allocator)
const {
562 return GetWithDefault(root, ValueType(defaultValue).Move(), allocator);
566 template <
typename stackAllocator>
568 return GetWithDefault(document, defaultValue, document.
GetAllocator());
572 template <
typename stackAllocator>
574 return GetWithDefault(document, defaultValue, document.
GetAllocator());
577 #if RAPIDJSON_HAS_STDSTRING
579 template <
typename stackAllocator>
581 return GetWithDefault(document, defaultValue, document.
GetAllocator());
589 template <
typename T,
typename stackAllocator>
592 return GetWithDefault(document, defaultValue, document.
GetAllocator());
610 ValueType&
Set(ValueType& root, ValueType& value,
typename ValueType::AllocatorType& allocator)
const {
611 return Create(root, allocator) = value;
615 ValueType&
Set(ValueType& root,
const ValueType& value,
typename ValueType::AllocatorType& allocator)
const {
616 return Create(root, allocator).CopyFrom(value, allocator);
620 ValueType&
Set(ValueType& root,
const Ch* value,
typename ValueType::AllocatorType& allocator)
const {
621 return Create(root, allocator) = ValueType(value, allocator).Move();
624 #if RAPIDJSON_HAS_STDSTRING
626 ValueType&
Set(ValueType& root,
const std::basic_string<Ch>& value,
typename ValueType::AllocatorType& allocator)
const {
627 return Create(root, allocator) = ValueType(value, allocator).Move();
635 template <
typename T>
637 Set(ValueType& root, T value,
typename ValueType::AllocatorType& allocator)
const {
638 return Create(root, allocator) = ValueType(value).Move();
642 template <
typename stackAllocator>
644 return Create(document) = value;
648 template <
typename stackAllocator>
650 return Create(document).CopyFrom(value, document.
GetAllocator());
654 template <
typename stackAllocator>
656 return Create(document) = ValueType(value, document.
GetAllocator()).Move();
659 #if RAPIDJSON_HAS_STDSTRING
661 template <
typename stackAllocator>
663 return Create(document) = ValueType(value, document.
GetAllocator()).Move();
671 template <
typename T,
typename stackAllocator>
674 return Create(document) = value;
692 ValueType&
Swap(ValueType& root, ValueType& value,
typename ValueType::AllocatorType& allocator)
const {
693 return Create(root, allocator).Swap(value);
697 template <
typename stackAllocator>
699 return Create(document).Swap(value);
713 if (tokenCount_ == 0)
716 ValueType* v = &root;
717 const Token* last = tokens_ + (tokenCount_ - 1);
718 for (
const Token *t = tokens_; t != last; ++t) {
719 switch (v->GetType()) {
723 if (m == v->MemberEnd())
729 if (t->index == kPointerInvalidIndex || t->index >= v->Size())
731 v = &((*v)[t->index]);
738 switch (v->GetType()) {
742 if (last->
index == kPointerInvalidIndex || last->
index >= v->Size())
744 v->Erase(v->Begin() + last->
index);
759 Ch* CopyFromRaw(
const GenericPointer& rhs,
size_t extraToken = 0,
size_t extraNameBufferSize = 0) {
763 size_t nameBufferSize = rhs.tokenCount_;
764 for (Token *t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t)
765 nameBufferSize += t->length;
767 tokenCount_ = rhs.tokenCount_ + extraToken;
768 tokens_ =
static_cast<Token *
>(allocator_->Malloc(tokenCount_ *
sizeof(Token) + (nameBufferSize + extraNameBufferSize) *
sizeof(
Ch)));
769 nameBuffer_ =
reinterpret_cast<Ch *
>(tokens_ + tokenCount_);
770 if (rhs.tokenCount_ > 0) {
771 std::memcpy(tokens_, rhs.tokens_, rhs.tokenCount_ *
sizeof(Token));
773 if (nameBufferSize > 0) {
774 std::memcpy(nameBuffer_, rhs.nameBuffer_, nameBufferSize *
sizeof(
Ch));
778 std::ptrdiff_t diff = nameBuffer_ - rhs.nameBuffer_;
779 for (Token *t = tokens_; t != tokens_ + rhs.tokenCount_; ++t)
782 return nameBuffer_ + nameBufferSize;
790 bool NeedPercentEncode(
Ch c)
const {
791 return !((c >=
'0' && c <=
'9') || (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z') || c ==
'-' || c ==
'.' || c ==
'_' || c ==
'~');
802 void Parse(
const Ch* source,
size_t length) {
813 for (
const Ch* s = source; s != source + length; s++)
817 Token* token = tokens_ =
static_cast<Token *
>(allocator_->Malloc(tokenCount_ *
sizeof(Token) + length *
sizeof(
Ch)));
818 Ch* name = nameBuffer_ =
reinterpret_cast<Ch *
>(tokens_ + tokenCount_);
822 bool uriFragment =
false;
823 if (source[i] ==
'#') {
828 if (i != length && source[i] !=
'/') {
838 bool isNumber =
true;
840 while (i < length && source[i] !=
'/') {
845 PercentDecodeStream is(&source[i], source + length);
847 Ch* begin = os.PutBegin();
852 size_t len = os.PutEnd(begin);
863 else if (NeedPercentEncode(c)) {
875 if (c ==
'0') c =
'~';
876 else if (c ==
'1') c =
'/';
890 if (c < '0' || c >
'9')
895 token->length =
static_cast<SizeType>(name - token->name);
896 if (token->length == 0)
901 if (isNumber && token->length > 1 && token->name[0] ==
'0')
907 for (
size_t j = 0; j < token->length; j++) {
917 token->index = isNumber ? n : kPointerInvalidIndex;
926 Allocator::Free(tokens_);
930 parseErrorOffset_ = i;
940 template<
bool uriFragment,
typename OutputStream>
941 bool Stringify(OutputStream& os)
const {
947 for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
949 for (
size_t j = 0; j < t->length; j++) {
959 else if (uriFragment && NeedPercentEncode(c)) {
962 PercentEncodeStream<OutputStream> target(os);
965 j += source.Tell() - 1;
980 class PercentDecodeStream {
982 typedef typename ValueType::Ch
Ch;
989 PercentDecodeStream(
const Ch* source,
const Ch* end) : src_(source), head_(source), end_(end), valid_(true) {}
992 if (*src_ !=
'%' || src_ + 3 > end_) {
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);
1013 size_t Tell()
const {
return static_cast<size_t>(src_ - head_); }
1014 bool IsValid()
const {
return valid_; }
1024 template <
typename OutputStream>
1025 class PercentEncodeStream {
1027 PercentEncodeStream(OutputStream& os) : os_(os) {}
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]);
1044 size_t parseErrorOffset_;
1056 template <
typename T>
1058 return pointer.Create(root, a);
1061 template <
typename T,
typename CharType,
size_t N>
1062 typename T::ValueType& CreateValueByPointer(T& root,
const CharType(&source)[N],
typename T::AllocatorType& a) {
1068 template <
typename DocumentType>
1070 return pointer.Create(document);
1073 template <
typename DocumentType,
typename CharType,
size_t N>
1074 typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document,
const CharType(&source)[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>
1091 typename T::ValueType* GetValueByPointer(T& root,
const CharType (&source)[N],
size_t* unresolvedTokenIndex = 0) {
1095 template <
typename T,
typename CharType,
size_t N>
1096 const typename T::ValueType* GetValueByPointer(
const T& root,
const CharType(&source)[N],
size_t* unresolvedTokenIndex = 0) {
1102 template <
typename T>
1103 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const typename T::ValueType& defaultValue,
typename T::AllocatorType& a) {
1104 return pointer.GetWithDefault(root, defaultValue, a);
1107 template <
typename T>
1108 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const typename T::Ch* defaultValue,
typename T::AllocatorType& a) {
1109 return pointer.GetWithDefault(root, defaultValue, a);
1112 #if RAPIDJSON_HAS_STDSTRING
1113 template <
typename T>
1114 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const std::basic_string<typename T::Ch>& defaultValue,
typename T::AllocatorType& a) {
1115 return pointer.GetWithDefault(root, defaultValue, a);
1119 template <
typename T,
typename T2>
1122 return pointer.GetWithDefault(root, defaultValue, a);
1125 template <
typename T,
typename CharType,
size_t N>
1126 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const CharType(&source)[N],
const typename T::ValueType& defaultValue,
typename T::AllocatorType& a) {
1130 template <
typename T,
typename CharType,
size_t N>
1131 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const CharType(&source)[N],
const typename T::Ch* defaultValue,
typename T::AllocatorType& a) {
1135 #if RAPIDJSON_HAS_STDSTRING
1136 template <
typename T,
typename CharType,
size_t N>
1137 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const CharType(&source)[N],
const std::basic_string<typename T::Ch>& defaultValue,
typename T::AllocatorType& a) {
1142 template <
typename T,
typename CharType,
size_t N,
typename T2>
1144 GetValueByPointerWithDefault(T& root,
const CharType(&source)[N], T2 defaultValue,
typename T::AllocatorType& a) {
1150 template <
typename DocumentType>
1152 return pointer.GetWithDefault(document, defaultValue);
1155 template <
typename DocumentType>
1157 return pointer.GetWithDefault(document, defaultValue);
1160 #if RAPIDJSON_HAS_STDSTRING
1161 template <
typename DocumentType>
1163 return pointer.GetWithDefault(document, defaultValue);
1167 template <
typename DocumentType,
typename T2>
1168 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>,
internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1170 return pointer.GetWithDefault(document, defaultValue);
1173 template <
typename DocumentType,
typename CharType,
size_t N>
1174 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::ValueType& defaultValue) {
1178 template <
typename DocumentType,
typename CharType,
size_t N>
1179 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::Ch* defaultValue) {
1183 #if RAPIDJSON_HAS_STDSTRING
1184 template <
typename DocumentType,
typename CharType,
size_t N>
1185 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N],
const std::basic_string<typename DocumentType::Ch>& defaultValue) {
1190 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1191 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>,
internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1192 GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N], T2 defaultValue) {
1198 template <
typename T>
1200 return pointer.Set(root, value, a);
1203 template <
typename T>
1205 return pointer.Set(root, value, a);
1208 template <
typename T>
1210 return pointer.Set(root, value, a);
1213 #if RAPIDJSON_HAS_STDSTRING
1214 template <
typename T>
1215 typename T::ValueType& SetValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const std::basic_string<typename T::Ch>& value,
typename T::AllocatorType& a) {
1216 return pointer.Set(root, value, a);
1220 template <
typename T,
typename T2>
1223 return pointer.Set(root, value, a);
1226 template <
typename T,
typename CharType,
size_t N>
1227 typename T::ValueType& SetValueByPointer(T& root,
const CharType(&source)[N],
typename T::ValueType& value,
typename T::AllocatorType& a) {
1231 template <
typename T,
typename CharType,
size_t N>
1232 typename T::ValueType& SetValueByPointer(T& root,
const CharType(&source)[N],
const typename T::ValueType& value,
typename T::AllocatorType& a) {
1236 template <
typename T,
typename CharType,
size_t N>
1237 typename T::ValueType& SetValueByPointer(T& root,
const CharType(&source)[N],
const typename T::Ch* value,
typename T::AllocatorType& a) {
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>
1250 SetValueByPointer(T& root,
const CharType(&source)[N], T2 value,
typename T::AllocatorType& a) {
1256 template <
typename DocumentType>
1258 return pointer.Set(document, value);
1261 template <
typename DocumentType>
1263 return pointer.Set(document, value);
1266 template <
typename DocumentType>
1268 return pointer.Set(document, value);
1271 #if RAPIDJSON_HAS_STDSTRING
1272 template <
typename DocumentType>
1274 return pointer.Set(document, value);
1278 template <
typename DocumentType,
typename T2>
1279 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>,
internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1281 return pointer.Set(document, value);
1284 template <
typename DocumentType,
typename CharType,
size_t N>
1285 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const CharType(&source)[N],
typename DocumentType::ValueType& value) {
1289 template <
typename DocumentType,
typename CharType,
size_t N>
1290 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::ValueType& value) {
1294 template <
typename DocumentType,
typename CharType,
size_t N>
1295 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::Ch* value) {
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>
1307 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>,
internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1308 SetValueByPointer(DocumentType& document,
const CharType(&source)[N], T2 value) {
1314 template <
typename T>
1316 return pointer.Swap(root, value, a);
1319 template <
typename T,
typename CharType,
size_t N>
1320 typename T::ValueType& SwapValueByPointer(T& root,
const CharType(&source)[N],
typename T::ValueType& value,
typename T::AllocatorType& a) {
1324 template <
typename DocumentType>
1326 return pointer.Swap(document, value);
1329 template <
typename DocumentType,
typename CharType,
size_t N>
1330 typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document,
const CharType(&source)[N],
typename DocumentType::ValueType& value) {
1336 template <
typename T>
1338 return pointer.Erase(root);
1341 template <
typename T,
typename CharType,
size_t N>
1342 bool EraseValueByPointer(T& root,
const CharType(&source)[N]) {
A document for parsing JSON text as DOM.
Definition: document.h:2024
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2308
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: pointer.h:81
GenericPointer(const GenericPointer &rhs, Allocator *allocator=0)
Copy constructor.
Definition: pointer.h:168
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) Set(GenericDocument< EncodingType
Set a primitive value in a document.
GenericPointer & operator=(const GenericPointer &rhs)
Assignment operator.
Definition: pointer.h:180
ValueType & Set(ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const
Set a null-terminated string in a subtree.
Definition: pointer.h:620
ValueType & Swap(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Swap a value with a value in a subtree.
Definition: pointer.h:692
GenericPointer(const Ch *source, Allocator *allocator=0)
Constructor that parses a string or URI fragment representation.
Definition: pointer.h:116
ValueType::EncodingType EncodingType
Encoding type from Value.
Definition: pointer.h:83
GenericPointer(const Token *tokens, size_t tokenCount)
Constructor with user-supplied tokens.
Definition: pointer.h:165
GenericPointer(Allocator *allocator=0)
Default constructor.
Definition: pointer.h:109
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 Erase(ValueType &root) const
Erase a value in a subtree.
Definition: pointer.h:711
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
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) Set(ValueType &root
Set a primitive value in a subtree.
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
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
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
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Append a token and return a new Pointer.
Definition: pointer.h:211
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.
ValueType::Ch Ch
Character type from Value.
Definition: pointer.h:84
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
~GenericPointer()
Destructor.
Definition: pointer.h:173
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
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:540
Concept for allocating, resizing and freeing memory block.
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:402
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
PointerParseErrorCode
Error code of parsing.
Definition: pointer.h:39
@ kPointerParseErrorInvalidEscape
Invalid escape.
Definition: pointer.h:43
@ kPointerParseErrorTokenMustBeginWithSolidus
A token must begin with a '/'.
Definition: pointer.h:42
@ kPointerParseErrorNone
The parse is successful.
Definition: pointer.h:40
@ kPointerParseErrorCharacterMustPercentEncode
A character must percent encoded in URI fragment.
Definition: pointer.h:45
@ kPointerParseErrorInvalidPercentEncoding
Invalid percent encoding in URI fragment.
Definition: pointer.h:44
Type
Type of JSON value.
Definition: rapidjson.h:603
@ kObjectType
object
Definition: rapidjson.h:607
@ kArrayType
array
Definition: rapidjson.h:608
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:590
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:380
#define RAPIDJSON_NEW(x)
! customization point for global new
Definition: rapidjson.h:586
A read-write string stream.
Definition: stream.h:144
A token is the basic units of internal representation.
Definition: pointer.h:99
SizeType index
A valid array index, if it is not equal to kPointerInvalidIndex.
Definition: pointer.h:102
SizeType length
Length of the name.
Definition: pointer.h:101
const Ch * name
Name of the token. It has null character at the end but it can contain null character.
Definition: pointer.h:100
Reference to a constant string (not taking a copy)
Definition: document.h:249
Read-only string stream.
Definition: stream.h:110
Encoding conversion.
Definition: encodings.h:658
UTF-8 encoding.
Definition: encodings.h:96
Definition: document.h:401