Open Lighting Architecture  Latest Git
Classes | Public Member Functions | List of all members
ola::web::JsonPointer Class Reference

Detailed Description

A JSON pointer (RFC 6901) refers to a possible element in a JSON data structure.

The element referenced by the pointer may or may not exist.

Given the JSON:

{
"foo": {
"bar": 1,
"baz": true
},
"bat": [0, 1, 2]
}

The JSON pointers for each element are:

Classes

class  Iterator
 An iterator for traversing a JsonPointer. More...
 

Public Member Functions

 JsonPointer (const JsonPointer &other)
 
 JsonPointer (const std::string &path)
 Construct a new JsonPointer from a string representing the path. More...
 
bool operator== (const JsonPointer &other) const
 Equality operator.
 
bool IsValid () const
 Returns true if this pointer is valid. More...
 
Iterator begin () const
 Return an iterator pointing to the first token in the JsonPointer.
 
unsigned int TokenCount () const
 The number of tokens in the Json Pointer. More...
 
std::string TokenAt (unsigned int i) const
 Return the token at the specified index. More...
 
void Push (const std::string &token)
 Append a token to the pointer path. More...
 
void Pop ()
 Pop the last token from the pointer.
 
std::string ToString () const
 Returns the string representation of the pointer.
 
bool IsPrefixOf (const JsonPointer &other) const
 Check if this pointer is a prefix of another. More...
 

Constructor & Destructor Documentation

◆ JsonPointer()

ola::web::JsonPointer::JsonPointer ( const std::string &  path)
explicit

Construct a new JsonPointer from a string representing the path.

Parameters
pathA Json Pointer path. The path should either be empty, or start with a /.

Member Function Documentation

◆ IsPrefixOf()

bool ola::web::JsonPointer::IsPrefixOf ( const JsonPointer other) const

Check if this pointer is a prefix of another.

Parameters
otherthe JsonPointer to compare to.
Returns
true if this object is a prefix of the parameter.

◆ IsValid()

bool ola::web::JsonPointer::IsValid ( ) const
inline

Returns true if this pointer is valid.

Invalid pointers are ones that don't start with a /. If the pointer is invalid, the result of all other methods is undefined.

◆ Push()

void ola::web::JsonPointer::Push ( const std::string &  token)

Append a token to the pointer path.

Parameters
tokenThe un-escaped token to add to this JsonPointer.

◆ TokenAt()

std::string ola::web::JsonPointer::TokenAt ( unsigned int  i) const
inline

Return the token at the specified index.

Parameters
ithe index of the token to return.
Returns
the un-encoded representation of the token.

◆ TokenCount()

unsigned int ola::web::JsonPointer::TokenCount ( ) const
inline

The number of tokens in the Json Pointer.

A valid pointer has at least one token (""). The number of tokens is the number of / plus one.


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