Electroneum
Loading...
Searching...
No Matches
GenericPointer< ValueType, Allocator > Class Template Reference

Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator. More...

#include <pointer.h>

Collaboration diagram for GenericPointer< ValueType, Allocator >:

Classes

struct  Token
 A token is the basic units of internal representation. More...

Public Types

typedef ValueType::EncodingType EncodingType
 Encoding type from Value.
typedef ValueType::Ch Ch
 Character type from Value.

Public Member Functions

Constructors and destructor.
 GenericPointer (Allocator *allocator=0)
 Default constructor.
 GenericPointer (const Ch *source, Allocator *allocator=0)
 Constructor that parses a string or URI fragment representation.
 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.
 GenericPointer (const Token *tokens, size_t tokenCount)
 Constructor with user-supplied tokens.
 GenericPointer (const GenericPointer &rhs)
 Copy constructor.
 GenericPointer (const GenericPointer &rhs, Allocator *allocator)
 Copy constructor.
 ~GenericPointer ()
 Destructor.
GenericPointeroperator= (const GenericPointer &rhs)
 Assignment operator.

Append token

Allocatorallocator
Allocator stackAllocator stackAllocator & document
Allocator stackAllocator stackAllocator T defaultValue const
GenericPointer Append (const Token &token, Allocator *allocator=0) const
 Append a token and return a new Pointer.
GenericPointer Append (const Ch *name, SizeType length, Allocator *allocator=0) const
 Append a name token with length, and return a new Pointer.
