Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
GenericPointer< ValueType, Allocator > Class Template Reference

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::Ch Ch
 Character type from Value. More...
 
typedef ValueType::EncodingType EncodingType
 Encoding type from Value. More...
 

Public Member Functions

bool Erase (ValueType &root) const
 Erase a value in a subtree. More...
 
Allocator stackAllocator RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) GetWithDefault(GenericDocument< EncodingType
 
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, Allocator *allocator=0)
 Copy constructor. More...
 
 ~GenericPointer ()
 Destructor. More...
 
GenericPointeroperator= (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 T defaultValue const
 
Allocator stackAllocator stackAllocator & document
 

Private Member Functions

ChCopyFromRaw (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...
 
ChnameBuffer_
 A buffer containing all names in tokens. More...
 
Allocator * ownAllocator_
 Allocator owned by this Pointer. More...
 
PointerParseErrorCode parseErrorCode_
 Parsing error code. More...
 
size_t parseErrorOffset_
 Offset in code unit when parsing fail. More...
 
size_t tokenCount_
 Number of tokens in tokens_. More...
 
Tokentokens_
 A list of tokens. 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...
 

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 126 of file fwd.h.

Member Typedef Documentation

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

Character type from Value.

Definition at line 84 of file pointer.h.

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

Encoding type from Value.

Definition at line 83 of file pointer.h.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 109 of file pointer.h.

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 116 of file pointer.h.

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 139 of file pointer.h.

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

Definition at line 165 of file pointer.h.

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

Copy constructor.

Definition at line 168 of file pointer.h.

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

Destructor.

Definition at line 173 of file pointer.h.

Member Function Documentation

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 211 of file pointer.h.

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 229 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
Ch* GenericPointer< ValueType, Allocator >::CopyFromRaw ( const GenericPointer< ValueType, Allocator > &  rhs,
size_t  extraToken = 0,
size_t  extraNameBufferSize = 0 
)
inlineprivate

Clone the content from rhs to this.

Parameters
rhsSource pointer.
extraTokenExtra tokens to be allocated.
extraNameBufferSizeExtra name buffer size (in number of Ch) to be allocated.
Returns
Start of non-occupied name buffer, for storing extra names.

Definition at line 759 of file pointer.h.

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 711 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
bool GenericPointer< ValueType, Allocator >::NeedPercentEncode ( Ch  c) const
inlineprivate

Check whether a character should be percent-encoded.

According to RFC 3986 2.3 Unreserved Characters.

Parameters
cThe character (code unit) to be tested.

Definition at line 790 of file pointer.h.

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

Assignment operator.

Definition at line 180 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
void GenericPointer< ValueType, Allocator >::Parse ( const Ch source,
size_t  length 
)
inlineprivate

Parse a JSON String or its URI fragment representation into tokens.

Parameters
sourceEither a JSON Pointer string, or its URI fragment representation. Not need to be null terminated.
lengthLength of the source string.
Note
Source cannot be JSON String Representation of JSON Pointer, e.g. In "/\u0000", will not be unescaped.

Definition at line 802 of file pointer.h.

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.
template<typename ValueType, typename Allocator = CrtAllocator>
Allocator stackAllocator GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN ( (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >)  ,
(ValueType &)   
)
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
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
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 610 of file pointer.h.

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 615 of file pointer.h.

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 620 of file pointer.h.

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 643 of file pointer.h.

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 649 of file pointer.h.

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 655 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
template<bool uriFragment, typename OutputStream >
bool GenericPointer< ValueType, Allocator >::Stringify ( OutputStream &  os) const
inlineprivate

Stringify to string or URI fragment representation.

Template Parameters
uriFragmentTrue for stringifying to URI fragment representation. False for string representation.
OutputStreamtype of output stream.
Parameters
osThe output stream.

Definition at line 941 of file pointer.h.

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 692 of file pointer.h.

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 698 of file pointer.h.

Member Data Documentation

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

Definition at line 242 of file pointer.h.

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

The current allocator. It is either user-supplied or equal to ownAllocator_.

Definition at line 1039 of file pointer.h.

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

Definition at line 591 of file pointer.h.

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 637 of file pointer.h.

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

Definition at line 673 of file pointer.h.

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

Definition at line 591 of file pointer.h.

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

Definition at line 673 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
Ch* GenericPointer< ValueType, Allocator >::nameBuffer_
private

A buffer containing all names in tokens.

Definition at line 1041 of file pointer.h.

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

Allocator owned by this Pointer.

Definition at line 1040 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
PointerParseErrorCode GenericPointer< ValueType, Allocator >::parseErrorCode_
private

Parsing error code.

Definition at line 1045 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
size_t GenericPointer< ValueType, Allocator >::parseErrorOffset_
private

Offset in code unit when parsing fail.

Definition at line 1044 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
size_t GenericPointer< ValueType, Allocator >::tokenCount_
private

Number of tokens in tokens_.

Definition at line 1043 of file pointer.h.

template<typename ValueType, typename Allocator = CrtAllocator>
Token* GenericPointer< ValueType, Allocator >::tokens_
private

A list of tokens.

Definition at line 1042 of file pointer.h.

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

Definition at line 637 of file pointer.h.


The documentation for this class was generated from the following files:


choreo_rapidjson
Author(s):
autogenerated on Thu Jul 18 2019 03:59:10