Query a value in a subtree. ! \param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. \param unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token. \return Pointer to the value if it can be resolved. Otherwise null. \note There are onl
| 477 | Use unresolvedTokenIndex to retrieve the token index. |
| 478 | */ |
| 479 | ValueType* Get(ValueType& root, size_t* unresolvedTokenIndex = 0) const { |
| 480 | RAPIDJSON_ASSERT(IsValid()); |
| 481 | ValueType* v = &root; |
| 482 | for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { |
| 483 | switch (v->GetType()) { |
| 484 | case kObjectType: |
| 485 | { |
| 486 | typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length)); |
| 487 | if (m == v->MemberEnd()) |
| 488 | break; |
| 489 | v = &m->value; |
| 490 | } |
| 491 | continue; |
| 492 | case kArrayType: |
| 493 | if (t->index == kPointerInvalidIndex || t->index >= v->Size()) |
| 494 | break; |
| 495 | v = &((*v)[t->index]); |
| 496 | continue; |
| 497 | default: |
| 498 | break; |
| 499 | } |
| 500 | |
| 501 | // Error: unresolved token |
| 502 | if (unresolvedTokenIndex) |
| 503 | *unresolvedTokenIndex = static_cast<size_t>(t - tokens_); |
| 504 | return 0; |
| 505 | } |
| 506 | return v; |
| 507 | } |
| 508 | |
| 509 | //! Query a const value in a const subtree. |
| 510 | /*! |
no test coverage detected