template<typename T>
 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 stackAllocator RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) GetWithDefault(GenericDocument< EncodingType

Set a value

T value
T ValueType::AllocatorType &allocator const
stackAllocator & document
stackAllocator T value const
ValueType & Set (ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
 Set a value in a subtree, with move semantics.
ValueType & Set (ValueType &root, const ValueType &value, typename ValueType::AllocatorType &allocator) const
 Set a value in a subtree, with copy semantics.
ValueType & Set (ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const
 Set a null-terminated string in a subtree.
template<typename T>
 RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) Set(ValueType &root
 Set a primitive value in a subtree.
template<typename stackAllocator>
ValueType & Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
 Set a value in a document, with move semantics.
template<typename stackAllocator>
ValueType & Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const ValueType &value) const
 Set a value in a document, with copy semantics.
template<typename stackAllocator>
ValueType & Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *value) const
 Set a null-terminated string in a document.
template<typename T, typename stackAllocator>
 RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) Set(GenericDocument< EncodingType
 Set a primitive value in a document.

Swap a value

ValueType & Swap (ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
 Swap a value with a value in a subtree.
template<typename stackAllocator>
ValueType & Swap (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
 Swap a value with a value in a document.
bool Erase (ValueType &root) const
 Erase a value in a subtree.

Detailed Description

template<typename ValueType, typename Allocator = CrtAllocator>
class GenericPointer< ValueType, Allocator >

Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.

This class implements RFC 6901 "JavaScript Object Notation (JSON) Pointer" (https://tools.ietf.org/html/rfc6901).

A JSON pointer is for identifying a specific value in a JSON document (GenericDocument). It can simplify coding of DOM tree manipulation, because it can access multiple-level depth of DOM tree with single API call.

After it parses a string representation (e.g. "/foo/0" or URI fragment representation (e.g. "#/foo/0") into its internal representation (tokens), it can be used to resolve a specific value in multiple documents, or sub-tree of documents.

Contrary to GenericValue, Pointer can be copy constructed and copy assigned. Apart from assignment, a Pointer cannot be modified after construction.

Although Pointer is very convenient, please aware that constructing Pointer involves parsing and dynamic memory allocation. A special constructor with user- supplied tokens eliminates these.

GenericPointer depends on GenericDocument and GenericValue.

Template Parameters
ValueTypeThe value type of the DOM tree. E.g. GenericValue<UTF8<> >
AllocatorThe allocator type for allocating memory for internal representation.
Note
GenericPointer uses same encoding of ValueType. However, Allocator of GenericPointer is independent of Allocator of Value.

Definition at line 79 of file pointer.h.

Member Typedef Documentation

◆ Ch

template<typename ValueType, typename Allocator = CrtAllocator>
typedef ValueType::Ch GenericPointer< ValueType, Allocator >::Ch

Character type from Value.

Definition at line 82 of file pointer.h.

◆ EncodingType

template<typename ValueType, typename Allocator = CrtAllocator>
typedef ValueType::EncodingType GenericPointer< ValueType, Allocator >::EncodingType

Encoding type from Value.

Definition at line 81 of file pointer.h.

Constructor & Destructor Documentation

◆ GenericPointer() [1/6]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::GenericPointer ( Allocator * allocator = 0)
inline

Default constructor.

Definition at line 107 of file pointer.h.

107: allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition pointer.h:79

◆ GenericPointer() [2/6]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::GenericPointer ( const Ch * source,
Allocator * allocator = 0 )
inlineexplicit

Constructor that parses a string or URI fragment representation.

Parameters
sourceA null-terminated, string or URI fragment representation of JSON pointer.
allocatorUser supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.

Definition at line 114 of file pointer.h.

114 : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
116 }

◆ GenericPointer() [3/6]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::GenericPointer ( const Ch * source,
size_t length,
Allocator * allocator = 0 )
inline

Constructor that parses a string or URI fragment representation, with length of the source string.

Parameters
sourceA string or URI fragment representation of JSON pointer.
lengthLength of source.
allocatorUser supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
Note
Slightly faster than the overload without length.

Definition at line 137 of file pointer.h.

137 : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
138 Parse(source, length);
139 }

◆ GenericPointer() [4/6]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::GenericPointer ( const Token * tokens,
size_t tokenCount )
inline

Constructor with user-supplied tokens.

This constructor let user supplies const array of tokens. This prevents the parsing process and eliminates allocation. This is preferred for memory constrained environments.

Parameters
tokensAn constant array of tokens representing the JSON pointer.
tokenCountNumber of tokens.

Example

#define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, kPointerInvalidIndex }
#define INDEX(i) { #i, sizeof(#i) - 1, i }
static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(123) };
static const Pointer p(kTokens, sizeof(kTokens) / sizeof(kTokens[0]));
// Equivalent to static const Pointer p("/foo/123");
#undef NAME
#undef INDEX
GenericPointer< Value, CrtAllocator > Pointer
Definition fwd.h:128
#define NAME(s)
#define INDEX(i)

Definition at line 163 of file pointer.h.

163: allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}

◆ GenericPointer() [5/6]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::GenericPointer ( const GenericPointer< ValueType, Allocator > & rhs)
inline

Copy constructor.

Definition at line 166 of file pointer.h.

166 : allocator_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
167 *this = rhs;
168 }

◆ GenericPointer() [6/6]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::GenericPointer ( const GenericPointer< ValueType, Allocator > & rhs,
Allocator * allocator )
inline

Copy constructor.

Definition at line 171 of file pointer.h.

171 : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
172 *this = rhs;
173 }

◆ ~GenericPointer()

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::~GenericPointer ( )
inline

Destructor.

Definition at line 176 of file pointer.h.

176 {
177 if (nameBuffer_) // If user-supplied tokens constructor is used, nameBuffer_ is nullptr and tokens_ are not deallocated.
178 Allocator::Free(tokens_);
179 RAPIDJSON_DELETE(ownAllocator_);
180 }
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition rapidjson.h:607

Member Function Documentation

◆ Append() [1/2]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer GenericPointer< ValueType, Allocator >::Append ( const Ch * name,
SizeType length,
Allocator * allocator = 0 ) const
inline

Append a name token with length, and return a new Pointer.

Parameters
nameName to be appended.
lengthLength of name.
allocatorAllocator for the newly return Pointer.
Returns
A new Pointer with appended token.

Definition at line 232 of file pointer.h.

232 {
234 return Append(token, allocator);
235 }
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Definition pointer.h:214

◆ Append() [2/2]

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer GenericPointer< ValueType, Allocator >::Append ( const Token & token,
Allocator * allocator = 0 ) const
inline

Append a token and return a new Pointer.

Parameters
tokenToken to be appended.
allocatorAllocator for the newly return Pointer.
Returns
A new Pointer with appended token.

Definition at line 214 of file pointer.h.

214 {
216 r.allocator_ = allocator;
217 Ch *p = r.CopyFromRaw(*this, 1, token.length + 1);
218 std::memcpy(p, token.name, (token.length + 1) * sizeof(Ch));
219 r.tokens_[tokenCount_].name = p;
220 r.tokens_[tokenCount_].length = token.length;
221 r.tokens_[tokenCount_].index = token.index;
222 return r;
223 }
GenericPointer(Allocator *allocator=0)
Definition pointer.h:107
SizeType index
A valid array index, if it is not equal to kPointerInvalidIndex.
Definition pointer.h:100
SizeType length
Length of the name.
Definition pointer.h:99
const Ch * name
Name of the token. It has null character at the end but it can contain null character.
Definition pointer.h:98
Here is the caller graph for this function:

◆ Erase()

template<typename ValueType, typename Allocator = CrtAllocator>
bool GenericPointer< ValueType, Allocator >::Erase ( ValueType & root) const
inline

Erase a value in a subtree.

Parameters
rootRoot value of a DOM sub-tree to be resolved. It can be any value other than document root.
Returns
Whether the resolved value is found and erased.
Note
Erasing with an empty pointer Pointer(""), i.e. the root, always fail and return false.

Definition at line 714 of file pointer.h.

714 {
716 if (tokenCount_ == 0) // Cannot erase the root
717 return false;
718
719 ValueType* v = &root;
720 const Token* last = tokens_ + (tokenCount_ - 1);
721 for (const Token *t = tokens_; t != last; ++t) {
722 switch (v->GetType()) {
723 case kObjectType:
724 {
725 typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
726 if (m == v->MemberEnd())
727 return false;
728 v = &m->value;
729 }
730 break;
731 case kArrayType:
732 if (t->index == kPointerInvalidIndex || t->index >= v->Size())
733 return false;
734 v = &((*v)[t->index]);
735 break;
736 default:
737 return false;
738 }
739 }
740
741 switch (v->GetType()) {
742 case kObjectType:
743 return v->EraseMember(GenericStringRef<Ch>(last->name, last->length));
744 case kArrayType:
745 if (last->index == kPointerInvalidIndex || last->index >= v->Size())
746 return false;
747 v->Erase(v->Begin() + last->index);
748 return true;
749 default:
750 return false;
751 }
752 }
bool Erase(ValueType &root) const
Erase a value in a subtree.
Definition pointer.h:714
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:411
Here is the caller graph for this function:

◆ operator=()

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer & GenericPointer< ValueType, Allocator >::operator= ( const GenericPointer< ValueType, Allocator > & rhs)
inline

Assignment operator.

Definition at line 183 of file pointer.h.

183 {
184 if (this != &rhs) {
185 // Do not delete ownAllcator
186 if (nameBuffer_)
187 Allocator::Free(tokens_);
188
189 tokenCount_ = rhs.tokenCount_;
190 parseErrorOffset_ = rhs.parseErrorOffset_;
191 parseErrorCode_ = rhs.parseErrorCode_;
192
193 if (rhs.nameBuffer_)
194 CopyFromRaw(rhs); // Normally parsed tokens.
195 else {
196 tokens_ = rhs.tokens_; // User supplied const tokens.
197 nameBuffer_ = 0;
198 }
199 }
200 return *this;
201 }

◆ RAPIDJSON_DISABLEIF_RETURN() [1/4]

template<typename ValueType, typename Allocator = CrtAllocator>
template<typename T>
GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN ( (internal::NotExpr< internal::IsSame< typename internal::RemoveConst< T >::Type, Ch > >) ,
(GenericPointer< ValueType, Allocator >)  )

Append a name token without length, and return a new Pointer.

