全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
rapidjson::GenericPointer< ValueType, Allocator > 模板类 参考

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

#include <pointer.h>

struct  Token
 A token is the basic units of internal representation. 更多...
 

Public 类型

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

Public 成员函数

bool Erase (ValueType &root) const
 Erase a value in a subtree. 更多...
 
Constructors and destructor.
 GenericPointer ()
 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 ()
 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 >
GenericPointer Append (T *name, Allocator *allocator=0) const
 Append a name token without length, and return a new Pointer. 更多...
 
GenericPointer Append (const std::basic_string< Ch > &name, Allocator *allocator=0) const
 Append a name token, and return a new Pointer. 更多...
 
GenericPointer Append (SizeType index, Allocator *allocator=0) const
 Append a index token, and return a new Pointer. 更多...
 
GenericPointer Append (const ValueType &token, Allocator *allocator=0) const
 Append a token by value, and return a new Pointer. 更多...
 
Handling Parse Error
bool IsValid () const
 Check whether this is a valid pointer.
 
size_t GetParseErrorOffset () const
 Get the parsing error offset in code unit.
 
PointerParseErrorCode GetParseErrorCode () const
 Get the parsing error code.
 
Tokens
const TokenGetTokens () const
 Get the token array (const version only).
 
size_t GetTokenCount () const
 Get the number of tokens.
 
Equality/inequality operators
bool operator== (const GenericPointer &rhs) const
 Equality operator. 更多...
 
bool operator!= (const GenericPointer &rhs) const
 Inequality operator. 更多...
 
Stringify
template<typename OutputStream >
bool Stringify (OutputStream &os) const
 Stringify the pointer into string representation. 更多...
 
template<typename OutputStream >
bool StringifyUriFragment (OutputStream &os) const
 Stringify the pointer into URI fragment representation. 更多...
 
Create value
ValueType & Create (ValueType &root, typename ValueType::AllocatorType &allocator, bool *alreadyExist=0) const
 Create a value in a subtree. 更多...
 
template<typename stackAllocator >
ValueType & Create (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, bool *alreadyExist=0) const
 Creates a value in a document. 更多...
 
Query value
ValueType * Get (ValueType &root) const
 Query a value in a subtree. 更多...
 
const ValueType * Get (const ValueType &root) const
 Query a const value in a const subtree. 更多...
 
Query a value with default
ValueType & GetWithDefault (ValueType &root, const ValueType &defaultValue, typename ValueType::AllocatorType &allocator) const
 Query a value in a subtree with default value. 更多...
 
ValueType & GetWithDefault (ValueType &root, const Ch *defaultValue, typename ValueType::AllocatorType &allocator) const
 Query a value in a subtree with default null-terminated string.
 
ValueType & GetWithDefault (ValueType &root, const std::basic_string< Ch > &defaultValue, typename ValueType::AllocatorType &allocator) const
 Query a value in a subtree with default std::basic_string.
 
template<typename T >
ValueType & GetWithDefault (ValueType &root, T defaultValue, typename ValueType::AllocatorType &allocator) const
 Query a value in a subtree with default primitive value. 更多...
 
template<typename stackAllocator >
ValueType & GetWithDefault (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const ValueType &defaultValue) const
 Query a value in a document with default value.
 
template<typename stackAllocator >
ValueType & GetWithDefault (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *defaultValue) const
 Query a value in a document with default null-terminated string.
 
template<typename stackAllocator >
ValueType & GetWithDefault (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const std::basic_string< Ch > &defaultValue) const
 Query a value in a document with default std::basic_string.
 
template<typename T , typename stackAllocator >
ValueType & GetWithDefault (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, T defaultValue) const
 Query a value in a document with default primitive value. 更多...
 
