rapidjson::GenericPointer< ValueType, Allocator > 模板类 参考

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

#include <pointer.h>

class  PercentEncodeStream
 A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence. 更多...
 
struct  Token
 A token is the basic units of internal representation. 更多...
 

Public 类型

typedef ValueType::EncodingType EncodingType
 Encoding type from Value
 
typedef ValueType::Ch Ch
 Character type from Value
 

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 std::basic_string< 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)
 Copy constructor.
 
 GenericPointer (const GenericPointer &rhs, Allocator *allocator)
 Copy constructor.
 
 ~GenericPointer ()
 Destructor.
 
GenericPointeroperator= (const GenericPointer &rhs)
 Assignment operator.
 
GenericPointerSwap (GenericPointer &other) RAPIDJSON_NOEXCEPT
 Swap the content of this pointer with an other. 更多...
 
void swap (GenericPointer &a, GenericPointer &b) RAPIDJSON_NOEXCEPT
 free-standing swap function helper 更多...
 

Append token

Allocatorallocator
 
Allocatorallocator_
 The current allocator. It is either user-supplied or equal to ownAllocator_.
 
AllocatorownAllocator_
 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.
 
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 更多...
 

详细描述

template<typename ValueType, typename Allocator = CrtAllocator>
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.

模板参数
ValueTypeThe value type of the DOM tree. E.g. GenericValue<UTF8<> >
AllocatorThe allocator type for allocating memory for internal representation.
注解
GenericPointer uses same encoding of ValueType. However, Allocator of GenericPointer is independent of Allocator of Value.

构造及析构函数说明

◆ GenericPointer() [1/4]

template<typename ValueType , typename Allocator = CrtAllocator>
rapidjson::GenericPointer< ValueType, Allocator >::GenericPointer ( const Ch source,
Allocator allocator = 0 
)
inlineexplicit

Constructor that parses a string or URI fragment representation.

参数
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.

◆ GenericPointer() [2/4]

template<typename ValueType , typename Allocator = CrtAllocator>
rapidjson::GenericPointer< ValueType, Allocator >::GenericPointer ( const std::basic_string< Ch > &  source,
Allocator allocator = 0 
)
inlineexplicit

Constructor that parses a string or URI fragment representation.

参数
sourceA 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.
注解
Requires the definition of the preprocessor symbol RAPIDJSON_HAS_STDSTRING.

◆ GenericPointer() [3/4]

template<typename ValueType , typename Allocator = CrtAllocator>
rapidjson::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.

参数
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.
注解
Slightly faster than the overload without length.

◆ GenericPointer() [4/4]

template<typename ValueType , typename Allocator = CrtAllocator>
rapidjson::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.

参数
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

成员函数说明

◆ Append() [1/2]

template<typename ValueType , typename Allocator = CrtAllocator>
GenericPointer rapidjson::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

参数
nameName to be appended.
lengthLength of name.
allocatorAllocator for the newly return Pointer.
返回
A new Pointer with appended token.

◆ Append() [2/2]

template<typename ValueType , typename Allocator = CrtAllocator>
GenericPointer rapidjson::GenericPointer< ValueType, Allocator >::Append ( const Token token,
Allocator allocator = 0 
) const
inline

Append a token and return a new Pointer

参数
tokenToken to be appended.
allocatorAllocator for the newly return Pointer.
返回
A new Pointer with appended token.

◆ RAPIDJSON_DISABLEIF_RETURN()

template<typename ValueType , typename Allocator = CrtAllocator>
template<typename T >
rapidjson::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

参数
nameName (const Ch*) to be appended.
allocatorAllocator for the newly return Pointer.
返回
A new Pointer with appended token.

◆ Swap()

template<typename ValueType , typename Allocator = CrtAllocator>
GenericPointer& rapidjson::GenericPointer< ValueType, Allocator >::Swap ( GenericPointer< ValueType, Allocator > &  other)
inline

Swap the content of this pointer with an other.

参数
otherThe pointer to swap with.
注解
Constant complexity.

友元及相关函数文档

◆ swap

template<typename ValueType , typename Allocator = CrtAllocator>
void swap ( GenericPointer< ValueType, Allocator > &  a,
GenericPointer< ValueType, Allocator > &  b 
)
friend

free-standing swap function helper

Helper function to enable support for common swap implementation pattern based on std::swap:

void swap(MyClass& a, MyClass& b) {
using std::swap;
swap(a.pointer, b.pointer);
// ...
}
参见
Swap()

该类的文档由以下文件生成:
rapidjson::Pointer
GenericPointer< Value, CrtAllocator > Pointer
GenericPointer for Value (UTF-8, default allocator).
Definition: fwd.h:126
rapidjson::GenericPointer::swap
friend void swap(GenericPointer &a, GenericPointer &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: pointer.h:231