Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator. More...
#include <fwd.h>
Classes | |
class | PercentDecodeStream |
A helper stream for decoding a percent-encoded sequence into code unit. More... | |
class | PercentEncodeStream |
A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence. More... | |
struct | Token |
A token is the basic units of internal representation. More... | |
Public Types | |
typedef ValueType::EncodingType | EncodingType |
Encoding type from Value. More... | |
typedef ValueType::Ch | Ch |
Character type from Value. More... | |
Public Member Functions | |
Allocator stackAllocator | RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) GetWithDefault(GenericDocument< EncodingType |
bool | Erase (ValueType &root) const |
Erase a value in a subtree. More... | |
Constructors and destructor. | |
GenericPointer (Allocator *allocator=0) | |
Default constructor. More... | |
GenericPointer (const Ch *source, Allocator *allocator=0) | |
Constructor that parses a string or URI fragment representation. More... | |
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. More... | |
GenericPointer (const Token *tokens, size_t tokenCount) | |
Constructor with user-supplied tokens. More... | |
GenericPointer (const GenericPointer &rhs) | |
Copy constructor. More... | |
GenericPointer (const GenericPointer &rhs, Allocator *allocator) | |
Copy constructor. More... | |
~GenericPointer () | |
Destructor. More... | |
GenericPointer & | operator= (const GenericPointer &rhs) |
Assignment operator. More... | |
Append token | |
GenericPointer | Append (const Token &token, Allocator *allocator=0) const |
Append a token and return a new Pointer. More... | |
GenericPointer | Append (const Ch *name, SizeType length, Allocator *allocator=0) const |
Append a name token with length, and return a new Pointer. More... | |
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. More... | |
Swap a value | |
ValueType & | Swap (ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const |
Swap a value with a value in a subtree. More... | |
template<typename stackAllocator > | |
ValueType & | Swap (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const |
Swap a value with a value in a document. More... | |
Public Attributes | |
Allocator * | allocator |
Allocator stackAllocator stackAllocator & | document |
Allocator stackAllocator stackAllocator T defaultValue | const |
Private Member Functions | |
Ch * | CopyFromRaw (const GenericPointer &rhs, size_t extraToken=0, size_t extraNameBufferSize=0) |
Clone the content from rhs to this. More... | |
bool | NeedPercentEncode (Ch c) const |
Check whether a character should be percent-encoded. More... | |
void | Parse (const Ch *source, size_t length) |
Parse a JSON String or its URI fragment representation into tokens. More... | |
template<bool uriFragment, typename OutputStream > | |
bool | Stringify (OutputStream &os) const |
Stringify to string or URI fragment representation. More... | |
Private Attributes | |
Allocator * | allocator_ |
The current allocator. It is either user-supplied or equal to ownAllocator_. More... | |
Allocator * | ownAllocator_ |
Allocator owned by this Pointer. More... | |
Ch * | nameBuffer_ |
A buffer containing all names in tokens. More... | |
Token * | tokens_ |
A list of tokens. More... | |
size_t | tokenCount_ |
Number of tokens in tokens_. More... | |
size_t | parseErrorOffset_ |
Offset in code unit when parsing fail. More... | |
PointerParseErrorCode | parseErrorCode_ |
Parsing error code. More... | |
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. More... | |
ValueType & | Set (ValueType &root, const ValueType &value, typename ValueType::AllocatorType &allocator) const |
Set a value in a subtree, with copy semantics. More... | |
ValueType & | Set (ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const |
Set a null-terminated string in a subtree. More... | |
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. More... | |
template<typename stackAllocator > | |
ValueType & | Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const |
Set a value in a document, with move semantics. More... | |
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. More... | |
template<typename stackAllocator > | |
ValueType & | Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *value) const |
Set a null-terminated string in a document. More... | |
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. More... | |
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.
ValueType | The value type of the DOM tree. E.g. GenericValue<UTF8<> > |
Allocator | The allocator type for allocating memory for internal representation. |
typedef ValueType::Ch GenericPointer< ValueType, Allocator >::Ch |
typedef ValueType::EncodingType GenericPointer< ValueType, Allocator >::EncodingType |
|
inline |
Default constructor.
Definition at line 107 of file pointer.h.
|
inlineexplicit |
Constructor that parses a string or URI fragment representation.
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. |
Definition at line 114 of file pointer.h.
|
inline |
Constructor that parses a string or URI fragment representation, with length of the source string.
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. |
Definition at line 137 of file pointer.h.
|
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.
tokens | An constant array of tokens representing the JSON pointer. |
tokenCount | Number of tokens. |
Definition at line 163 of file pointer.h.
|
inline |
Copy constructor.
Definition at line 166 of file pointer.h.
|
inline |
Copy constructor.
Definition at line 171 of file pointer.h.
|
inline |
Destructor.
Definition at line 176 of file pointer.h.
|
inline |
Append a token and return a new Pointer.
token | Token to be appended. |
allocator | Allocator for the newly return Pointer. |
Definition at line 214 of file pointer.h.
|
inline |
Append a name token with length, and return a new Pointer.
name | Name to be appended. |
length | Length of name. |
allocator | Allocator for the newly return Pointer. |
Definition at line 232 of file pointer.h.
|
inlineprivate |
Clone the content from rhs to this.
rhs | Source pointer. |
extraToken | Extra tokens to be allocated. |
extraNameBufferSize | Extra name buffer size (in number of Ch) to be allocated. |
Definition at line 762 of file pointer.h.
|
inline |
Erase a value in a subtree.
root | Root value of a DOM sub-tree to be resolved. It can be any value other than document root. |
Pointer
(""), i.e. the root, always fail and return false. Definition at line 714 of file pointer.h.
|
inlineprivate |
Check whether a character should be percent-encoded.
According to RFC 3986 2.3 Unreserved Characters.
c | The character (code unit) to be tested. |
|
inline |
Assignment operator.
Definition at line 183 of file pointer.h.
|
inlineprivate |
Parse a JSON String or its URI fragment representation into tokens.
source | Either a JSON Pointer string, or its URI fragment representation. Not need to be null terminated. |
length | Length of the source string. |
Definition at line 805 of file pointer.h.
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.
name | Name (const Ch*) to be appended. |
allocator | Allocator for the newly return Pointer. |
Allocator stackAllocator GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN | ( | (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >) | , |
(ValueType &) | |||
) |
GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN | ( | (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >) | , |
(ValueType &) | |||
) |
Set a primitive value in a subtree.
T | Either Type, int , unsigned , int64_t , uint64_t , bool |
GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN | ( | (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >) | , |
(ValueType &) | |||
) |
Set a primitive value in a document.
T | Either Type, int , unsigned , int64_t , uint64_t , bool |
|
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.
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. |
Definition at line 613 of file pointer.h.
|
inline |
|
inline |
|
inline |
|
inline |
Set a value in a document, with copy semantics.
Definition at line 652 of file pointer.h.
|
inline |
Set a null-terminated string in a document.
Definition at line 658 of file pointer.h.
|
inlineprivate |
Stringify to string or URI fragment representation.
uriFragment | True for stringifying to URI fragment representation. False for string representation. |
OutputStream | type of output stream. |
os | The output stream. |
Definition at line 944 of file pointer.h.
|
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.
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. |
Definition at line 695 of file pointer.h.
|
inline |
Allocator* GenericPointer< ValueType, Allocator >::allocator |
|
private |
Allocator stackAllocator stackAllocator T defaultValue GenericPointer< ValueType, Allocator >::const |
T ValueType::AllocatorType& allocator GenericPointer< ValueType, Allocator >::const |
stackAllocator T value GenericPointer< ValueType, Allocator >::const |
Allocator stackAllocator stackAllocator& GenericPointer< ValueType, Allocator >::document |
stackAllocator& GenericPointer< ValueType, Allocator >::document |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
T GenericPointer< ValueType, Allocator >::value |