Set a value
ValueType & Set (ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
 Set a value in a subtree, with move semantics. 更多...
 
ValueType & Set (ValueType &root, const ValueType &value, typename ValueType::AllocatorType &allocator) const
 Set a value in a subtree, with copy semantics.
 
ValueType & Set (ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const
 Set a null-terminated string in a subtree.
 
ValueType & Set (ValueType &root, const std::basic_string< Ch > &value, typename ValueType::AllocatorType &allocator) const
 Set a std::basic_string in a subtree.
 
template<typename T >
ValueType & Set (ValueType &root, T value, typename ValueType::AllocatorType &allocator) const
 Set a primitive value in a subtree. 更多...
 
template<typename stackAllocator >
ValueType & Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
 Set a value in a document, with move semantics.
 
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.
 
template<typename stackAllocator >
ValueType & Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *value) const
 Set a null-terminated string in a document.
 
template<typename stackAllocator >
ValueType & Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const std::basic_string< Ch > &value) const
 Sets a std::basic_string in a document.
 
template<typename T , typename stackAllocator >
ValueType & Set (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, T value) const
 Set a primitive value in a document. 更多...
 
Swap a value
ValueType & Swap (ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
 Swap a value with a value in a subtree. 更多...
 
template<typename stackAllocator >
ValueType & Swap (GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
 Swap a value with a value in a document.
 

详细描述

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.

构造及析构函数说明

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

成员函数说明

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

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.
template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer rapidjson::GenericPointer< ValueType, Allocator >::Append ( const std::basic_string< Ch > &  name,
Allocator allocator = 0 
) const
inline

Append a name token, and return a new Pointer.

参数
nameName to be appended.
allocatorAllocator for the newly return Pointer.
返回
A new Pointer with appended token.
template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer rapidjson::GenericPointer< ValueType, Allocator >::Append ( SizeType  index,
Allocator allocator = 0 
) const
inline

Append a index token, and return a new Pointer.

参数
indexIndex to be appended.
allocatorAllocator for the newly return Pointer.
返回
A new Pointer with appended token.
template<typename ValueType, typename Allocator = CrtAllocator>
GenericPointer rapidjson::GenericPointer< ValueType, Allocator >::Append ( const ValueType &  token,
Allocator allocator = 0 
) const
inline

Append a token by value, and return a new Pointer.

参数
valueValue (either Uint or String) to be appended.
allocatorAllocator for the newly return Pointer.
返回
A new Pointer with appended token.
template<typename ValueType, typename Allocator = CrtAllocator>
ValueType& rapidjson::GenericPointer< ValueType, Allocator >::Create ( ValueType &  root,
typename ValueType::AllocatorType &  allocator,
bool *  alreadyExist = 0 
) const
inline

Create a value in a subtree.

If the value is not exist, it creates all parent values and a JSON Null value. So it always succeed and return the newly created or existing value.

Remind that it may change types of parents according to tokens, so it potentially removes previously stored values. For example, if a document was an array, and "/foo" is used to create a value, then the document will be changed to an object, and all existing array elements are lost.

参数
rootRoot value of a DOM subtree to be resolved. It can be any value other than document root.
allocatorAllocator for creating the values if the specified value or its parents are not exist.
alreadyExistIf non-null, it stores whether the resolved value is already exist.
返回
The resolved newly created (a JSON Null value), or already exists value.
template<typename ValueType, typename Allocator = CrtAllocator>
template<typename stackAllocator >
ValueType& rapidjson::GenericPointer< ValueType, Allocator >::Create ( GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &  document,
bool *  alreadyExist = 0 
) const
inline

Creates a value in a document.

参数
documentA document to be resolved.
allocatorAllocator for creating the values if the specified value or its parents are not exist.
alreadyExistIf non-null, it stores whether the resolved value is already exist.
返回
The resolved newly created, or already exists value.
template<typename ValueType, typename Allocator = CrtAllocator>
bool rapidjson::GenericPointer< ValueType, Allocator >::Erase ( ValueType &  root) const
inline

Erase a value in a subtree.

参数
rootRoot value of a DOM sub-tree to be resolved. It can be any value other than document root.
返回
Whether the resolved value is found and erased.
注解
Erasing with an empty pointer Pointer(""), i.e. the root, always fail and return false.
template<typename ValueType, typename Allocator = CrtAllocator>
ValueType* rapidjson::GenericPointer< ValueType, Allocator >::Get ( ValueType &  root) const
inline

Query a value in a subtree.

参数
rootRoot value of a DOM sub-tree to be resolved. It can be any value other than document root.
返回
Pointer to the value if it can be resolved. Otherwise null.
template<typename ValueType, typename Allocator = CrtAllocator>
const ValueType* rapidjson::GenericPointer< ValueType, Allocator >::Get ( const ValueType &  root) const
inline

Query a const value in a const subtree.

参数
rootRoot value of a DOM sub-tree to be resolved. It can be any value other than document root.
返回
Pointer to the value if it can be resolved. Otherwise null.
template<typename ValueType, typename Allocator = CrtAllocator>
ValueType& rapidjson::GenericPointer< ValueType, Allocator >::GetWithDefault ( ValueType &  root,
const ValueType &  defaultValue,
typename ValueType::AllocatorType &  allocator 
) const
inline

Query a value in a subtree with default value.

Similar to Get(), but if the specified value do not exists, it creates all parents and clone the default value. So that this function always succeed.

参数
rootRoot value of a DOM sub-tree to be resolved. It can be any value other than document root.
defaultValueDefault value to be cloned if the value was not exists.
allocatorAllocator for creating the values if the specified value or its parents are not exist.
参见
Create()
template<typename ValueType, typename Allocator = CrtAllocator>
template<typename T >
ValueType& rapidjson::GenericPointer< ValueType, Allocator >::GetWithDefault ( ValueType &  root,
defaultValue,
typename ValueType::AllocatorType &  allocator 
) const
inline

Query a value in a subtree with default primitive value.

模板参数
T
TEither Type, int, unsigned, int64_t, uint64_t, bool
template<typename ValueType, typename Allocator = CrtAllocator>
template<typename T , typename stackAllocator >
ValueType& rapidjson::GenericPointer< ValueType, Allocator >::GetWithDefault ( GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &  document,
defaultValue 
) const
inline

Query a value in a document with default primitive value.

模板参数
T
TEither Type, int, unsigned, int64_t, uint64_t, bool
template<typename ValueType, typename Allocator = CrtAllocator>
bool rapidjson::GenericPointer< ValueType, Allocator >::operator!= ( const GenericPointer< ValueType, Allocator > &  rhs) const
inline

Inequality operator.

注解
When any pointers are invalid, always returns true.
template<typename ValueType, typename Allocator = CrtAllocator>
bool rapidjson::GenericPointer< ValueType, Allocator >::operator== ( const GenericPointer< ValueType, Allocator > &  rhs) const
inline

Equality operator.

注解
When any pointers are invalid, always returns false.
template<typename ValueType, typename Allocator = CrtAllocator>
ValueType& rapidjson::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.

参数
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.
参见
Create()
template<typename ValueType, typename Allocator = CrtAllocator>
template<typename T >
ValueType& rapidjson::GenericPointer< ValueType, Allocator >::Set ( ValueType &  root,
value,
typename ValueType::AllocatorType &  allocator 
) const
inline

Set a primitive value in a subtree.

模板参数
T
TEither Type, int, unsigned, int64_t, uint64_t, bool
template<typename ValueType, typename Allocator = CrtAllocator>
template<typename T , typename stackAllocator >
ValueType& rapidjson::GenericPointer< ValueType, Allocator >::Set ( GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &  document,
value 
) const
inline

Set a primitive value in a document.

模板参数
T
TEither Type, int, unsigned, int64_t, uint64_t, bool
template<typename ValueType, typename Allocator = CrtAllocator>
template<typename OutputStream >
bool rapidjson::GenericPointer< ValueType, Allocator >::Stringify ( OutputStream &  os) const
inline

Stringify the pointer into string representation.

模板参数
OutputStreamType of output stream.
参数
osThe output stream.
template<typename ValueType, typename Allocator = CrtAllocator>
template<typename OutputStream >
bool rapidjson::GenericPointer< ValueType, Allocator >::StringifyUriFragment ( OutputStream &  os) const
inline

Stringify the pointer into URI fragment representation.

模板参数
OutputStreamType of output stream.
参数
osThe output stream.
template<typename ValueType, typename Allocator = CrtAllocator>
ValueType& rapidjson::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.

参数
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.
参见
Create()

该类的文档由以下文件生成: