15 #ifndef RAPIDJSON_POINTER_H_
16 #define RAPIDJSON_POINTER_H_
19 #include "internal/itoa.h"
23 RAPIDJSON_DIAG_OFF(
switch-
enum)
24 #elif defined(_MSC_VER)
26 RAPIDJSON_DIAG_OFF(4512)
29 RAPIDJSON_NAMESPACE_BEGIN
78 template <
typename ValueType,
typename Allocator = CrtAllocator>
79 class GenericPointer {
82 typedef typename ValueType::Ch
Ch;
115 Parse(source, internal::StrLen(source));
118 #if RAPIDJSON_HAS_STDSTRING
126 Parse(source.c_str(), source.size());
138 Parse(source, length);
178 Allocator::Free(tokens_);
187 Allocator::Free(tokens_);
189 tokenCount_ = rhs.tokenCount_;
190 parseErrorOffset_ = rhs.parseErrorOffset_;
191 parseErrorCode_ = rhs.parseErrorCode_;
196 tokens_ = rhs.tokens_;
209 internal::Swap(allocator_, other.allocator_);
210 internal::Swap(ownAllocator_, other.ownAllocator_);
211 internal::Swap(nameBuffer_, other.nameBuffer_);
212 internal::Swap(tokens_, other.tokens_);
213 internal::Swap(tokenCount_, other.tokenCount_);
214 internal::Swap(parseErrorOffset_, other.parseErrorOffset_);
215 internal::Swap(parseErrorCode_, other.parseErrorCode_);
246 r.allocator_ = allocator;
247 Ch *p = r.CopyFromRaw(*
this, 1, token.
length + 1);
248 std::memcpy(p, token.
name, (token.
length + 1) *
sizeof(
Ch));
249 r.tokens_[tokenCount_].name = p;
250 r.tokens_[tokenCount_].length = token.
length;
251 r.tokens_[tokenCount_].index = token.
index;
263 Token token = { name, length, kPointerInvalidIndex };
264 return Append(token, allocator);
273 template <
typename T>
275 Append(T* name,
Allocator* allocator = 0)
const {
276 return Append(name, internal::StrLen(name), allocator);
279 #if RAPIDJSON_HAS_STDSTRING
286 GenericPointer Append(
const std::basic_string<Ch>& name,
Allocator* allocator = 0)
const {
287 return Append(name.c_str(), static_cast<SizeType>(name.size()), allocator);
299 char* end =
sizeof(
SizeType) == 4 ? internal::u32toa(index, buffer) : internal::u64toa(index, buffer);
300 SizeType length = static_cast<SizeType>(end - buffer);
301 buffer[length] =
'\0';
303 if (
sizeof(Ch) == 1) {
304 Token token = { reinterpret_cast<Ch*>(buffer), length, index };
305 return Append(token, allocator);
309 for (
size_t i = 0; i <= length; i++)
310 name[i] = static_cast<Ch>(buffer[i]);
311 Token token = { name, length, index };
312 return Append(token, allocator);
322 GenericPointer Append(
const ValueType& token,
Allocator* allocator = 0)
const {
323 if (token.IsString())
324 return Append(token.GetString(), token.GetStringLength(), allocator);
328 return Append(static_cast<SizeType>(token.GetUint64()), allocator);
339 size_t GetParseErrorOffset()
const {
return parseErrorOffset_; }
347 Allocator& GetAllocator() {
return *allocator_; }
353 const Token* GetTokens()
const {
return tokens_; }
356 size_t GetTokenCount()
const {
return tokenCount_; }
367 bool operator==(
const GenericPointer& rhs)
const {
368 if (!IsValid() || !rhs.IsValid() || tokenCount_ != rhs.tokenCount_)
371 for (
size_t i = 0; i < tokenCount_; i++) {
372 if (tokens_[i].index != rhs.tokens_[i].index ||
373 tokens_[i].length != rhs.tokens_[i].length ||
374 (tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].name,
sizeof(Ch)* tokens_[i].length) != 0))
387 bool operator!=(
const GenericPointer& rhs)
const {
return !(*
this == rhs); }
393 bool operator<(
const GenericPointer& rhs)
const {
399 if (tokenCount_ != rhs.tokenCount_)
400 return tokenCount_ < rhs.tokenCount_;
402 for (
size_t i = 0; i < tokenCount_; i++) {
403 if (tokens_[i].index != rhs.tokens_[i].index)
404 return tokens_[i].index < rhs.tokens_[i].index;
406 if (tokens_[i].length != rhs.tokens_[i].length)
407 return tokens_[i].length < rhs.tokens_[i].length;
409 if (
int cmp = std::memcmp(tokens_[i].name, rhs.tokens_[i].name,
sizeof(Ch) * tokens_[i].length))
426 template<
typename OutputStream>
427 bool Stringify(OutputStream& os)
const {
428 return Stringify<false, OutputStream>(os);
436 template<
typename OutputStream>
437 bool StringifyUriFragment(OutputStream& os)
const {
438 return Stringify<true, OutputStream>(os);
461 ValueType& Create(ValueType& root,
typename ValueType::AllocatorType& allocator,
bool* alreadyExist = 0)
const {
463 ValueType* v = &root;
465 for (
const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
466 if (v->IsArray() && t->name[0] ==
'-' && t->length == 1) {
467 v->PushBack(ValueType().Move(), allocator);
468 v = &((*v)[v->Size() - 1]);
472 if (t->index == kPointerInvalidIndex) {
477 if (!v->IsArray() && !v->IsObject())
482 if (t->index >= v->Size()) {
483 v->Reserve(t->index + 1, allocator);
484 while (t->index >= v->Size())
485 v->PushBack(ValueType().Move(), allocator);
488 v = &((*v)[t->index]);
491 typename ValueType::MemberIterator m = v->FindMember(GenericValue<EncodingType>(GenericStringRef<Ch>(t->name, t->length)));
492 if (m == v->MemberEnd()) {
493 v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator);
505 *alreadyExist = exist;
516 template <
typename stackAllocator>
517 ValueType& Create(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document,
bool* alreadyExist = 0)
const {
518 return Create(document, document.GetAllocator(), alreadyExist);
540 ValueType* Get(ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
542 ValueType* v = &root;
543 for (
const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
544 switch (v->GetType()) {
547 typename ValueType::MemberIterator m = v->FindMember(GenericValue<EncodingType>(GenericStringRef<Ch>(t->name, t->length)));
548 if (m == v->MemberEnd())
554 if (t->index == kPointerInvalidIndex || t->index >= v->Size())
556 v = &((*v)[t->index]);
563 if (unresolvedTokenIndex)
564 *unresolvedTokenIndex = static_cast<size_t>(t - tokens_);
575 const ValueType* Get(
const ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
576 return Get(const_cast<ValueType&>(root), unresolvedTokenIndex);
594 ValueType& GetWithDefault(ValueType& root,
const ValueType& defaultValue,
typename ValueType::AllocatorType& allocator)
const {
596 ValueType& v = Create(root, allocator, &alreadyExist);
597 return alreadyExist ? v : v.CopyFrom(defaultValue, allocator);
601 ValueType& GetWithDefault(ValueType& root,
const Ch* defaultValue,
typename ValueType::AllocatorType& allocator)
const {
603 ValueType& v = Create(root, allocator, &alreadyExist);
604 return alreadyExist ? v : v.SetString(defaultValue, allocator);
607 #if RAPIDJSON_HAS_STDSTRING
609 ValueType& GetWithDefault(ValueType& root,
const std::basic_string<Ch>& defaultValue,
typename ValueType::AllocatorType& allocator)
const {
611 ValueType& v = Create(root, allocator, &alreadyExist);
612 return alreadyExist ? v : v.SetString(defaultValue, allocator);
620 template <
typename T>
621 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
622 GetWithDefault(ValueType& root, T defaultValue,
typename ValueType::AllocatorType& allocator)
const {
623 return GetWithDefault(root, ValueType(defaultValue).Move(), allocator);
627 template <
typename stackAllocator>
628 ValueType& GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document,
const ValueType& defaultValue)
const {
629 return GetWithDefault(document, defaultValue, document.GetAllocator());
633 template <
typename stackAllocator>
634 ValueType& GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document,
const Ch* defaultValue)
const {
635 return GetWithDefault(document, defaultValue, document.GetAllocator());
638 #if RAPIDJSON_HAS_STDSTRING
640 template <
typename stackAllocator>
641 ValueType& GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document,
const std::basic_string<Ch>& defaultValue)
const {
642 return GetWithDefault(document, defaultValue, document.GetAllocator());
650 template <
typename T,
typename stackAllocator>
651 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
652 GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, T defaultValue)
const {
653 return GetWithDefault(document, defaultValue, document.GetAllocator());
671 ValueType& Set(ValueType& root, ValueType& value,
typename ValueType::AllocatorType& allocator)
const {
672 return Create(root, allocator) = value;
676 ValueType& Set(ValueType& root,
const ValueType& value,
typename ValueType::AllocatorType& allocator)
const {
677 return Create(root, allocator).CopyFrom(value, allocator);
681 ValueType& Set(ValueType& root,
const Ch* value,
typename ValueType::AllocatorType& allocator)
const {
682 return Create(root, allocator) = ValueType(value, allocator).Move();
685 #if RAPIDJSON_HAS_STDSTRING
687 ValueType& Set(ValueType& root,
const std::basic_string<Ch>& value,
typename ValueType::AllocatorType& allocator)
const {
688 return Create(root, allocator) = ValueType(value, allocator).Move();
696 template <
typename T>
697 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
698 Set(ValueType& root, T value,
typename ValueType::AllocatorType& allocator)
const {
699 return Create(root, allocator) = ValueType(value).Move();
703 template <
typename stackAllocator>
704 ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, ValueType& value)
const {
705 return Create(document) = value;
709 template <
typename stackAllocator>
710 ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document,
const ValueType& value)
const {
711 return Create(document).CopyFrom(value, document.GetAllocator());
715 template <
typename stackAllocator>
716 ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document,
const Ch* value)
const {
717 return Create(document) = ValueType(value, document.GetAllocator()).Move();
720 #if RAPIDJSON_HAS_STDSTRING
722 template <
typename stackAllocator>
723 ValueType& Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document,
const std::basic_string<Ch>& value)
const {
724 return Create(document) = ValueType(value, document.GetAllocator()).Move();
732 template <
typename T,
typename stackAllocator>
733 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
734 Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, T value)
const {
735 return Create(document) = value;
753 ValueType& Swap(ValueType& root, ValueType& value,
typename ValueType::AllocatorType& allocator)
const {
754 return Create(root, allocator).Swap(value);
758 template <
typename stackAllocator>
759 ValueType& Swap(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, ValueType& value)
const {
760 return Create(document).Swap(value);
772 bool Erase(ValueType& root)
const {
774 if (tokenCount_ == 0)
777 ValueType* v = &root;
778 const Token* last = tokens_ + (tokenCount_ - 1);
779 for (
const Token *t = tokens_; t != last; ++t) {
780 switch (v->GetType()) {
783 typename ValueType::MemberIterator m = v->FindMember(GenericValue<EncodingType>(GenericStringRef<Ch>(t->name, t->length)));
784 if (m == v->MemberEnd())
790 if (t->index == kPointerInvalidIndex || t->index >= v->Size())
792 v = &((*v)[t->index]);
799 switch (v->GetType()) {
801 return v->EraseMember(GenericStringRef<Ch>(last->name, last->length));
803 if (last->index == kPointerInvalidIndex || last->index >= v->Size())
805 v->Erase(v->Begin() + last->index);
820 Ch* CopyFromRaw(
const GenericPointer& rhs,
size_t extraToken = 0,
size_t extraNameBufferSize = 0) {
824 size_t nameBufferSize = rhs.tokenCount_;
825 for (Token *t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t)
826 nameBufferSize += t->length;
828 tokenCount_ = rhs.tokenCount_ + extraToken;
829 tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ *
sizeof(Token) + (nameBufferSize + extraNameBufferSize) *
sizeof(Ch)));
830 nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
831 if (rhs.tokenCount_ > 0) {
832 std::memcpy(tokens_, rhs.tokens_, rhs.tokenCount_ *
sizeof(Token));
834 if (nameBufferSize > 0) {
835 std::memcpy(nameBuffer_, rhs.nameBuffer_, nameBufferSize *
sizeof(Ch));
839 std::ptrdiff_t diff = nameBuffer_ - rhs.nameBuffer_;
840 for (Token *t = tokens_; t != tokens_ + rhs.tokenCount_; ++t)
843 return nameBuffer_ + nameBufferSize;
851 bool NeedPercentEncode(Ch c)
const {
852 return !((c >=
'0' && c <=
'9') || (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z') || c ==
'-' || c ==
'.' || c ==
'_' || c ==
'~');
856 #ifndef __clang__ // -Wdocumentation
863 void Parse(
const Ch* source,
size_t length) {
874 for (
const Ch* s = source; s != source + length; s++)
878 Token* token = tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ *
sizeof(Token) + length *
sizeof(Ch)));
879 Ch* name = nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
883 bool uriFragment =
false;
884 if (source[i] ==
'#') {
889 if (i != length && source[i] !=
'/') {
899 bool isNumber =
true;
901 while (i < length && source[i] !=
'/') {
906 PercentDecodeStream is(&source[i], source + length);
907 GenericInsituStringStream<EncodingType> os(name);
908 Ch* begin = os.PutBegin();
909 if (!Transcoder<UTF8<>, EncodingType>().Validate(is, os) || !is.IsValid()) {
913 size_t len = os.PutEnd(begin);
924 else if (NeedPercentEncode(c)) {
936 if (c ==
'0') c =
'~';
937 else if (c ==
'1') c =
'/';
951 if (c < '0' || c >
'9')
956 token->length = static_cast<SizeType>(name - token->name);
957 if (token->length == 0)
962 if (isNumber && token->length > 1 && token->name[0] ==
'0')
968 for (
size_t j = 0; j < token->length; j++) {
969 SizeType m = n * 10 + static_cast<SizeType>(token->name[j] -
'0');
978 token->index = isNumber ? n : kPointerInvalidIndex;
987 Allocator::Free(tokens_);
991 parseErrorOffset_ = i;
1001 template<
bool uriFragment,
typename OutputStream>
1002 bool Stringify(OutputStream& os)
const {
1008 for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
1010 for (
size_t j = 0; j < t->length; j++) {
1016 else if (c ==
'/') {
1020 else if (uriFragment && NeedPercentEncode(c)) {
1022 GenericStringStream<typename ValueType::EncodingType> source(&t->name[j]);
1023 PercentEncodeStream<OutputStream> target(os);
1024 if (!Transcoder<EncodingType, UTF8<> >().Validate(source, target))
1026 j += source.Tell() - 1;
1041 class PercentDecodeStream {
1043 typedef typename ValueType::Ch Ch;
1050 PercentDecodeStream(
const Ch* source,
const Ch* end) : src_(source), head_(source), end_(end), valid_(true) {}
1053 if (*src_ !=
'%' || src_ + 3 > end_) {
1059 for (
int j = 0; j < 2; j++) {
1060 c = static_cast<Ch>(c << 4);
1062 if (h >=
'0' && h <=
'9') c = static_cast<Ch>(c + h -
'0');
1063 else if (h >=
'A' && h <=
'F') c = static_cast<Ch>(c + h -
'A' + 10);
1064 else if (h >=
'a' && h <=
'f') c = static_cast<Ch>(c + h -
'a' + 10);
1074 size_t Tell()
const {
return static_cast<size_t>(src_ - head_); }
1075 bool IsValid()
const {
return valid_; }
1085 template <
typename OutputStream>
1090 unsigned char u = static_cast<unsigned char>(c);
1091 static const char hexDigits[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
1093 os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u >> 4]));
1094 os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u & 15]));
1117 template <
typename T>
1119 return pointer.Create(root, a);
1122 template <
typename T,
typename CharType,
size_t N>
1123 typename T::ValueType& CreateValueByPointer(T& root,
const CharType(&source)[N],
typename T::AllocatorType& a) {
1124 return GenericPointer<typename T::ValueType>(source, N - 1).Create(root, a);
1129 template <
typename DocumentType>
1130 typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer) {
1131 return pointer.Create(document);
1134 template <
typename DocumentType,
typename CharType,
size_t N>
1135 typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document,
const CharType(&source)[N]) {
1136 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Create(document);
1141 template <
typename T>
1142 typename T::ValueType* GetValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer,
size_t* unresolvedTokenIndex = 0) {
1143 return pointer.Get(root, unresolvedTokenIndex);
1146 template <
typename T>
1147 const typename T::ValueType* GetValueByPointer(
const T& root,
const GenericPointer<typename T::ValueType>& pointer,
size_t* unresolvedTokenIndex = 0) {
1148 return pointer.Get(root, unresolvedTokenIndex);
1151 template <
typename T,
typename CharType,
size_t N>
1152 typename T::ValueType* GetValueByPointer(T& root,
const CharType (&source)[N],
size_t* unresolvedTokenIndex = 0) {
1153 return GenericPointer<typename T::ValueType>(source, N - 1).Get(root, unresolvedTokenIndex);
1156 template <
typename T,
typename CharType,
size_t N>
1157 const typename T::ValueType* GetValueByPointer(
const T& root,
const CharType(&source)[N],
size_t* unresolvedTokenIndex = 0) {
1158 return GenericPointer<typename T::ValueType>(source, N - 1).Get(root, unresolvedTokenIndex);
1163 template <
typename T>
1164 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const typename T::ValueType& defaultValue,
typename T::AllocatorType& a) {
1165 return pointer.GetWithDefault(root, defaultValue, a);
1168 template <
typename T>
1169 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const typename T::Ch* defaultValue,
typename T::AllocatorType& a) {
1170 return pointer.GetWithDefault(root, defaultValue, a);
1173 #if RAPIDJSON_HAS_STDSTRING
1174 template <
typename T>
1175 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const std::basic_string<typename T::Ch>& defaultValue,
typename T::AllocatorType& a) {
1176 return pointer.GetWithDefault(root, defaultValue, a);
1180 template <
typename T,
typename T2>
1181 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename T::ValueType&))
1182 GetValueByPointerWithDefault(T& root,
const GenericPointer<typename T::ValueType>& pointer, T2 defaultValue,
typename T::AllocatorType& a) {
1183 return pointer.GetWithDefault(root, defaultValue, a);
1186 template <
typename T,
typename CharType,
size_t N>
1187 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const CharType(&source)[N],
const typename T::ValueType& defaultValue,
typename T::AllocatorType& a) {
1188 return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
1191 template <
typename T,
typename CharType,
size_t N>
1192 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const CharType(&source)[N],
const typename T::Ch* defaultValue,
typename T::AllocatorType& a) {
1193 return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
1196 #if RAPIDJSON_HAS_STDSTRING
1197 template <
typename T,
typename CharType,
size_t N>
1198 typename T::ValueType& GetValueByPointerWithDefault(T& root,
const CharType(&source)[N],
const std::basic_string<typename T::Ch>& defaultValue,
typename T::AllocatorType& a) {
1199 return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
1203 template <
typename T,
typename CharType,
size_t N,
typename T2>
1204 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename T::ValueType&))
1205 GetValueByPointerWithDefault(T& root,
const CharType(&source)[N], T2 defaultValue,
typename T::AllocatorType& a) {
1206 return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
1211 template <
typename DocumentType>
1212 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
const typename DocumentType::ValueType& defaultValue) {
1213 return pointer.GetWithDefault(document, defaultValue);
1216 template <
typename DocumentType>
1217 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
const typename DocumentType::Ch* defaultValue) {
1218 return pointer.GetWithDefault(document, defaultValue);
1221 #if RAPIDJSON_HAS_STDSTRING
1222 template <
typename DocumentType>
1223 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
const std::basic_string<typename DocumentType::Ch>& defaultValue) {
1224 return pointer.GetWithDefault(document, defaultValue);
1228 template <
typename DocumentType,
typename T2>
1229 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1230 GetValueByPointerWithDefault(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer, T2 defaultValue) {
1231 return pointer.GetWithDefault(document, defaultValue);
1234 template <
typename DocumentType,
typename CharType,
size_t N>
1235 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::ValueType& defaultValue) {
1236 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
1239 template <
typename DocumentType,
typename CharType,
size_t N>
1240 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::Ch* defaultValue) {
1241 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
1244 #if RAPIDJSON_HAS_STDSTRING
1245 template <
typename DocumentType,
typename CharType,
size_t N>
1246 typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N],
const std::basic_string<typename DocumentType::Ch>& defaultValue) {
1247 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
1251 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1252 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1253 GetValueByPointerWithDefault(DocumentType& document,
const CharType(&source)[N], T2 defaultValue) {
1254 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
1259 template <
typename T>
1260 typename T::ValueType& SetValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer,
typename T::ValueType& value,
typename T::AllocatorType& a) {
1261 return pointer.Set(root, value, a);
1264 template <
typename T>
1265 typename T::ValueType& SetValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const typename T::ValueType& value,
typename T::AllocatorType& a) {
1266 return pointer.Set(root, value, a);
1269 template <
typename T>
1270 typename T::ValueType& SetValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const typename T::Ch* value,
typename T::AllocatorType& a) {
1271 return pointer.Set(root, value, a);
1274 #if RAPIDJSON_HAS_STDSTRING
1275 template <
typename T>
1276 typename T::ValueType& SetValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer,
const std::basic_string<typename T::Ch>& value,
typename T::AllocatorType& a) {
1277 return pointer.Set(root, value, a);
1281 template <
typename T,
typename T2>
1282 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename T::ValueType&))
1283 SetValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer, T2 value,
typename T::AllocatorType& a) {
1284 return pointer.Set(root, value, a);
1287 template <
typename T,
typename CharType,
size_t N>
1288 typename T::ValueType& SetValueByPointer(T& root,
const CharType(&source)[N],
typename T::ValueType& value,
typename T::AllocatorType& a) {
1289 return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
1292 template <
typename T,
typename CharType,
size_t N>
1293 typename T::ValueType& SetValueByPointer(T& root,
const CharType(&source)[N],
const typename T::ValueType& value,
typename T::AllocatorType& a) {
1294 return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
1297 template <
typename T,
typename CharType,
size_t N>
1298 typename T::ValueType& SetValueByPointer(T& root,
const CharType(&source)[N],
const typename T::Ch* value,
typename T::AllocatorType& a) {
1299 return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
1302 #if RAPIDJSON_HAS_STDSTRING
1303 template <
typename T,
typename CharType,
size_t N>
1304 typename T::ValueType& SetValueByPointer(T& root,
const CharType(&source)[N],
const std::basic_string<typename T::Ch>& value,
typename T::AllocatorType& a) {
1305 return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
1309 template <
typename T,
typename CharType,
size_t N,
typename T2>
1310 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename T::ValueType&))
1311 SetValueByPointer(T& root,
const CharType(&source)[N], T2 value,
typename T::AllocatorType& a) {
1312 return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
1317 template <
typename DocumentType>
1318 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
typename DocumentType::ValueType& value) {
1319 return pointer.Set(document, value);
1322 template <
typename DocumentType>
1323 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
const typename DocumentType::ValueType& value) {
1324 return pointer.Set(document, value);
1327 template <
typename DocumentType>
1328 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
const typename DocumentType::Ch* value) {
1329 return pointer.Set(document, value);
1332 #if RAPIDJSON_HAS_STDSTRING
1333 template <
typename DocumentType>
1334 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
const std::basic_string<typename DocumentType::Ch>& value) {
1335 return pointer.Set(document, value);
1339 template <
typename DocumentType,
typename T2>
1340 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1341 SetValueByPointer(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer, T2 value) {
1342 return pointer.Set(document, value);
1345 template <
typename DocumentType,
typename CharType,
size_t N>
1346 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const CharType(&source)[N],
typename DocumentType::ValueType& value) {
1347 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
1350 template <
typename DocumentType,
typename CharType,
size_t N>
1351 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::ValueType& value) {
1352 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
1355 template <
typename DocumentType,
typename CharType,
size_t N>
1356 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const CharType(&source)[N],
const typename DocumentType::Ch* value) {
1357 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
1360 #if RAPIDJSON_HAS_STDSTRING
1361 template <
typename DocumentType,
typename CharType,
size_t N>
1362 typename DocumentType::ValueType& SetValueByPointer(DocumentType& document,
const CharType(&source)[N],
const std::basic_string<typename DocumentType::Ch>& value) {
1363 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
1367 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1368 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (
typename DocumentType::ValueType&))
1369 SetValueByPointer(DocumentType& document,
const CharType(&source)[N], T2 value) {
1370 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
1375 template <
typename T>
1376 typename T::ValueType& SwapValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer,
typename T::ValueType& value,
typename T::AllocatorType& a) {
1377 return pointer.Swap(root, value, a);
1380 template <
typename T,
typename CharType,
size_t N>
1381 typename T::ValueType& SwapValueByPointer(T& root,
const CharType(&source)[N],
typename T::ValueType& value,
typename T::AllocatorType& a) {
1382 return GenericPointer<typename T::ValueType>(source, N - 1).Swap(root, value, a);
1385 template <
typename DocumentType>
1386 typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document,
const GenericPointer<typename DocumentType::ValueType>& pointer,
typename DocumentType::ValueType& value) {
1387 return pointer.Swap(document, value);
1390 template <
typename DocumentType,
typename CharType,
size_t N>
1391 typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document,
const CharType(&source)[N],
typename DocumentType::ValueType& value) {
1392 return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Swap(document, value);
1397 template <
typename T>
1398 bool EraseValueByPointer(T& root,
const GenericPointer<typename T::ValueType>& pointer) {
1399 return pointer.Erase(root);
1402 template <
typename T,
typename CharType,
size_t N>
1403 bool EraseValueByPointer(T& root,
const CharType(&source)[N]) {
1404 return GenericPointer<typename T::ValueType>(source, N - 1).Erase(root);
1409 RAPIDJSON_NAMESPACE_END
1411 #if defined(__clang__) || defined(_MSC_VER)
1415 #endif // RAPIDJSON_POINTER_H_