GenericPointer
Engine/source/persistence/rapidjson/pointer.h
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Classes:
A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence.
A token is the basic units of internal representation.
Append token
RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr< internal::IsSame< typename internal::RemoveConst< T >::Type, Ch > >) , (GenericPointer) )
Append a name token without length, and return a new Pointer.
The current allocator. It is either user-supplied or equal to ownAllocator_.
Allocator owned by this Pointer.
Ch *
A buffer containing all names in tokens.
size_t
Number of tokens in tokens_.
size_t
Offset in code unit when parsing fail.
Parsing error code.
Constructors and destructor.
GenericPointer(Allocator * allocator)
Default constructor.
GenericPointer(const Ch * source, Allocator * allocator)
Constructor that parses a string or URI fragment representation.
GenericPointer(const Ch * source, size_t length, Allocator * allocator)
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.
Destructor.
operator=(const GenericPointer & rhs)
Assignment operator.
Swap(GenericPointer & other)
Swap the content of this pointer with an other.
Public Types
ValueType::Ch
Ch
Character type from Value.
ValueType::EncodingType
EncodingType
Encoding type from Value.
Detailed Description
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
This class implements RFC 6901 "JavaScript Object Notation (JSON) Pointer" (
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.
Parameters:
ValueType | The value type of the DOM tree. E.g. GenericValue |
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.
Append token
Append(const Token & token, Allocator * allocator)
Append a token and return a new Pointer.
Parameters:
token | Token to be appended. |
allocator | Allocator for the newly return Pointer. |
A new Pointer with appended token.
Append(const Ch * name, SizeType length, Allocator * allocator)
Append a name token with length, and return a new Pointer.
Parameters:
name | Name to be appended. |
length | Length of name. |
allocator | Allocator for the newly return Pointer. |
A new Pointer with appended token.
RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr< internal::IsSame< typename internal::RemoveConst< T >::Type, Ch > >) , (GenericPointer) )
Append a name token without length, and return a new Pointer.
Parameters:
name | Name (const Ch*) to be appended. |
allocator | Allocator for the newly return Pointer. |
A new Pointer with appended token.
Allocator * allocator
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Allocator * ownAllocator_
Allocator owned by this Pointer.
Ch * nameBuffer_
A buffer containing all names in tokens.
Token * tokens_
A list of tokens.
size_t tokenCount_
Number of tokens in tokens_.
size_t parseErrorOffset_
Offset in code unit when parsing fail.
PointerParseErrorCode parseErrorCode_
Parsing error code.
Constructors and destructor.
GenericPointer(Allocator * allocator)
Default constructor.
GenericPointer(const Ch * source, Allocator * allocator)
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(const Ch * source, size_t length, Allocator * allocator)
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(const Token * tokens, size_t tokenCount)
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. |
#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(const GenericPointer & rhs)
Copy constructor.
GenericPointer(const GenericPointer & rhs, Allocator * allocator)
Copy constructor.
~GenericPointer()
Destructor.
operator=(const GenericPointer & rhs)
Assignment operator.
Swap(GenericPointer & other)
Swap the content of this pointer with an other.
Parameters:
other | The pointer to swap with. |
note:Constant complexity.