Parameters
nameName (const Ch*) to be appended.
allocatorAllocator for the newly return Pointer.
Returns
A new Pointer with appended token.

◆ RAPIDJSON_DISABLEIF_RETURN() [2/4]

template<typename ValueType, typename Allocator = CrtAllocator>
Allocator stackAllocator GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN ( (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >) ,
(ValueType &)  )

◆ RAPIDJSON_DISABLEIF_RETURN() [3/4]

template<typename ValueType, typename Allocator = CrtAllocator>
template<typename T, typename stackAllocator>
GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN ( (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >) ,
(ValueType &)  )

Set a primitive value in a document.

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t, bool

◆ RAPIDJSON_DISABLEIF_RETURN() [4/4]

template<typename ValueType, typename Allocator = CrtAllocator>
template<typename T>
GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN ( (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >) ,
(ValueType &)  ) &

Set a primitive value in a subtree.

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t, bool

◆ Set() [1/6]

template<typename ValueType, typename Allocator = CrtAllocator>
template<typename stackAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Set ( GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > & document,
const Ch * value ) const
inline

Set a null-terminated string in a document.

Definition at line 658 of file pointer.h.

658 {
659 return Create(document) = ValueType(value, document.GetAllocator()).Move();
660 }
Allocator stackAllocator stackAllocator & document
Definition pointer.h:594

◆ Set() [2/6]

template<typename ValueType, typename Allocator = CrtAllocator>
template<typename stackAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Set ( GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > & document,
const ValueType & value ) const
inline

Set a value in a document, with copy semantics.

Definition at line 652 of file pointer.h.

652 {
653 return Create(document).CopyFrom(value, document.GetAllocator());
654 }

◆ Set() [3/6]

template<typename ValueType, typename Allocator = CrtAllocator>
template<typename stackAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Set ( GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > & document,
ValueType & value ) const
inline

Set a value in a document, with move semantics.

Definition at line 646 of file pointer.h.

646 {
647 return Create(document) = value;
648 }

◆ Set() [4/6]

template<typename ValueType, typename Allocator = CrtAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Set ( ValueType & root,
const Ch * value,
typename ValueType::AllocatorType & allocator ) const
inline

Set a null-terminated string in a subtree.

Definition at line 623 of file pointer.h.

623 {
624 return Create(root, allocator) = ValueType(value, allocator).Move();
625 }

◆ Set() [5/6]

template<typename ValueType, typename Allocator = CrtAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Set ( ValueType & root,
const ValueType & value,
typename ValueType::AllocatorType & allocator ) const
inline

Set a value in a subtree, with copy semantics.

Definition at line 618 of file pointer.h.

618 {
619 return Create(root, allocator).CopyFrom(value, allocator);
620 }

◆ Set() [6/6]

template<typename ValueType, typename Allocator = CrtAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Set ( ValueType & root,
ValueType & value,
typename ValueType::AllocatorType & allocator ) const
inline

Set a value in a subtree, with move semantics.

It creates all parents if they are not exist or types are different to the tokens. So this function always succeeds but potentially remove existing values.

Parameters
rootRoot value of a DOM sub-tree to be resolved. It can be any value other than document root.
valueValue to be set.
allocatorAllocator for creating the values if the specified value or its parents are not exist.
See also
Create()

Definition at line 613 of file pointer.h.

613 {
614 return Create(root, allocator) = value;
615 }
Here is the caller graph for this function:

◆ Swap() [1/2]

template<typename ValueType, typename Allocator = CrtAllocator>
template<typename stackAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Swap ( GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > & document,
ValueType & value ) const
inline

Swap a value with a value in a document.

Definition at line 701 of file pointer.h.

