IN2OSM  1.0.1
GenericPointer< ValueType, Allocator >

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

#include <fwd.h>

Collaboration diagram for GenericPointer< ValueType, Allocator >:
Collaboration graph

Classes

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

Public Member Functions

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

Public Attributes

Allocator * allocator
 
Allocator * allocator_
 The current allocator. It is either user-supplied or equal to ownAllocator_. More...
 
Allocator * ownAllocator_
 Allocator owned by this Pointer. More...
 
ChnameBuffer_
 A buffer containing all names in tokens. More...
 
Tokentokens_
 A list of tokens. More...
 
size_t tokenCount_
 Number of tokens in tokens_. More...
 
size_t parseErrorOffset_
 Offset in code unit when parsing fail. More...
 
PointerParseErrorCode parseErrorCode_
 Parsing error code. More...
 

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

◆ Ch

typedef ValueType::Ch Ch

Character type from Value.

Definition at line 82 of file pointer.h.

◆ EncodingType

typedef ValueType::EncodingType EncodingType

Encoding type from Value.

Definition at line 81 of file pointer.h.

Constructor & Destructor Documentation

◆ GenericPointer() [1/6]

GenericPointer ( Allocator *  allocator = 0)
inline

Default constructor.

Definition at line 107 of file pointer.h.

Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
The parse is successful.
Definition: pointer.h:38
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
Allocator * allocator
Definition: pointer.h:275
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103
Here is the caller graph for this function:

◆ GenericPointer() [2/6]

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

115  Parse(source, internal::StrLen(source));
116  }
const CharType(& source)[N]
Definition: pointer.h:1204
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
The parse is successful.
Definition: pointer.h:38
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
Allocator * allocator
Definition: pointer.h:275
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
Here is the call graph for this function:

◆ GenericPointer() [3/6]

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

138  Parse(source, length);
139  }
const CharType(& source)[N]
Definition: pointer.h:1204
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
The parse is successful.
Definition: pointer.h:38
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
Allocator * allocator
Definition: pointer.h:275
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103

◆ GenericPointer() [4/6]

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

163 : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
The parse is successful.
Definition: pointer.h:38
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103

◆ GenericPointer() [5/6]

GenericPointer ( const GenericPointer< ValueType, Allocator > &  rhs)
inline

Copy constructor.

Definition at line 166 of file pointer.h.

167  *this = rhs;
168  }
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
The parse is successful.
Definition: pointer.h:38
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103

◆ GenericPointer() [6/6]

GenericPointer ( const GenericPointer< ValueType, Allocator > &  rhs,
Allocator *  allocator 
)
inline

Copy constructor.

Definition at line 171 of file pointer.h.

172  *this = rhs;
173  }
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
The parse is successful.
Definition: pointer.h:38
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
Allocator * allocator
Definition: pointer.h:275
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103

◆ ~GenericPointer()

~GenericPointer ( )
inline

Destructor.

Definition at line 176 of file pointer.h.

176  {
177  if (nameBuffer_) // If user-supplied tokens constructor is used, nameBuffer_ is nullptr and tokens_ are not deallocated.
178  Allocator::Free(tokens_);
180  }
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:629
Token * tokens_
A list of tokens.
Definition: pointer.h:1102

Member Function Documentation

◆ Append() [1/2]

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

244  {
245  GenericPointer r;
246  r.allocator_ = allocator;
247  Ch *p = r.CopyFromRaw(*this, 1, token.length + 1);
248  std::memcpy(p, token.name, (token.length + 1) * sizeof(Ch));
249  r.tokens_[tokenCount_].name = p;
250  r.tokens_[tokenCount_].length = token.length;
251  r.tokens_[tokenCount_].index = token.index;
252  return r;
253  }
SizeType length
Length of the name.
Definition: pointer.h:99
const Ch * name
Name of the token. It has null character at the end but it can contain null character.
Definition: pointer.h:98
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: fwd.h:126
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
SizeType index
A valid array index, if it is not equal to kPointerInvalidIndex.
Definition: pointer.h:100
Allocator * allocator
Definition: pointer.h:275
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103
ValueType::Ch Ch
Character type from Value.
Definition: pointer.h:82
Here is the caller graph for this function:

◆ Append() [2/2]

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

262  {
263  Token token = { name, length, kPointerInvalidIndex };
264  return Append(token, allocator);
265  }
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Append a token and return a new Pointer.
Definition: pointer.h:244
static RAPIDJSON_NAMESPACE_BEGIN const SizeType kPointerInvalidIndex
Represents an invalid index in GenericPointer::Token.
Definition: pointer.h:31
Allocator * allocator
Definition: pointer.h:275
Here is the call graph for this function:

◆ operator=()

GenericPointer& operator= ( const GenericPointer< ValueType, Allocator > &  rhs)
inline

Assignment operator.

Definition at line 183 of file pointer.h.

183  {
184  if (this != &rhs) {
185  // Do not delete ownAllcator
186  if (nameBuffer_)
187  Allocator::Free(tokens_);
188 
189  tokenCount_ = rhs.tokenCount_;
192 
193  if (rhs.nameBuffer_)
194  CopyFromRaw(rhs); // Normally parsed tokens.
195  else {
196  tokens_ = rhs.tokens_; // User supplied const tokens.
197  nameBuffer_ = 0;
198  }
199  }
200  return *this;
201  }
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103

◆ RAPIDJSON_DISABLEIF_RETURN()

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.
Here is the caller graph for this function:

◆ Swap()

GenericPointer& Swap ( GenericPointer< ValueType, Allocator > &  other)
inline

Swap the content of this pointer with an other.

Parameters
otherThe pointer to swap with.
Note
Constant complexity.

Definition at line 208 of file pointer.h.

208  {
216  return *this;
217  }
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1100
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1099
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1104
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1101
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1105
Token * tokens_
A list of tokens.
Definition: pointer.h:1102
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1103
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ swap

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);
// ...
}
See also
Swap()

Definition at line 231 of file pointer.h.

231 { a.Swap(b); }
GenericPointer & Swap(GenericPointer &other) RAPIDJSON_NOEXCEPT
Swap the content of this pointer with an other.
Definition: pointer.h:208

Member Data Documentation

◆ allocator

Allocator* allocator

Definition at line 275 of file pointer.h.

◆ allocator_

Allocator* allocator_

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

Definition at line 1099 of file pointer.h.

◆ nameBuffer_

Ch* nameBuffer_

A buffer containing all names in tokens.

Definition at line 1101 of file pointer.h.

◆ ownAllocator_

Allocator* ownAllocator_

Allocator owned by this Pointer.

Definition at line 1100 of file pointer.h.

◆ parseErrorCode_

PointerParseErrorCode parseErrorCode_

Parsing error code.

Definition at line 1105 of file pointer.h.

◆ parseErrorOffset_

size_t parseErrorOffset_

Offset in code unit when parsing fail.

Definition at line 1104 of file pointer.h.

◆ tokenCount_

size_t tokenCount_

Number of tokens in tokens_.

Definition at line 1103 of file pointer.h.

◆ tokens_

Token* tokens_

A list of tokens.

Definition at line 1102 of file pointer.h.


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