15 #ifndef RAPIDJSON_POINTER_H_ 16 #define RAPIDJSON_POINTER_H_ 23 RAPIDJSON_DIAG_OFF(
switch-
enum)
24 #elif defined(_MSC_VER) 26 RAPIDJSON_DIAG_OFF(4512)
78 template <
typename ValueType,
typename Allocator = CrtAllocator>
82 typedef typename ValueType::Ch
Ch;
118 #if RAPIDJSON_HAS_STDSTRING 126 Parse(source.c_str(), source.size());
138 Parse(source, length);
218 std::memcpy(p, token.
name, (token.
length + 1) *
sizeof(Ch));
243 template <
typename T>
249 #if RAPIDJSON_HAS_STDSTRING 273 if (
sizeof(
Ch) == 1) {
274 Token token = {
reinterpret_cast<Ch*
>(buffer), length, index };
279 for (
size_t i = 0; i <=
length; i++)
280 name[i] = static_cast<Ch>(buffer[i]);
293 if (token.IsString())
317 Allocator& GetAllocator() {
return *
allocator_; }
326 size_t GetTokenCount()
const {
return tokenCount_; }
369 template<
typename OutputStream>
371 return Stringify<false, OutputStream>(os);
379 template<
typename OutputStream>
380 bool StringifyUriFragment(OutputStream& os)
const {
381 return Stringify<true, OutputStream>(os);
404 ValueType& Create(ValueType& root,
typename ValueType::AllocatorType&
allocator,
bool* alreadyExist = 0)
const {
406 ValueType* v = &root;
409 if (v->IsArray() &&
t->name[0] ==
'-' &&
t->length == 1) {
410 v->PushBack(ValueType().Move(), allocator);
411 v = &((*v)[v->Size() - 1]);
415 if (
t->index == kPointerInvalidIndex) {
420 if (!v->IsArray() && !v->IsObject())
425 if (
t->index >= v->Size()) {
426 v->Reserve(
t->index + 1, allocator);
427 while (
t->index >= v->Size())
428 v->PushBack(ValueType().Move(), allocator);
431 v = &((*v)[
t->index]);
435 if (m == v->MemberEnd()) {
436 v->AddMember(ValueType(
t->name,
t->length, allocator).Move(), ValueType().Move(),
allocator);
437 v = &(--v->MemberEnd())->
value;
447 *alreadyExist = exist;
458 template <
typename stackAllocator>
460 return Create(document, document.
GetAllocator(), alreadyExist);
482 ValueType* Get(ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
484 ValueType* v = &root;
486 switch (v->GetType()) {
490 if (m == v->MemberEnd())
496 if (
t->index == kPointerInvalidIndex ||
t->index >= v->Size())
498 v = &((*v)[
t->index]);
505 if (unresolvedTokenIndex)
506 *unresolvedTokenIndex =
static_cast<size_t>(
t -
tokens_);
517 const ValueType* Get(
const ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
518 return Get(const_cast<ValueType&>(root), unresolvedTokenIndex);
536 ValueType& GetWithDefault(ValueType& root,
const ValueType&
defaultValue,
typename ValueType::AllocatorType& allocator)
const {
538 ValueType& v = Create(root, allocator, &alreadyExist);
539 return alreadyExist ? v : v.CopyFrom(defaultValue, allocator);
543 ValueType& GetWithDefault(ValueType& root,
const Ch* defaultValue,
typename ValueType::AllocatorType& allocator)
const {
545 ValueType& v = Create(root, allocator, &alreadyExist);
546 return alreadyExist ? v : v.SetString(defaultValue, allocator);
549 #if RAPIDJSON_HAS_STDSTRING 551 ValueType& GetWithDefault(ValueType& root,
const std::basic_string<Ch>& defaultValue,
typename ValueType::AllocatorType& allocator)
const {
553 ValueType& v = Create(root, allocator, &alreadyExist);
554 return alreadyExist ? v : v.SetString(defaultValue, allocator);
562 template <
typename T>
564 GetWithDefault(ValueType& root,
T defaultValue,
typename ValueType::AllocatorType& allocator)
const {
565 return GetWithDefault(root, ValueType(defaultValue).Move(), allocator);
569 template <
typename stackAllocator>
571 return GetWithDefault(document, defaultValue, document.
GetAllocator());
575 template <
typename stackAllocator>
577 return GetWithDefault(document, defaultValue, document.
GetAllocator());
580 #if RAPIDJSON_HAS_STDSTRING 582 template <
typename stackAllocator>
584 return GetWithDefault(document, defaultValue, document.
GetAllocator());
592 template <
typename T,
typename stackAllocator>
595 return GetWithDefault(document, defaultValue, document.GetAllocator());
613 ValueType&
Set(ValueType& root, ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
614 return Create(root, allocator) =
value;
618 ValueType&
Set(ValueType& root,
const ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
619 return Create(root, allocator).CopyFrom(value, allocator);
624 return Create(root, allocator) = ValueType(value, allocator).Move();
627 #if RAPIDJSON_HAS_STDSTRING 629 ValueType&
Set(ValueType& root,
const std::basic_string<Ch>&
value,
typename ValueType::AllocatorType&
allocator)
const {
630 return Create(root, allocator) = ValueType(value, allocator).Move();
638 template <
typename T>
640 Set(ValueType& root,
T value, typename ValueType::AllocatorType& allocator)
const {
641 return Create(root, allocator) = ValueType(value).Move();
645 template <
typename stackAllocator>
647 return Create(document) =
value;
651 template <
typename stackAllocator>
653 return Create(document).CopyFrom(value, document.
GetAllocator());
657 template <
typename stackAllocator>
659 return Create(document) = ValueType(value, document.
GetAllocator()).Move();
662 #if RAPIDJSON_HAS_STDSTRING 664 template <
typename stackAllocator>
666 return Create(document) = ValueType(value, document.
GetAllocator()).Move();
674 template <
typename T,
typename stackAllocator>
677 return Create(document) =
value;
695 ValueType&
Swap(ValueType& root, ValueType& value,
typename ValueType::AllocatorType&
allocator)
const {
696 return Create(root, allocator).Swap(value);
700 template <
typename stackAllocator>
702 return Create(document).Swap(value);
719 ValueType* v = &root;
722 switch (v->GetType()) {
726 if (m == v->MemberEnd())
734 v = &((*v)[
t->index]);
741 switch (v->GetType()) {
747 v->Erase(v->Begin() + last->
index);
768 nameBufferSize +=
t->length;
776 if (nameBufferSize > 0) {
794 return !((c >=
'0' && c <= '9') || (c >=
'A' && c <='Z') || (c >=
'a' && c <=
'z') || c ==
'-' || c ==
'.' || c ==
'_' || c ==
'~');
798 #ifndef __clang__ // -Wdocumentation 816 for (
const Ch*
s = source;
s != source +
length;
s++)
825 bool uriFragment =
false;
826 if (source[i] ==
'#') {
831 if (i != length && source[i] !=
'/') {
841 bool isNumber =
true;
843 while (i < length && source[i] !=
'/') {
855 size_t len = os.
PutEnd(begin);
878 if (c ==
'0') c =
'~';
879 else if (c ==
'1') c =
'/';
893 if (c < '0' || c >
'9')
904 if (isNumber && token->
length > 1 && token->
name[0] ==
'0')
910 for (
size_t j = 0; j < token->
length; j++) {
943 template<
bool uriFragment,
typename OutputStream>
952 for (
size_t j = 0; j <
t->length; j++) {
968 j += source.
Tell() - 1;
985 typedef typename ValueType::Ch
Ch;
995 if (*src_ !=
'%' || src_ + 3 > end_) {
1001 for (
int j = 0; j < 2; j++) {
1002 c =
static_cast<Ch
>(c << 4);
1004 if (h >=
'0' && h <=
'9') c =
static_cast<Ch
>(c + h -
'0');
1005 else if (h >=
'A' && h <=
'F') c =
static_cast<Ch
>(c + h -
'A' + 10);
1006 else if (h >=
'a' && h <=
'f') c =
static_cast<Ch
>(c + h -
'a' + 10);
1016 size_t Tell()
const {
return static_cast<size_t>(src_ - head_); }
1027 template <
typename OutputStream>
1032 unsigned char u =
static_cast<unsigned char>(
c);
1033 static const char hexDigits[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
1035 os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u >> 4]));
1036 os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u & 15]));
1059 template <
typename T>
1061 return pointer.Create(root, a);
1064 template <
typename T,
typename CharType,
size_t N>
1071 template <
typename DocumentType>
1073 return pointer.Create(document);
1076 template <
typename DocumentType,
typename CharType,
size_t N>
1083 template <
typename T>
1085 return pointer.Get(root, unresolvedTokenIndex);
1088 template <
typename T>
1090 return pointer.Get(root, unresolvedTokenIndex);
1093 template <
typename T,
typename CharType,
size_t N>
1098 template <
typename T,
typename CharType,
size_t N>
1105 template <
typename T>
1107 return pointer.GetWithDefault(root, defaultValue, a);
1110 template <
typename T>
1112 return pointer.GetWithDefault(root, defaultValue, a);
1115 #if RAPIDJSON_HAS_STDSTRING 1116 template <
typename T>
1118 return pointer.GetWithDefault(root, defaultValue, a);
1122 template <
typename T,
typename T2>
1125 return pointer.GetWithDefault(root, defaultValue, a);
1128 template <
typename T,
typename CharType,
size_t N>
1133 template <
typename T,
typename CharType,
size_t N>
1138 #if RAPIDJSON_HAS_STDSTRING 1139 template <
typename T,
typename CharType,
size_t N>
1145 template <
typename T,
typename CharType,
size_t N,
typename T2>
1153 template <
typename DocumentType>
1155 return pointer.GetWithDefault(document, defaultValue);
1158 template <
typename DocumentType>
1160 return pointer.GetWithDefault(document, defaultValue);
1163 #if RAPIDJSON_HAS_STDSTRING 1164 template <
typename DocumentType>
1166 return pointer.GetWithDefault(document, defaultValue);
1170 template <
typename DocumentType,
typename T2>
1173 return pointer.GetWithDefault(document, defaultValue);
1176 template <
typename DocumentType,
typename CharType,
size_t N>
1181 template <
typename DocumentType,
typename CharType,
size_t N>
1186 #if RAPIDJSON_HAS_STDSTRING 1187 template <
typename DocumentType,
typename CharType,
size_t N>
1188 typename DocumentType::ValueType&
GetValueByPointerWithDefault(DocumentType& document,
const CharType(&
source)[
N],
const std::basic_string<typename DocumentType::Ch>& defaultValue) {
1193 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1201 template <
typename T>
1203 return pointer.
Set(root, value, a);
1206 template <
typename T>
1208 return pointer.
Set(root, value, a);
1211 template <
typename T>
1213 return pointer.
Set(root, value, a);
1216 #if RAPIDJSON_HAS_STDSTRING 1217 template <
typename T>
1219 return pointer.
Set(root, value, a);
1223 template <
typename T,
typename T2>
1226 return pointer.Set(root, value, a);
1229 template <
typename T,
typename CharType,
size_t N>
1234 template <
typename T,
typename CharType,
size_t N>
1235 typename T::ValueType&
SetValueByPointer(
T& root,
const CharType(&
source)[
N],
const typename T::ValueType& value,
typename T::AllocatorType&
a) {
1239 template <
typename T,
typename CharType,
size_t N>
1244 #if RAPIDJSON_HAS_STDSTRING 1245 template <
typename T,
typename CharType,
size_t N>
1246 typename T::ValueType&
SetValueByPointer(
T& root,
const CharType(&
source)[
N],
const std::basic_string<typename T::Ch>& value,
typename T::AllocatorType&
a) {
1251 template <
typename T,
typename CharType,
size_t N,
typename T2>
1259 template <
typename DocumentType>
1261 return pointer.
Set(document, value);
1264 template <
typename DocumentType>
1266 return pointer.
Set(document, value);
1269 template <
typename DocumentType>
1271 return pointer.
Set(document, value);
1274 #if RAPIDJSON_HAS_STDSTRING 1275 template <
typename DocumentType>
1277 return pointer.
Set(document, value);
1281 template <
typename DocumentType,
typename T2>
1284 return pointer.
Set(document, value);
1287 template <
typename DocumentType,
typename CharType,
size_t N>
1288 typename DocumentType::ValueType&
SetValueByPointer(DocumentType& document,
const CharType(&
source)[N],
typename DocumentType::ValueType& value) {
1292 template <
typename DocumentType,
typename CharType,
size_t N>
1293 typename DocumentType::ValueType&
SetValueByPointer(DocumentType& document,
const CharType(&
source)[N],
const typename DocumentType::ValueType& value) {
1297 template <
typename DocumentType,
typename CharType,
size_t N>
1298 typename DocumentType::ValueType&
SetValueByPointer(DocumentType& document,
const CharType(&
source)[N],
const typename DocumentType::Ch* value) {
1302 #if RAPIDJSON_HAS_STDSTRING 1303 template <
typename DocumentType,
typename CharType,
size_t N>
1304 typename DocumentType::ValueType&
SetValueByPointer(DocumentType& document,
const CharType(&
source)[N],
const std::basic_string<typename DocumentType::Ch>& value) {
1309 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1317 template <
typename T>
1319 return pointer.
Swap(root, value, a);
1322 template <
typename T,
typename CharType,
size_t N>
1323 typename T::ValueType&
SwapValueByPointer(
T& root,
const CharType(&
source)[N],
typename T::ValueType& value,
typename T::AllocatorType& a) {
1327 template <
typename DocumentType>
1329 return pointer.
Swap(document, value);
1332 template <
typename DocumentType,
typename CharType,
size_t N>
1333 typename DocumentType::ValueType&
SwapValueByPointer(DocumentType& document,
const CharType(&
source)[N],
typename DocumentType::ValueType& value) {
1339 template <
typename T>
1341 return pointer.
Erase(root);
1344 template <
typename T,
typename CharType,
size_t N>
1353 #if defined(__clang__) || defined(_MSC_VER) 1357 #endif // RAPIDJSON_POINTER_H_ GenericPointer(const Token *tokens, size_t tokenCount)
Constructor with user-supplied tokens.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const ValueType &value) const
Set a value in a document, with copy semantics.
T::ValueType & GetValueByPointerWithDefault(T &root, const GenericPointer< typename T::ValueType > &pointer, const typename T::ValueType &defaultValue, typename T::AllocatorType &a)
char * u64toa(uint64_t value, char *buffer)
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *value) const
Set a null-terminated string in a document.
const CharType(& source)[N]
ValueType & Set(ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const
Set a null-terminated string in a subtree.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
#define RAPIDJSON_ASSERT(x)
Assertion.
void Parse(const Ch *source, size_t length)
Parse a JSON String or its URI fragment representation into tokens.
Ch * CopyFromRaw(const GenericPointer &rhs, size_t extraToken=0, size_t extraNameBufferSize=0)
Clone the content from rhs to this.
Ch * nameBuffer_
A buffer containing all names in tokens.
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
ValueType & Set(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Set a value in a subtree, with move semantics.
ValueType::EncodingType EncodingType
Encoding type from Value.
Invalid percent encoding in URI fragment.
ValueType & Set(ValueType &root, const ValueType &value, typename ValueType::AllocatorType &allocator) const
Set a value in a subtree, with copy semantics.
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...
PointerParseErrorCode parseErrorCode_
Parsing error code.
const Ch * head_
Original head of the string.
PercentDecodeStream(const Ch *source, const Ch *end)
Constructor.
GenericPointer(const GenericPointer &rhs)
Copy constructor.
Token * tokens_
A list of tokens.
static RAPIDJSON_NAMESPACE_BEGIN const SizeType kPointerInvalidIndex
Represents an invalid index in GenericPointer::Token.
GenericPointer Append(const Ch *name, SizeType length, Allocator *allocator=0) const
Append a name token with length, and return a new Pointer.
A helper stream for decoding a percent-encoded sequence into code unit.
SizeType index
A valid array index, if it is not equal to kPointerInvalidIndex.
T::ValueType & SwapValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
A token is the basic units of internal representation.
A document for parsing JSON text as DOM.
A token must begin with a '/'.
A read-write string stream.
SizeType length
Length of the name.
bool valid_
Whether the parsing is valid.
GenericPointer(const Ch *source, Allocator *allocator=0)
Constructor that parses a string or URI fragment representation.
size_t parseErrorOffset_
Offset in code unit when parsing fail.
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
ValueType & Swap(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Swap a value with a value in a subtree.
Allocator stackAllocator stackAllocator & document
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
GenericPointer & operator=(const GenericPointer &rhs)
Assignment operator.
const Ch * end_
Past-the-end position.
A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence.
GenericPointer< Value > Pointer
GenericPointer for Value (UTF-8, default allocator).
PercentEncodeStream(OutputStream &os)
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.
Allocator & GetAllocator()
Get the allocator of this document.
size_t tokenCount_
Number of tokens in tokens_.
#define RAPIDJSON_DELETE(x)
! customization point for global delete
char * u32toa(uint32_t value, char *buffer)
T::ValueType & CreateValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::AllocatorType &a)
GenericPointer(const GenericPointer &rhs, Allocator *allocator)
Copy constructor.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
ValueType::Ch Ch
Character type from Value.
const Ch * name
Name of the token. It has null character at the end but it can contain null character.
PointerParseErrorCode
Error code of parsing.
bool NeedPercentEncode(Ch c) const
Check whether a character should be percent-encoded.
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Append a token and return a new Pointer.
bool Erase(ValueType &root) const
Erase a value in a subtree.
bool EraseValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer)
Allocator stackAllocator stackAllocator T defaultValue const
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
Set a value in a document, with move semantics.
bool Stringify(OutputStream &os) const
Stringify to string or URI fragment representation.
const GenericPointer< typename T::ValueType > T2 defaultValue
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Reference to a constant string (not taking a copy)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
const GenericPointer< typename T::ValueType > & pointer
A character must percent encoded in URI fragment.
Allocator * ownAllocator_
Allocator owned by this Pointer.
T::ValueType & SetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
GenericPointer(Allocator *allocator=0)
Default constructor.
const Ch * src_
Current read position.
T::ValueType * GetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, size_t *unresolvedTokenIndex=0)
ValueType & Swap(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
Swap a value with a value in a document.
~GenericPointer()
Destructor.
h
training ###############################
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept