GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Classes | Public Types | List of all members
GenericPointer< ValueType, Allocator > Class Template Reference

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

#include <pointer.h>

Classes

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

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. 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.
 
 ~GenericPointer ()
 Destructor.
 
GenericPointeroperator= (const GenericPointer &rhs)
 Assignment operator.
 

Append token

Allocatorallocator
 
Allocator stackAllocator stackAllocator & document
 
Allocator stackAllocator stackAllocator T defaultValue const
 
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...
 
Allocator stackAllocator RAPIDJSON_DISABLEIF_RETURN ((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) GetWithDefault(GenericDocument< EncodingType
 

Set a value

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.
 
ValueType & Set (ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const
 Set a null-terminated string in a subtree.
 
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.
 
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 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...
 

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.
 
bool Erase (ValueType &root) const
 Erase a value in a subtree. 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.

Constructor & Destructor Documentation

◆ GenericPointer() [1/3]

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.

◆ GenericPointer() [2/3]

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.

◆ GenericPointer() [3/3]

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
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: pointer.h:81
A token is the basic units of internal representation.
Definition: pointer.h:99

Member Function Documentation

◆ Append() [1/2]

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.

◆ Append() [2/2]

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.

◆ Erase()

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.

◆ RAPIDJSON_DISABLEIF_RETURN() [1/3]

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.

◆ RAPIDJSON_DISABLEIF_RETURN() [2/3]

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

◆ RAPIDJSON_DISABLEIF_RETURN() [3/3]

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

◆ Set()

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()

◆ Swap()

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()

Member Data Documentation

◆ const [1/3]

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

◆ const [2/3]

template<typename ValueType , typename Allocator = CrtAllocator>
T ValueType::AllocatorType& allocator GenericPointer< ValueType, Allocator >::const
Initial value:
{
return Create(root, allocator) = ValueType(value).Move()

◆ const [3/3]

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

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