OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ot::PropertyManager Class Reference

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"

+ Inheritance diagram for ot::PropertyManager:

Public Member Functions

 PropertyManager ()
 Default constructor.
 
 PropertyManager (const ConstJsonObject &_jsonObject)
 Deserialize constructor.
 
 PropertyManager (PropertyManager &&_other) noexcept
 Move constructor.
 
virtual ~PropertyManager ()
 Destructor.
 
PropertyManageroperator= (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::PropertyaddProperty (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.
 
PropertyBoolsetBool (const std::string &_groupName, const std::string &_valueName, bool _value)
 Sets boolean property.
 
PropertyIntsetInt (const std::string &_groupName, const std::string &_valueName, int _value)
 Sets integer property.
 
PropertyDoublesetDouble (const std::string &_groupName, const std::string &_valueName, double _value)
 Sets double property.
 
PropertyStringsetString (const std::string &_groupName, const std::string &_valueName, const std::string &_value)
 Sets string property.
 
PropertyStringListsetStringList (const std::string &_groupName, const std::string &_valueName, const std::string &_value)
 Sets string property.
 
PropertyColorsetColor (const std::string &_groupName, const std::string &_valueName, const Color &_value)
 Sets color property.
 
PropertyPainter2DsetPainter2D (const std::string &_groupName, const std::string &_valueName, Painter2D *_painter)
 Sets painter property.
 
PropertyPainter2DsetPainter2D (const std::string &_groupName, const std::string &_valueName, const Painter2D *_painter)
 Sets painter property.
 
PropertyPathsetPath (const std::string &_groupName, const std::string &_valueName, const std::string &_path)
 Sets path property.
 
PropertyfindProperty (const std::string &_groupName, const std::string &_valueName)
 Finds a property by group and name.
 
const PropertyfindProperty (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 ColorgetColor (const std::string &_groupName, const std::string &_valueName) const
 Retrieves color property value.
 
const Painter2DgetPainter2D (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.
 
PropertyManagerNotifierremoveNotifier (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.
 
- Public Member Functions inherited from ot::Serializable
 Serializable ()
 
 Serializable (const Serializable &)
 
 Serializable (Serializable &&) noexcept
 
virtual ~Serializable ()
 
Serializableoperator= (const Serializable &)
 
Serializableoperator= (Serializable &&) noexcept
 

Protected Member Functions

virtual PropertystoreProperty (const std::string &_groupName, Property *_property)
 Stores a property within a specified group.
 
PropertyGroupfindGroup (const std::string &_group) const
 Find an existing group by name.
 
PropertyGroupfindOrCreateGroup (const std::string &_group)
 Find or create a group by name.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PropertyManager() [1/3]

ot::PropertyManager::PropertyManager ( )

Default constructor.

◆ PropertyManager() [2/3]

ot::PropertyManager::PropertyManager ( const ConstJsonObject & _jsonObject)

Deserialize constructor.

References setFromJsonObject().

◆ PropertyManager() [3/3]

ot::PropertyManager::PropertyManager ( PropertyManager && _other)
noexcept

Move constructor.

Parameters
_otherThe PropertyManager to move from.

◆ ~PropertyManager()

ot::PropertyManager::~PropertyManager ( )
virtual

Destructor.

Member Function Documentation

◆ addNotifier()

void ot::PropertyManager::addNotifier ( PropertyManagerNotifier * _notifier)

Register property manager notifier.

Parameters
_notifierNotifier to add.

References OTAssert, and OTAssertNullptr.

◆ addProperty()

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.

Parameters
_groupNameName of group to add property to.
_propertyProperty to add.

References ot::PropertyBase::getPropertyName(), and OTAssertNullptr.

◆ addReadCallbackNotifier()

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.

Parameters
_notifierNotifier to add. PropertyReadCallbackNotifier

References ot::PropertyReadCallbackNotifier::getPropertyPath(), OTAssert, and OTAssertNullptr.

◆ addToJsonObject()

void ot::PropertyManager::addToJsonObject ( ot::JsonValue & _object,
ot::JsonAllocator & _allocator ) const
overridevirtual

Serializes the object to a JSON structure.

Parameters
_objectThe JSON object reference to populate.
_allocatorThe JSON allocator for memory management.

Implements ot::Serializable.

◆ addWriteCallbackNotifier()

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.

Parameters
_notifierNotifier to add. PropertyWriteCallbackNotifierBase

References ot::PropertyWriteCallbackNotifierBase::getPropertyPath(), OTAssert, and OTAssertNullptr.

◆ clear()

void ot::PropertyManager::clear ( void )

Removes all groups and properties.

◆ createGridConfiguration()

ot::PropertyGridCfg ot::PropertyManager::createGridConfiguration ( void ) const

Creates a grid configuration that can be used to serialize or visualize the properties.

Returns
Grid configuration.

References ot::PropertyGridCfg::addRootGroup().

◆ findGroup()

ot::PropertyGroup * ot::PropertyManager::findGroup ( const std::string & _group) const
protected

Find an existing group by name.

Parameters
_groupThe group name.
Returns
Pointer to the found PropertyGroup, or nullptr if not found.

◆ findOrCreateGroup()

ot::PropertyGroup * ot::PropertyManager::findOrCreateGroup ( const std::string & _group)
protected

Find or create a group by name.

Parameters
_groupThe group name.
Returns
Pointer to the found or created PropertyGroup.

◆ findProperty() [1/2]

ot::Property * ot::PropertyManager::findProperty ( const std::string & _groupName,
const std::string & _valueName )

Finds a property by group and name.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
Pointer to the found Property, or nullptr if not found.

References ot::PropertyGroup::findPropertyByPath().

◆ findProperty() [2/2]

const ot::Property * ot::PropertyManager::findProperty ( const std::string & _groupName,
const std::string & _valueName ) const

Finds a property by group and name.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
Pointer to the found Property, or nullptr if not found.

References ot::PropertyGroup::findPropertyByPath().

◆ getBool()

bool ot::PropertyManager::getBool ( const std::string & _groupName,
const std::string & _valueName ) const

Retrieves boolean property value.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
The boolean value.

References ot::PropertyBool::getValue(), and OTAssertNullptr.

◆ getColor()

const ot::Color & ot::PropertyManager::getColor ( const std::string & _groupName,
const std::string & _valueName ) const

Retrieves color property value.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
The color value.

References ot::PropertyColor::getValue(), and OTAssertNullptr.

◆ getData()

const std::map< std::string, PropertyGroup * > & ot::PropertyManager::getData ( void ) const
inline

Return data that is managed by this property manager.

Returns
Const reference to used object name to its PropertyGroup map.

◆ getDouble()

double ot::PropertyManager::getDouble ( const std::string & _groupName,
const std::string & _valueName ) const

Retrieves double property value.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
The boolean value.

References ot::PropertyDouble::getValue(), and OTAssertNullptr.

◆ getInt()

int ot::PropertyManager::getInt ( const std::string & _groupName,
const std::string & _valueName ) const

Retrieves int property value.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
The boolean value.

References ot::PropertyInt::getValue(), and OTAssertNullptr.

◆ getPainter2D()

const ot::Painter2D * ot::PropertyManager::getPainter2D ( const std::string & _groupName,
const std::string & _valueName ) const

Retrieves Painter2D property value.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
The Painter2D value.

References ot::PropertyPainter2D::getPainter(), and OTAssertNullptr.

◆ getPath()

const std::string & ot::PropertyManager::getPath ( const std::string & _groupName,
const std::string & _valueName ) const

Retrieves path property value.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
The file path.

References ot::PropertyPath::getPath(), and OTAssertNullptr.

◆ getProperty() [1/2]

template<class T >
T * ot::PropertyManager::getProperty ( const std::string & _groupName,
const std::string & _valueName )
inline

Finds a property by group and name. The found property will be casted to the specified type.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
Pointer to the found Property, or nullptr if not found.

References OTAssertNullptr.

◆ getProperty() [2/2]

template<class T >
const T * ot::PropertyManager::getProperty ( const std::string & _groupName,
const std::string & _valueName ) const
inline

Finds a property by group and name. The found property will be casted to the specified type.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
Pointer to the found Property, or nullptr if not found.

References OTAssertNullptr.

◆ getSilenceNotifications()

bool ot::PropertyManager::getSilenceNotifications ( void ) const
inline

◆ getString()

const std::string & ot::PropertyManager::getString ( const std::string & _groupName,
const std::string & _valueName ) const

Retrieves string property value.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
Returns
The boolean value.

References ot::PropertyString::getValue(), and OTAssertNullptr.

◆ mergeWith()

void ot::PropertyManager::mergeWith ( const PropertyManager & _other,
const PropertyBase::MergeMode & _mergeMode = PropertyBase::MergeValues )

Merge the properties with the other manager.

Parameters
_otherOther property manager to copy values and properties from.
_mergeModeMode to use when merging.

References ot::PropertyBase::AddMissing, getData(), ot::PropertyGroup::mergeWith(), and OTAssertNullptr.

◆ notifyAllChanged()

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.

◆ operator=()

ot::PropertyManager & ot::PropertyManager::operator= ( PropertyManager && _other)
noexcept

Move assignment operator.

Parameters
_otherThe PropertyManager to move from.
Returns
Reference to the updated PropertyManager.

◆ propertyChanged()

void ot::PropertyManager::propertyChanged ( const Property * _property)
virtual

Will be called whenever a property has been changed.

Parameters
_propertyProperty that has been changed.

Reimplemented in ot::WidgetPropertyManager.

References ot::Property::getPropertyPath().

◆ readingProperty()

void ot::PropertyManager::readingProperty ( const std::string & _propertyGroupName,
const std::string & _propertyName ) const
virtual

Will be called before a property will be read.

Parameters
_propertyGroupNameName of the group where the property should be located at.
_propertyNameName of the property. The name should be unique inside a group.

Reimplemented in ot::WidgetPropertyManager.

◆ removeNotifier()

ot::PropertyManagerNotifier * ot::PropertyManager::removeNotifier ( PropertyManagerNotifier * _notifier,
bool _destroyObject )

Remove given notifier from this manager.

Parameters
_notifierNotifier to remove.
_destroyObjectWill destroy the passed notifier no matter if it exists or not.
Returns
The removed notifier or nullptr if not found or destroyed.

◆ removeReadCallbackNotifier()

void ot::PropertyManager::removeReadCallbackNotifier ( PropertyReadCallbackNotifier * _notifier)

◆ removeWriteCallbackNotifier()

void ot::PropertyManager::removeWriteCallbackNotifier ( PropertyWriteCallbackNotifierBase * _notifier)

Remove write callback notifier.

Parameters
_notifierNotifier to remove. PropertyWriteCallbackNotifierBase

References ot::PropertyWriteCallbackNotifierBase::getPropertyPath(), and OTAssertNullptr.

◆ setBool()

ot::PropertyBool * ot::PropertyManager::setBool ( const std::string & _groupName,
const std::string & _valueName,
bool _value )

Sets boolean property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_valueThe boolean value to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyBool::setValue().

◆ setColor()

ot::PropertyColor * ot::PropertyManager::setColor ( const std::string & _groupName,
const std::string & _valueName,
const Color & _value )

Sets color property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_valueThe color to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyColor::setValue().

◆ setDouble()

ot::PropertyDouble * ot::PropertyManager::setDouble ( const std::string & _groupName,
const std::string & _valueName,
double _value )

Sets double property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_valueThe value to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyDouble::setValue().

◆ setFromJsonObject()

void ot::PropertyManager::setFromJsonObject ( const ot::ConstJsonObject & _object)
overridevirtual

Deserializes the object from a JSON structure.

Parameters
_objectThe JSON object containing the necessary data.
Exceptions
Throwsan exception if the provided JSON object is invalid.

Implements ot::Serializable.

References ot::PropertyGroup::getName(), ot::json::getObjectList(), OTAssert, and ot::PropertyGroup::setFromJsonObject().

◆ setInt()

ot::PropertyInt * ot::PropertyManager::setInt ( const std::string & _groupName,
const std::string & _valueName,
int _value )

Sets integer property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_valueThe value to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyInt::setValue().

◆ setPainter2D() [1/2]

ot::PropertyPainter2D * ot::PropertyManager::setPainter2D ( const std::string & _groupName,
const std::string & _valueName,
const Painter2D * _painter )

Sets painter property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_painterThe painter to create copy from.
Returns
Pointer to the set property.

References ot::Painter2D::createCopy(), and OTAssertNullptr.

◆ setPainter2D() [2/2]

ot::PropertyPainter2D * ot::PropertyManager::setPainter2D ( const std::string & _groupName,
const std::string & _valueName,
Painter2D * _painter )

Sets painter property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_painterThe painter to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyPainter2D::setPainter().

◆ setPath()

ot::PropertyPath * ot::PropertyManager::setPath ( const std::string & _groupName,
const std::string & _valueName,
const std::string & _path )

Sets path property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_pathThe path to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyPath::setPath().

◆ setSilenceNotifications()

void ot::PropertyManager::setSilenceNotifications ( bool _silence)
inline

Set the notifications silenced. If set property access won't trigger any notification.

◆ setString()

ot::PropertyString * ot::PropertyManager::setString ( const std::string & _groupName,
const std::string & _valueName,
const std::string & _value )

Sets string property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_valueThe value to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyString::setValue().

◆ setStringList()

ot::PropertyStringList * ot::PropertyManager::setStringList ( const std::string & _groupName,
const std::string & _valueName,
const std::string & _value )

Sets string property.

Parameters
_groupNameThe property group name.
_valueNameThe property value name.
_valueThe value to set.
Returns
Pointer to the set property.

References OTAssertNullptr, and ot::PropertyStringList::setCurrent().

◆ storeProperty()

ot::Property * ot::PropertyManager::storeProperty ( const std::string & _groupName,
Property * _property )
protectedvirtual

Stores a property within a specified group.

Parameters
_groupNameThe group to store the property in.
_propertyPointer to the property to store.
Returns
Pointer to the stored property.

References ot::PropertyGroup::addProperty(), ot::PropertyGroup::findPropertyByPath(), ot::PropertyBase::getPropertyName(), OTAssert, and OTAssertNullptr.

◆ updateProperty() [1/2]

void ot::PropertyManager::updateProperty ( const std::string & _groupName,
const Property * _property,
bool _deleteProvidedProperty )

Updates an existing property or creates a new one.

Parameters
_groupNameName of group to add property to.
_propertyProperty to update.
_deleteProvidedPropertyIf true the provided _property will be destroyed.

References ot::Property::createCopy(), ot::PropertyBase::getPropertyName(), ot::PropertyBase::MergeValues, ot::Property::mergeWith(), and OTAssertNullptr.

◆ updateProperty() [2/2]

void ot::PropertyManager::updateProperty ( const std::string & _groupName,
Property * _property )

Updates an existing property or creates a new one.

Parameters
_groupNameName of group to add property to.
_propertyProperty to update.

References ot::PropertyBase::getPropertyName(), ot::PropertyBase::MergeValues, ot::Property::mergeWith(), and OTAssertNullptr.


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