701 {
702 return Create(document).Swap(value);
703 }
ValueType & Swap(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Swap a value with a value in a subtree.
Definition pointer.h:695

◆ Swap() [2/2]

template<typename ValueType, typename Allocator = CrtAllocator>
ValueType & GenericPointer< ValueType, Allocator >::Swap ( ValueType & root,
ValueType & value,
typename ValueType::AllocatorType & allocator ) const
inline

Swap a value with a value in a subtree.

It creates all parents if they are not exist or types are different to the tokens. So this function always succeeds but potentially remove existing values.

Parameters
rootRoot value of a DOM sub-tree to be resolved. It can be any value other than document root.
valueValue to be swapped.
allocatorAllocator for creating the values if the specified value or its parents are not exist.
See also
Create()

Definition at line 695 of file pointer.h.

695 {
696 return Create(root, allocator).Swap(value);
697 }
Here is the caller graph for this function:

Member Data Documentation

◆ allocator

template<typename ValueType, typename Allocator = CrtAllocator>
Allocator* GenericPointer< ValueType, Allocator >::allocator

Definition at line 245 of file pointer.h.

245 {
247 }
248
249#if RAPIDJSON_HAS_STDSTRING
251
257 return Append(name.c_str(), static_cast<SizeType>(name.size()), allocator);
258 }
259#endif
260
262
268 char buffer[21];
270 SizeType length = static_cast<SizeType>(end - buffer);
271 buffer[length] = '\0';
272
273 if (sizeof(Ch) == 1) {
274 Token token = { reinterpret_cast<Ch*>(buffer), length, index };
275 return Append(token, allocator);
276 }
277 else {
278 Ch name[21];
279 for (size_t i = 0; i <= length; i++)
280 name[i] = static_cast<Ch>(buffer[i]);
281 Token token = { name, length, index };
282 return Append(token, allocator);
283 }
284 }
285
287
293 if (token.IsString())
294 return Append(token.GetString(), token.GetStringLength(), allocator);
295 else {
296 RAPIDJSON_ASSERT(token.IsUint64());
297 RAPIDJSON_ASSERT(token.GetUint64() <= SizeType(~0));
298 return Append(static_cast<SizeType>(token.GetUint64()), allocator);
299 }
300 }
301
303
304
306 bool IsValid() const { return parseErrorCode_ == kPointerParseErrorNone; }
307
309 size_t GetParseErrorOffset() const { return parseErrorOffset_; }
310
312 PointerParseErrorCode GetParseErrorCode() const { return parseErrorCode_; }
313
315
317 Allocator& GetAllocator() { return *allocator_; }
318
320
321
323 const Token* GetTokens() const { return tokens_; }
324
326 size_t GetTokenCount() const { return tokenCount_; }
327
329
331
332
334
337 bool operator==(const GenericPointer& rhs) const {
338 if (!IsValid() || !rhs.IsValid() || tokenCount_ != rhs.tokenCount_)
339 return false;
340
341 for (size_t i = 0; i < tokenCount_; i++) {
342 if (tokens_[i].index != rhs.tokens_[i].index ||
343 tokens_[i].length != rhs.tokens_[i].length ||
344 (tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch)* tokens_[i].length) != 0))
345 {
346 return false;
347 }
348 }
349
350 return true;
351 }
352
354
357 bool operator!=(const GenericPointer& rhs) const { return !(*this == rhs); }
358
360
362
363
365
369 template<typename OutputStream>
370 bool Stringify(OutputStream& os) const {
372 }
373
375
379 template<typename OutputStream>
382 }
383
385
387
388
390
406 ValueType* v = &root;
407 bool exist = true;
408 for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
409 if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
410 v->PushBack(ValueType().Move(), allocator);
411 v = &((*v)[v->Size() - 1]);
412 exist = false;
413 }
414 else {
415 if (t->index == kPointerInvalidIndex) { // must be object name
416 if (!v->IsObject())
417 v->SetObject(); // Change to Object
418 }
419 else { // object name or array index
420 if (!v->IsArray() && !v->IsObject())
421 v->SetArray(); // Change to Array
422 }
423
424 if (v->IsArray()) {
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);
429 exist = false;
430 }
431 v = &((*v)[t->index]);
432 }
433 else {
434 typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
435 if (m == v->MemberEnd()) {
436 v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator);
437 v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end
438 exist = false;
439 }
440 else
441 v = &m->value;
442 }
443 }
444 }
445
446 if (alreadyExist)
448
449 return *v;
450 }
451
453
458 template <typename stackAllocator>
460 return Create(document, document.GetAllocator(), alreadyExist);
461 }
462
464
466
467
469
482 ValueType* Get(ValueType& root, size_t* unresolvedTokenIndex = 0) const {
484 ValueType* v = &root;
485 for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
486 switch (v->GetType()) {
487 case kObjectType:
488 {
489 typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
490 if (m == v->MemberEnd())
491 break;
492 v = &m->value;
493 }
494 continue;
495 case kArrayType:
496 if (t->index == kPointerInvalidIndex || t->index >= v->Size())
497 break;
498 v = &((*v)[t->index]);
499 continue;
500 default:
501 break;
502 }
503
504 // Error: unresolved token
506 *unresolvedTokenIndex = static_cast<size_t>(t - tokens_);
507 return 0;
508 }
509 return v;
510 }
511
513
517 const ValueType* Get(const ValueType& root, size_t* unresolvedTokenIndex = 0) const {
518 return Get(const_cast<ValueType&>(root), unresolvedTokenIndex);
519 }
520
522
524
525
527
537 bool alreadyExist;
539 return alreadyExist ? v : v.CopyFrom(defaultValue, allocator);
540 }
541
544 bool alreadyExist;
546 return alreadyExist ? v : v.SetString(defaultValue, allocator);
547 }
548
549#if RAPIDJSON_HAS_STDSTRING
552 bool alreadyExist;
554 return alreadyExist ? v : v.SetString(defaultValue, allocator);
555 }
556#endif
557
559
562 template <typename T>
566 }
567
569 template <typename stackAllocator>
571 return GetWithDefault(document, defaultValue, document.GetAllocator());
572 }
573
575 template <typename stackAllocator>
577 return GetWithDefault(document, defaultValue, document.GetAllocator());
578 }
RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr< internal::IsSame< typename internal::RemoveConst< T >::Type, Ch > >),(GenericPointer)) Append(T *name
bool operator==(expect< T > const &lhs, expect< U > const &rhs) noexcept(noexcept(lhs.equal(rhs)))
Definition expect.h:401
char * u64toa(uint64_t value, char *buffer)
Definition itoa.h:126
bool operator!=(const ec_scalar &a, const ec_scalar &b)
Definition main.cpp:49

◆ const [1/3]

template<typename ValueType, typename Allocator = CrtAllocator>
stackAllocator T value GenericPointer< ValueType, Allocator >::const
Initial value:
{
return Create(document) = value

Definition at line 676 of file pointer.h.

◆ const [2/3]

template<typename ValueType, typename Allocator = CrtAllocator>
T ValueType::AllocatorType& allocator GenericPointer< ValueType, Allocator >::const
Initial value:
{
return Create(root, allocator) = ValueType(value).Move()

Definition at line 640 of file pointer.h.

◆ const [3/3]

template<typename ValueType, typename Allocator = CrtAllocator>
Allocator stackAllocator stackAllocator T defaultValue GenericPointer< ValueType, Allocator >::const
Initial value:
{
return GetWithDefault(document, defaultValue, document.GetAllocator())
const GenericPointer< typename T::ValueType > T2 defaultValue
Definition pointer.h:1124

Definition at line 594 of file pointer.h.

◆ document [1/2]

template<typename ValueType, typename Allocator = CrtAllocator>
stackAllocator& GenericPointer< ValueType, Allocator >::document

Definition at line 676 of file pointer.h.

◆ document [2/2]

template<typename ValueType, typename Allocator = CrtAllocator>
Allocator stackAllocator stackAllocator& GenericPointer< ValueType, Allocator >::document

Definition at line 594 of file pointer.h.

◆ value

template<typename ValueType, typename Allocator = CrtAllocator>
T GenericPointer< ValueType, Allocator >::value

Definition at line 640 of file pointer.h.


The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/include/rapidjson/fwd.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/include/rapidjson/pointer.h