Open Lighting Architecture: ola::web::JsonObject Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
Public Member Functions | List of all members
ola::web::JsonObject Class Reference
JSON

## 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:

## Public Member Functions
| JsonObject ()
| Create a new JsonObject.
JsonValue * | LookupElementWithIter (JsonPointer::Iterator *iter)
| Lookup the Value referred to by the Iterator.
bool | operator== (const JsonValue &other) const
| Equality operator.
bool | Equals (const JsonObject &other) const
| Check if this JsonValue equals a JsonObject.
void | Add (const std::string &key, const std::string &value)
| Add a key to string mapping.
void | Add (const std::string &key, const char *value)
| Set the given key to a string value.
void | Add (const std::string &key, unsigned int i)
| Set the given key to a unsigned int value.
void | Add (const std::string &key, int i)
| Set the given key to a int value.
void | Add (const std::string &key, double d)
| Set the given key to a double value.
void | Add (const std::string &key, bool value)
| Set the given key to a bool value.
void | Add (const std::string &key)
| Set the given key to a null value.
JsonObject * | AddObject (const std::string &key)
| Set the given key to a JsonObject.
class JsonArray * | AddArray (const std::string &key)
| Set the given key to a JsonArray.
void | AddValue (const std::string &key, JsonValue *value)
| Set the key to the supplied JsonValue.
void | AddRaw (const std::string &key, const std::string &value)
| Set the given key to a raw value.
bool | Remove (const std::string &key)
| Remove the JsonValue with the specified key.
bool | ReplaceValue (const std::string &key, JsonValue *value)
| Replace the key with the supplied JsonValue.
void | Accept (JsonValueVisitorInterface *visitor)
| The Accept method for the visitor pattern.
void | Accept (JsonValueConstVisitorInterface *visitor) const
| The Accept (const) method for the visitor pattern.
JsonValue * | Clone () const
| Make a copy of this JsonValue.
bool | IsEmpty () const
| Check if there are properties within the object.
unsigned int | Size () const
void | VisitProperties (JsonObjectPropertyVisitor *visitor) const
| Visit each of the properties in this object.
Public Member Functions inherited from ola::web::JsonValue
virtual JsonValue * | LookupElement (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 | ( | 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.

## ◆ Accept() [2/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.

## ◆ Add() [1/7]

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

Set the given key to a null value.

Parameters

  key | the key to set.

## ◆ Add() [2/7]

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

Set the given key to a bool value.

Parameters

  key | the key to set.
  value | the value to add

## ◆ Add() [3/7]

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

Set the given key to a string value.

Parameters

  key | the key to set.
  value | the value to add

## ◆ Add() [4/7]

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

Add a key to string mapping.

Parameters

  key | the key to set.
  value | the 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

  key | the key to set.
  d | the value to add

## ◆ Add() [6/7]

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

Set the given key to a int value.

Parameters

  key | the key to set.
  i | the value to add

## ◆ Add() [7/7]

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

Set the given key to a unsigned int value.

Parameters

  key | the key to set.
  i | the value to add

## ◆ AddArray()

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

Set the given key to a JsonArray.

Parameters

  key | the 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

  key | the 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

  key | the key to add
  value | the raw value to append.

## ◆ AddValue()

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

Set the key to the supplied JsonValue.

Parameters

  key | the key to add
  value | the JsonValue object, ownership is transferred.

## ◆ Clone()

JsonValue * ola::web::JsonObject::Clone | ( |  | ) | const
| virtual

Make a copy of this JsonValue.

Implements ola::web::JsonValue.

## ◆ 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

  key | the 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

  key | the key to add.
  value | the 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:

- include/ola/web/Json.h
- common/web/Json.cpp