Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator. More...
#include <pointer.h>
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, Allocator *allocator=0) | |
| Copy constructor. | |
| ~GenericPointer () | |
| Destructor. | |
| GenericPointer & | operator= (const GenericPointer &rhs) |
| Assignment operator. | |
Append token | |
| 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> | |
| GenericPointer | Append (T *name, Allocator *allocator=0) const |
| Append a name token without length, and return a new Pointer. | |
| GenericPointer | Append (SizeType index, Allocator *allocator=0) const |
| Append a index token, and return a new Pointer. | |
| GenericPointer | Append (const ValueType &token, Allocator *allocator=0) const |
| Append a token by value, and return a new Pointer. | |
Handling Parse Error | |
| bool | IsValid () const |
| Check whether this is a valid pointer. | |
| size_t | GetParseErrorOffset () const |
| Get the parsing error offset in code unit. | |
| PointerParseErrorCode | GetParseErrorCode () const |
| Get the parsing error code. | |
| Allocator & | GetAllocator () |
| Get the allocator of this pointer. | |
Tokens | |
| const Token * | GetTokens () const |
| Get the token array (const version only). | |
| size_t | GetTokenCount () const |
| Get the number of tokens. | |
Equality/inequality operators | |
| bool | operator== (const GenericPointer &rhs) const |
| Equality operator. | |
| bool | operator!= (const GenericPointer &rhs) const |
| Inequality operator. | |
Stringify | |
| template<typename OutputStream> | |
| bool | Stringify (OutputStream &os) const |
| Stringify the pointer into string representation. | |
| template<typename OutputStream> | |
| bool | StringifyUriFragment (OutputStream &os) const |
| Stringify the pointer into URI fragment representation. | |
Create value | |
| ValueType & | Create (ValueType &root, typename ValueType::AllocatorType &allocator, bool *alreadyExist=0) const |
| Create a value in a subtree. | |
| template<typename stackAllocator> | |
| ValueType & | Create (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, bool *alreadyExist=0) const |
| Creates a value in a document. | |
Query value | |
| ValueType * | Get (ValueType &root, size_t *unresolvedTokenIndex=0) const |
| Query a value in a subtree. | |
| const ValueType * | Get (const ValueType &root, size_t *unresolvedTokenIndex=0) const |
| Query a const value in a const subtree. | |
Query a value with default | |
| ValueType & | GetWithDefault (ValueType &root, const ValueType &defaultValue, typename ValueType::AllocatorType &allocator) const |
| Query a value in a subtree with default value. | |
| ValueType & | GetWithDefault (ValueType &root, const Ch *defaultValue, typename ValueType::AllocatorType &allocator) const |
| Query a value in a subtree with default null-terminated string. | |
| template<typename T> | |
| ValueType & | GetWithDefault (ValueType &root, T defaultValue, typename ValueType::AllocatorType &allocator) const |
| Query a value in a subtree with default primitive value. | |
| template<typename stackAllocator> | |
| ValueType & | GetWithDefault (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const ValueType &defaultValue) const |
| Query a value in a document with default value. | |
| template<typename stackAllocator> | |
| ValueType & | GetWithDefault (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *defaultValue) const |
| Query a value in a document with default null-terminated string. | |
| template<typename T, typename stackAllocator> | |
| ValueType & | GetWithDefault (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, T defaultValue) const |
| Query a value in a document with default primitive value. | |
Set a value | |
| 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> | |
| ValueType & | Set (ValueType &root, T value, typename ValueType::AllocatorType &allocator) const |
| 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> | |
| ValueType & | Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, T value) const |
| 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
class rapidjson::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
-
ValueType The value type of the DOM tree. E.g. GenericValue<UTF8<> > Allocator The 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.
Constructor & Destructor Documentation
◆ GenericPointer() [1/3]
|
inlineexplicit |
Constructor that parses a string or URI fragment representation.
- Parameters
-
source A null-terminated, string or URI fragment representation of JSON pointer. allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
◆ GenericPointer() [2/3]
|
inline |
Constructor that parses a string or URI fragment representation, with length of the source string.
- Parameters
-
source A string or URI fragment representation of JSON pointer. length Length of source. allocator User supplied allocator for this pointer. If no allocator is provided, it creates a self-owned one.
- Note
- Slightly faster than the overload without length.
◆ GenericPointer() [3/3]
|
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
-
tokens An constant array of tokens representing the JSON pointer. tokenCount Number of tokens.
Example
Member Function Documentation
◆ Append() [1/5]
|
inline |
◆ Append() [2/5]
|
inline |
◆ Append() [3/5]
|
inline |
◆ Append() [4/5]
|
inline |
◆ Append() [5/5]
|
inline |
◆ Create() [1/2]
|
inline |
Creates a value in a document.
- Parameters
-
document A document to be resolved. alreadyExist If non-null, it stores whether the resolved value is already exist.
- Returns
- The resolved newly created, or already exists value.
◆ Create() [2/2]
|
inline |
Create a value in a subtree.
If the value is not exist, it creates all parent values and a JSON Null value. So it always succeed and return the newly created or existing value.
Remind that it may change types of parents according to tokens, so it potentially removes previously stored values. For example, if a document was an array, and "/foo" is used to create a value, then the document will be changed to an object, and all existing array elements are lost.
- Parameters
-
root Root value of a DOM subtree to be resolved. It can be any value other than document root. allocator Allocator for creating the values if the specified value or its parents are not exist. alreadyExist If non-null, it stores whether the resolved value is already exist.
- Returns
- The resolved newly created (a JSON Null value), or already exists value.
◆ Erase()
|
inline |
Erase a value in a subtree.
- Parameters
-
root Root 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.
◆ Get() [1/2]
|
inline |
Query a const value in a const subtree.
- Parameters
-
root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
- Returns
- Pointer to the value if it can be resolved. Otherwise null.
◆ Get() [2/2]
|
inline |
Query a value in a subtree.
- Parameters
-
root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token.
- Returns
- Pointer to the value if it can be resolved. Otherwise null.
- Note
- There are only 3 situations when a value cannot be resolved:
- A value in the path is not an array nor object.
- An object value does not contain the token.
- A token is out of range of an array value.
Use unresolvedTokenIndex to retrieve the token index.
◆ GetWithDefault() [1/3]
|
inline |
Query a value in a document with default primitive value.
- Template Parameters
-
T Either Type, int,unsigned,int64_t,uint64_t,bool
◆ GetWithDefault() [2/3]
|
inline |
Query a value in a subtree with default value.
Similar to Get(), but if the specified value do not exists, it creates all parents and clone the default value. So that this function always succeed.
- Parameters
-
root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. defaultValue Default value to be cloned if the value was not exists. allocator Allocator for creating the values if the specified value or its parents are not exist.
- See also
- Create()
◆ GetWithDefault() [3/3]
|
inline |
Query a value in a subtree with default primitive value.
- Template Parameters
-
T Either Type, int,unsigned,int64_t,uint64_t,bool
◆ operator!=()
|
inline |
Inequality operator.
- Note
- When any pointers are invalid, always returns true.
◆ operator==()
|
inline |
Equality operator.
- Note
- When any pointers are invalid, always returns false.
◆ Set() [1/3]
|
inline |
Set a primitive value in a document.
- Template Parameters
-
T Either Type, int,unsigned,int64_t,uint64_t,bool
◆ Set() [2/3]
|
inline |
Set a primitive value in a subtree.
- Template Parameters
-
T Either Type, int,unsigned,int64_t,uint64_t,bool
◆ Set() [3/3]
|
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
-
root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. value Value to be set. allocator Allocator for creating the values if the specified value or its parents are not exist.
- See also
- Create()
◆ Stringify()
|
inline |
Stringify the pointer into string representation.
- Template Parameters
-
OutputStream Type of output stream.
- Parameters
-
os The output stream.
◆ StringifyUriFragment()
|
inline |
Stringify the pointer into URI fragment representation.
- Template Parameters
-
OutputStream Type of output stream.
- Parameters
-
os The output stream.
◆ Swap()
|
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
-
root Root value of a DOM sub-tree to be resolved. It can be any value other than document root. value Value to be swapped. allocator Allocator for creating the values if the specified value or its parents are not exist.
- See also
- Create()
The documentation for this class was generated from the following files: