VR-Vantage 2.7 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Public Attributes
GenericPointer< ValueType, Allocator > Class Template Reference

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

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

Public Member Functions

Allocator stackAllocator RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) GetWithDefault(GenericDocument< EncodingType
stackAllocator RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) Set(GenericDocument< EncodingType
OutputStream bool Stringify (OutputStream &os) const
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.
GenericPointeroperator= (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 >
 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.

Public Attributes

Allocator * allocator
Allocator stackAllocator
stackAllocator & 
document
stackAllocator stackAllocator & document
Allocator * allocator_
 The current allocator. It is either user-supplied or equal to ownAllocator_.
Allocator * ownAllocator_
 Allocator owned by this Pointer.
ChnameBuffer_
 A buffer containing all names in tokens.
Tokentokens_
 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.

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.

Member Typedef Documentation

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

Encoding type from Value.

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

Character type from Value.

Constructor & Destructor Documentation

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

Default constructor.

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.

References internal::StrLen().

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.
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
template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer< ValueType, Allocator >::GenericPointer ( const GenericPointer< ValueType, Allocator > &  rhs,
Allocator *  allocator = 0 
)
inline

Copy constructor.

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

Member Function Documentation

template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer& GenericPointer< ValueType, Allocator >::operator= ( const GenericPointer< ValueType, Allocator > &  rhs)
inline
template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer GenericPointer< ValueType, Allocator >::Append ( const Token token,
Allocator *  allocator = 0 
) const
inline
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.

References GenericPointer< ValueType, Allocator >::allocator, and GenericPointer< ValueType, Allocator >::Append().

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>
stackAllocator GenericPointer< ValueType, Allocator >::RAPIDJSON_DISABLEIF_RETURN ( (internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >)  ,
(ValueType &)   
)
template<typename ValueType, typename Allocator = CrtAllocator>
OutputStream bool GenericPointer< ValueType, Allocator >::Stringify ( OutputStream &  os) const
inline

Member Data Documentation

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

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

Referenced by GenericPointer< ValueType, Allocator >::Append().

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

Allocator owned by this Pointer.

Referenced by GenericPointer< ValueType, Allocator >::~GenericPointer().

template<typename ValueType, typename Allocator = CrtAllocator>
Ch* GenericPointer< ValueType, Allocator >::nameBuffer_
template<typename ValueType, typename Allocator = CrtAllocator>
Token* GenericPointer< ValueType, Allocator >::tokens_
template<typename ValueType, typename Allocator = CrtAllocator>
size_t GenericPointer< ValueType, Allocator >::tokenCount_
template<typename ValueType, typename Allocator = CrtAllocator>
size_t GenericPointer< ValueType, Allocator >::parseErrorOffset_

Offset in code unit when parsing fail.

Referenced by GenericPointer< ValueType, Allocator >::operator=().

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

Parsing error code.

Referenced by GenericPointer< ValueType, Allocator >::operator=().


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


Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)