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

Detailed Description

A JSON object. JSON Objects are key : value mappings, similar to dictionaries in Python.

If the same key is added more than once, the latest value wins.

Todo:
Since key names tend to reuse the same strings, it would be nice to intern the strings here. That's a future optimization for someone.
Inheritance diagram for ola::web::JsonObject:
Inheritance graph
[legend]
Collaboration diagram for ola::web::JsonObject:
Collaboration graph
[legend]

Public Member Functions

 JsonObject ()
 Create a new JsonObject.
 
JsonValueLookupElementWithIter (JsonPointer::Iterator *iter)
 Lookup the Value referred to by the Iterator. More...
 
bool operator== (const JsonValue &other) const
 Equality operator. More...
 
bool Equals (const JsonObject &other) const
 Check if this JsonValue equals a JsonObject. More...
 
void Add (const std::string &key, const std::string &value)
 Add a key to string mapping. More...
 
void Add (const std::string &key, const char *value)
 Set the given key to a string value. More...
 
void Add (const std::string &key, unsigned int i)
 Set the given key to a unsigned int value. More...
 
void Add (const std::string &key, int i)
 Set the given key to a int value. More...
 
void Add (const std::string &key, double d)
 Set the given key to a double value. More...
 
void Add (const std::string &key, bool value)
 Set the given key to a bool value. More...
 
void Add (const std::string &key)
 Set the given key to a null value. More...
 
JsonObjectAddObject (const std::string &key)
 Set the given key to a JsonObject. More...
 
class JsonArrayAddArray (const std::string &key)
 Set the given key to a JsonArray. More...
 
void AddValue (const std::string &key, JsonValue *value)
 Set the key to the supplied JsonValue. More...
 
void AddRaw (const std::string &key, const std::string &value)
 Set the given key to a raw value. More...
 
bool Remove (const std::string &key)
 Remove the JsonValue with the specified key. More...
 
bool ReplaceValue (const std::string &key, JsonValue *value)
 Replace the key with the supplied JsonValue. More...
 
void Accept (JsonValueVisitorInterface *visitor)
 The Accept method for the visitor pattern. More...
 
void Accept (JsonValueConstVisitorInterface *visitor) const
 The Accept (const) method for the visitor pattern. More...
 
JsonValueClone () const
 Make a copy of this JsonValue.
 
bool IsEmpty () const
 Check if there are properties within the object. More...
 
unsigned int Size () const
 
void VisitProperties (JsonObjectPropertyVisitor *visitor) const
 Visit each of the properties in this object. More...
 
- Public Member Functions inherited from ola::web::JsonValue
virtual JsonValueLookupElement (const JsonPointer &pointer)
 Locate the JsonValue referred to by the JSON Pointer.
 
virtual bool operator!= (const JsonValue &other) const
 Not-equals operator.
 

Member Function Documentation

◆ Accept() [1/2]

void ola::web::JsonObject::Accept ( JsonValueVisitorInterface visitor)
inlinevirtual

The Accept method for the visitor pattern.

This can be used to traverse the Json Tree in a type-safe manner.

Implements ola::web::JsonValue.

◆ Accept() [2/2]

void ola::web::JsonObject::Accept ( JsonValueConstVisitorInterface visitor) const
inlinevirtual

The Accept (const) method for the visitor pattern.

This can be used to traverse the Json Tree in a type-safe manner.

Implements ola::web::JsonValue.

◆ Add() [1/7]

void ola::web::JsonObject::Add ( const std::string &  key,
const std::string &  value 
)

Add a key to string mapping.

Parameters
keythe key to set.
valuethe value to add.

◆ Add() [2/7]

void ola::web::JsonObject::Add ( const std::string &  key,
const char *  value 
)

Set the given key to a string value.

Parameters
keythe key to set.
valuethe value to add

◆ Add() [3/7]

void ola::web::JsonObject::Add ( const std::string &  key,
unsigned int  i 
)

Set the given key to a unsigned int value.

Parameters
keythe key to set.
ithe value to add

◆ Add() [4/7]

void ola::web::JsonObject::Add ( const std::string &  key,
int  i 
)

Set the given key to a int value.

Parameters
keythe key to set.
ithe value to add

◆ Add() [5/7]

void ola::web::JsonObject::Add ( const std::string &  key,
double  d 
)

Set the given key to a double value.

Parameters
keythe key to set.
dthe value to add

◆ Add() [6/7]

void ola::web::JsonObject::Add ( const std::string &  key,
bool  value 
)

Set the given key to a bool value.

Parameters
keythe key to set.
valuethe value to add

◆ Add() [7/7]

void ola::web::JsonObject::Add ( const std::string &  key)

Set the given key to a null value.

Parameters
keythe key to set.

◆ AddArray()

JsonArray * ola::web::JsonObject::AddArray ( const std::string &  key)

Set the given key to a JsonArray.

Parameters
keythe key to add
Returns
the new JsonObject.

◆ AddObject()

JsonObject * ola::web::JsonObject::AddObject ( const std::string &  key)

Set the given key to a JsonObject.

Parameters
keythe key to add
Returns
the new JsonObject.

◆ AddRaw()

void ola::web::JsonObject::AddRaw ( const std::string &  key,
const std::string &  value 
)

Set the given key to a raw value.

Parameters
keythe key to add
valuethe raw value to append.

◆ AddValue()

void ola::web::JsonObject::AddValue ( const std::string &  key,
JsonValue value 
)

Set the key to the supplied JsonValue.

Parameters
keythe key to add
valuethe JsonValue object, ownership is transferred.

◆ Equals()

bool ola::web::JsonObject::Equals ( const JsonObject ) const
virtual

Check if this JsonValue equals a JsonObject.

Returns
true if the two values are equal, false otherwise.

Reimplemented from ola::web::JsonValue.

◆ IsEmpty()

bool ola::web::JsonObject::IsEmpty ( ) const
inline

Check if there are properties within the object.

Returns
true if the object is empty, false if there are properties.

◆ LookupElementWithIter()

JsonValue * ola::web::JsonObject::LookupElementWithIter ( JsonPointer::Iterator iterator)
virtual

Lookup the Value referred to by the Iterator.

This is used by recursively by JsonValue classes. You should call LookupElement() instead.

Implements ola::web::JsonValue.

◆ operator==()

bool ola::web::JsonObject::operator== ( const JsonValue other) const
inlinevirtual

Equality operator.

This implements equality as defined in section 3.6 of the JSON Schema Core document.

Implements ola::web::JsonValue.

◆ Remove()

bool ola::web::JsonObject::Remove ( const std::string &  key)

Remove the JsonValue with the specified key.

Parameters
keythe key to remove
Returns
true if the key existed and was removed, false otherwise.

◆ ReplaceValue()

bool ola::web::JsonObject::ReplaceValue ( const std::string &  key,
JsonValue value 
)

Replace the key with the supplied JsonValue.

Parameters
keythe key to add.
valuethe JsonValue object, ownership is transferred.
Returns
true if the key was replaced, false otherwise.

If the key was not replaced, the value is deleted.

◆ VisitProperties()

void ola::web::JsonObject::VisitProperties ( JsonObjectPropertyVisitor visitor) const

Visit each of the properties in this object.

For each property : value, the visitor is called.


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