Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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:
ola::web::JsonValue

Public Member Functions

 JsonObject ()
 Create a new JsonObject.
JsonValueLookupElementWithIter (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.
JsonObjectAddObject (const std::string &key)
 Set the given key to a JsonObject.
class JsonArrayAddArray (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.
JsonValueClone () 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 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

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.

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.

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.
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
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
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
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
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
void ola::web::JsonObject::Add ( const std::string &  key)

Set the given key to a null value.

Parameters
keythe key to set.
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.
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.
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.
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.
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.

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

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.

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

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: