Manages various property types and serialization. The PropertyManager provides functions to set, get, and manage different property types. It also supports serialization to and from JSON objects. More...
#include "PropertyManager.h"
Public Member Functions | |
PropertyManager () | |
Default constructor. | |
PropertyManager (const ConstJsonObject &_jsonObject) | |
Deserialize constructor. | |
PropertyManager (PropertyManager &&_other) noexcept | |
Move constructor. | |
virtual | ~PropertyManager () |
Destructor. | |
PropertyManager & | operator= (PropertyManager &&_other) noexcept |
Move assignment operator. | |
virtual void | addToJsonObject (ot::JsonValue &_object, ot::JsonAllocator &_allocator) const override |
Serializes the object to a JSON structure. | |
virtual void | setFromJsonObject (const ot::ConstJsonObject &_object) override |
Deserializes the object from a JSON structure. | |
virtual void | propertyChanged (const Property *_property) |
Will be called whenever a property has been changed. | |
virtual void | readingProperty (const std::string &_propertyGroupName, const std::string &_propertyName) const |
Will be called before a property will be read. | |
void | setSilenceNotifications (bool _silence) |
Set the notifications silenced. If set property access won't trigger any notification. | |
bool | getSilenceNotifications (void) const |
void | notifyAllChanged (void) |
Will call PropertyManager::propertyChanged for every property that is currently registered. Calling this method if the manager is currently silenced will have no effect. | |
ot::Property * | addProperty (const std::string &_groupName, Property *_property) |
Adds the property to the specified group. The property should not exist, an existing one will be replaced. | |
void | updateProperty (const std::string &_groupName, Property *_property) |
Updates an existing property or creates a new one. | |
void | mergeWith (const PropertyManager &_other, const PropertyBase::MergeMode &_mergeMode=PropertyBase::MergeValues) |
Merge the properties with the other manager. | |
void | updateProperty (const std::string &_groupName, const Property *_property, bool _deleteProvidedProperty) |
Updates an existing property or creates a new one. | |
PropertyBool * | setBool (const std::string &_groupName, const std::string &_valueName, bool _value) |
Sets boolean property. | |
PropertyInt * | setInt (const std::string &_groupName, const std::string &_valueName, int _value) |
Sets integer property. | |
PropertyDouble * | setDouble (const std::string &_groupName, const std::string &_valueName, double _value) |
Sets double property. | |
PropertyString * | setString (const std::string &_groupName, const std::string &_valueName, const std::string &_value) |
Sets string property. | |
PropertyStringList * | setStringList (const std::string &_groupName, const std::string &_valueName, const std::string &_value) |
Sets string property. | |
PropertyColor * | setColor (const std::string &_groupName, const std::string &_valueName, const Color &_value) |
Sets color property. | |
PropertyPainter2D * | setPainter2D (const std::string &_groupName, const std::string &_valueName, Painter2D *_painter) |
Sets painter property. | |
PropertyPainter2D * | setPainter2D (const std::string &_groupName, const std::string &_valueName, const Painter2D *_painter) |
Sets painter property. | |
PropertyPath * | setPath (const std::string &_groupName, const std::string &_valueName, const std::string &_path) |
Sets path property. | |
Property * | findProperty (const std::string &_groupName, const std::string &_valueName) |
Finds a property by group and name. | |
const Property * | findProperty (const std::string &_groupName, const std::string &_valueName) const |
Finds a property by group and name. | |
bool | getBool (const std::string &_groupName, const std::string &_valueName) const |
Retrieves boolean property value. | |
int | getInt (const std::string &_groupName, const std::string &_valueName) const |
Retrieves int property value. | |
double | getDouble (const std::string &_groupName, const std::string &_valueName) const |
Retrieves double property value. | |
const std::string & | getString (const std::string &_groupName, const std::string &_valueName) const |
Retrieves string property value. | |
const Color & | getColor (const std::string &_groupName, const std::string &_valueName) const |
Retrieves color property value. | |
const Painter2D * | getPainter2D (const std::string &_groupName, const std::string &_valueName) const |
Retrieves Painter2D property value. | |
const std::string & | getPath (const std::string &_groupName, const std::string &_valueName) const |
Retrieves path property value. | |
template<class T > | |
T * | getProperty (const std::string &_groupName, const std::string &_valueName) |
Finds a property by group and name. The found property will be casted to the specified type. | |
template<class T > | |
const T * | getProperty (const std::string &_groupName, const std::string &_valueName) const |
Finds a property by group and name. The found property will be casted to the specified type. | |
PropertyGridCfg | createGridConfiguration (void) const |
Creates a grid configuration that can be used to serialize or visualize the properties. | |
void | clear (void) |
Removes all groups and properties. | |
const std::map< std::string, PropertyGroup * > & | getData (void) const |
Return data that is managed by this property manager. | |
void | addNotifier (PropertyManagerNotifier *_notifier) |
Register property manager notifier. | |
PropertyManagerNotifier * | removeNotifier (PropertyManagerNotifier *_notifier, bool _destroyObject) |
Remove given notifier from this manager. | |
void | addReadCallbackNotifier (PropertyReadCallbackNotifier *_notifier) |
Add read callback notifier. The read callback notifier will receive read callbacks for the property under the currently set property path. The callback method is called before the property read operation starts. | |
void | removeReadCallbackNotifier (PropertyReadCallbackNotifier *_notifier) |
void | addWriteCallbackNotifier (PropertyWriteCallbackNotifierBase *_notifier) |
Add write callback notifier. The write callback notifier will receive write callbacks for the property under the currently set property path. The callback method is called after the property write operation finishes and before the. | |
void | removeWriteCallbackNotifier (PropertyWriteCallbackNotifierBase *_notifier) |
Remove write callback notifier. | |
![]() | |
Serializable () | |
Serializable (const Serializable &) | |
Serializable (Serializable &&) noexcept | |
virtual | ~Serializable () |
Serializable & | operator= (const Serializable &) |
Serializable & | operator= (Serializable &&) noexcept |
Protected Member Functions | |
virtual Property * | storeProperty (const std::string &_groupName, Property *_property) |
Stores a property within a specified group. | |
PropertyGroup * | findGroup (const std::string &_group) const |
Find an existing group by name. | |
PropertyGroup * | findOrCreateGroup (const std::string &_group) |
Find or create a group by name. | |
Manages various property types and serialization. The PropertyManager provides functions to set, get, and manage different property types. It also supports serialization to and from JSON objects.
ot::PropertyManager::PropertyManager | ( | ) |
Default constructor.
ot::PropertyManager::PropertyManager | ( | const ConstJsonObject & | _jsonObject | ) |
Deserialize constructor.
References setFromJsonObject().
|
noexcept |
Move constructor.
_other | The PropertyManager to move from. |
|
virtual |
Destructor.
void ot::PropertyManager::addNotifier | ( | PropertyManagerNotifier * | _notifier | ) |
Register property manager notifier.
_notifier | Notifier to add. |
References OTAssert, and OTAssertNullptr.
ot::Property * ot::PropertyManager::addProperty | ( | const std::string & | _groupName, |
Property * | _property ) |
Adds the property to the specified group. The property should not exist, an existing one will be replaced.
_groupName | Name of group to add property to. |
_property | Property to add. |
References ot::PropertyBase::getPropertyName(), and OTAssertNullptr.
void ot::PropertyManager::addReadCallbackNotifier | ( | PropertyReadCallbackNotifier * | _notifier | ) |
Add read callback notifier. The read callback notifier will receive read callbacks for the property under the currently set property path. The callback method is called before the property read operation starts.
_notifier | Notifier to add. PropertyReadCallbackNotifier |
References ot::PropertyReadCallbackNotifier::getPropertyPath(), OTAssert, and OTAssertNullptr.
|
overridevirtual |
Serializes the object to a JSON structure.
_object | The JSON object reference to populate. |
_allocator | The JSON allocator for memory management. |
Implements ot::Serializable.
void ot::PropertyManager::addWriteCallbackNotifier | ( | PropertyWriteCallbackNotifierBase * | _notifier | ) |
Add write callback notifier. The write callback notifier will receive write callbacks for the property under the currently set property path. The callback method is called after the property write operation finishes and before the.
_notifier | Notifier to add. PropertyWriteCallbackNotifierBase |
References ot::PropertyWriteCallbackNotifierBase::getPropertyPath(), OTAssert, and OTAssertNullptr.
void ot::PropertyManager::clear | ( | void | ) |
Removes all groups and properties.
ot::PropertyGridCfg ot::PropertyManager::createGridConfiguration | ( | void | ) | const |
Creates a grid configuration that can be used to serialize or visualize the properties.
References ot::PropertyGridCfg::addRootGroup().
|
protected |
Find an existing group by name.
_group | The group name. |
|
protected |
Find or create a group by name.
_group | The group name. |
ot::Property * ot::PropertyManager::findProperty | ( | const std::string & | _groupName, |
const std::string & | _valueName ) |
Finds a property by group and name.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyGroup::findPropertyByPath().
const ot::Property * ot::PropertyManager::findProperty | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Finds a property by group and name.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyGroup::findPropertyByPath().
bool ot::PropertyManager::getBool | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Retrieves boolean property value.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyBool::getValue(), and OTAssertNullptr.
const ot::Color & ot::PropertyManager::getColor | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Retrieves color property value.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyColor::getValue(), and OTAssertNullptr.
|
inline |
Return data that is managed by this property manager.
double ot::PropertyManager::getDouble | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Retrieves double property value.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyDouble::getValue(), and OTAssertNullptr.
int ot::PropertyManager::getInt | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Retrieves int property value.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyInt::getValue(), and OTAssertNullptr.
const ot::Painter2D * ot::PropertyManager::getPainter2D | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Retrieves Painter2D property value.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyPainter2D::getPainter(), and OTAssertNullptr.
const std::string & ot::PropertyManager::getPath | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Retrieves path property value.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyPath::getPath(), and OTAssertNullptr.
|
inline |
Finds a property by group and name. The found property will be casted to the specified type.
_groupName | The property group name. |
_valueName | The property value name. |
References OTAssertNullptr.
|
inline |
Finds a property by group and name. The found property will be casted to the specified type.
_groupName | The property group name. |
_valueName | The property value name. |
References OTAssertNullptr.
|
inline |
const std::string & ot::PropertyManager::getString | ( | const std::string & | _groupName, |
const std::string & | _valueName ) const |
Retrieves string property value.
_groupName | The property group name. |
_valueName | The property value name. |
References ot::PropertyString::getValue(), and OTAssertNullptr.
void ot::PropertyManager::mergeWith | ( | const PropertyManager & | _other, |
const PropertyBase::MergeMode & | _mergeMode = PropertyBase::MergeValues ) |
Merge the properties with the other manager.
_other | Other property manager to copy values and properties from. |
_mergeMode | Mode to use when merging. |
References ot::PropertyBase::AddMissing, getData(), ot::PropertyGroup::mergeWith(), and OTAssertNullptr.
void ot::PropertyManager::notifyAllChanged | ( | void | ) |
Will call PropertyManager::propertyChanged for every property that is currently registered. Calling this method if the manager is currently silenced will have no effect.
|
noexcept |
Move assignment operator.
_other | The PropertyManager to move from. |
|
virtual |
Will be called whenever a property has been changed.
_property | Property that has been changed. |
Reimplemented in ot::WidgetPropertyManager.
References ot::Property::getPropertyPath().
|
virtual |
Will be called before a property will be read.
_propertyGroupName | Name of the group where the property should be located at. |
_propertyName | Name of the property. The name should be unique inside a group. |
Reimplemented in ot::WidgetPropertyManager.
ot::PropertyManagerNotifier * ot::PropertyManager::removeNotifier | ( | PropertyManagerNotifier * | _notifier, |
bool | _destroyObject ) |
Remove given notifier from this manager.
_notifier | Notifier to remove. |
_destroyObject | Will destroy the passed notifier no matter if it exists or not. |
void ot::PropertyManager::removeReadCallbackNotifier | ( | PropertyReadCallbackNotifier * | _notifier | ) |
References ot::PropertyReadCallbackNotifier::getPropertyPath(), and OTAssertNullptr.
void ot::PropertyManager::removeWriteCallbackNotifier | ( | PropertyWriteCallbackNotifierBase * | _notifier | ) |
Remove write callback notifier.
_notifier | Notifier to remove. PropertyWriteCallbackNotifierBase |
References ot::PropertyWriteCallbackNotifierBase::getPropertyPath(), and OTAssertNullptr.
ot::PropertyBool * ot::PropertyManager::setBool | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
bool | _value ) |
Sets boolean property.
_groupName | The property group name. |
_valueName | The property value name. |
_value | The boolean value to set. |
References OTAssertNullptr, and ot::PropertyBool::setValue().
ot::PropertyColor * ot::PropertyManager::setColor | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
const Color & | _value ) |
Sets color property.
_groupName | The property group name. |
_valueName | The property value name. |
_value | The color to set. |
References OTAssertNullptr, and ot::PropertyColor::setValue().
ot::PropertyDouble * ot::PropertyManager::setDouble | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
double | _value ) |
Sets double property.
_groupName | The property group name. |
_valueName | The property value name. |
_value | The value to set. |
References OTAssertNullptr, and ot::PropertyDouble::setValue().
|
overridevirtual |
Deserializes the object from a JSON structure.
_object | The JSON object containing the necessary data. |
Throws | an exception if the provided JSON object is invalid. |
Implements ot::Serializable.
References ot::PropertyGroup::getName(), ot::json::getObjectList(), OTAssert, and ot::PropertyGroup::setFromJsonObject().
ot::PropertyInt * ot::PropertyManager::setInt | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
int | _value ) |
Sets integer property.
_groupName | The property group name. |
_valueName | The property value name. |
_value | The value to set. |
References OTAssertNullptr, and ot::PropertyInt::setValue().
ot::PropertyPainter2D * ot::PropertyManager::setPainter2D | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
const Painter2D * | _painter ) |
Sets painter property.
_groupName | The property group name. |
_valueName | The property value name. |
_painter | The painter to create copy from. |
References ot::Painter2D::createCopy(), and OTAssertNullptr.
ot::PropertyPainter2D * ot::PropertyManager::setPainter2D | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
Painter2D * | _painter ) |
Sets painter property.
_groupName | The property group name. |
_valueName | The property value name. |
_painter | The painter to set. |
References OTAssertNullptr, and ot::PropertyPainter2D::setPainter().
ot::PropertyPath * ot::PropertyManager::setPath | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
const std::string & | _path ) |
Sets path property.
_groupName | The property group name. |
_valueName | The property value name. |
_path | The path to set. |
References OTAssertNullptr, and ot::PropertyPath::setPath().
|
inline |
Set the notifications silenced. If set property access won't trigger any notification.
ot::PropertyString * ot::PropertyManager::setString | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
const std::string & | _value ) |
Sets string property.
_groupName | The property group name. |
_valueName | The property value name. |
_value | The value to set. |
References OTAssertNullptr, and ot::PropertyString::setValue().
ot::PropertyStringList * ot::PropertyManager::setStringList | ( | const std::string & | _groupName, |
const std::string & | _valueName, | ||
const std::string & | _value ) |
Sets string property.
_groupName | The property group name. |
_valueName | The property value name. |
_value | The value to set. |
References OTAssertNullptr, and ot::PropertyStringList::setCurrent().
|
protectedvirtual |
Stores a property within a specified group.
_groupName | The group to store the property in. |
_property | Pointer to the property to store. |
References ot::PropertyGroup::addProperty(), ot::PropertyGroup::findPropertyByPath(), ot::PropertyBase::getPropertyName(), OTAssert, and OTAssertNullptr.
void ot::PropertyManager::updateProperty | ( | const std::string & | _groupName, |
const Property * | _property, | ||
bool | _deleteProvidedProperty ) |
Updates an existing property or creates a new one.
_groupName | Name of group to add property to. |
_property | Property to update. |
_deleteProvidedProperty | If true the provided _property will be destroyed. |
References ot::Property::createCopy(), ot::PropertyBase::getPropertyName(), ot::PropertyBase::MergeValues, ot::Property::mergeWith(), and OTAssertNullptr.
void ot::PropertyManager::updateProperty | ( | const std::string & | _groupName, |
Property * | _property ) |
Updates an existing property or creates a new one.
_groupName | Name of group to add property to. |
_property | Property to update. |
References ot::PropertyBase::getPropertyName(), ot::PropertyBase::MergeValues, ot::Property::mergeWith(), and OTAssertNullptr.