A container for ime::Property instances.
More...
#include <PropertyContainer.h>
A container for ime::Property instances.
Usage example:
settings.
addProperty(Property(
"masterVolume", 100.0f));
...
settings.setValue("sfxVolume", 20.0f);
A container for ime::Property instances.
bool addProperty(const Property &Property)
Add a property to the container.
Definition at line 38 of file PropertyContainer.h.
◆ Callback
template<typename... Args>
◆ addProperty()
bool ime::PropertyContainer::addProperty |
( |
const Property & |
Property | ) |
|
Add a property to the container.
- Parameters
-
- Returns
- True if the property was added or false if a property with the same name already exits in the container
◆ clear()
void ime::PropertyContainer::clear |
( |
| ) |
|
Remove all properties from the container.
◆ forEachProperty()
void ime::PropertyContainer::forEachProperty |
( |
const Callback< Property & > & |
callback | ) |
|
Apply a callback to each property in the container.
- Parameters
-
callback | The function to be applied |
◆ getCount()
std::size_t ime::PropertyContainer::getCount |
( |
| ) |
const |
Get the number of properties in the container.
- Returns
- The number of properties in the container
◆ getValue()
template<typename T >
T ime::PropertyContainer::getValue |
( |
const std::string & |
name | ) |
const |
Get the value of a property.
- Parameters
-
name | The name of the property to get the value for |
- Exceptions
-
std::bad_any_cast | if the value stored by the property is not of type T |
- Returns
- Value of a property
This function will throw an exception if the template argument T and the type of the stored value don't match. This means that the property must always have a value before calling this function
- See also
- setValue and propertyHasValue
◆ hasProperty()
bool ime::PropertyContainer::hasProperty |
( |
const std::string & |
name | ) |
const |
Check if the container has a given property.
- Parameters
-
name | The name of the property to be checked |
- Returns
- True if the property exists or false if the container does not have a property with the given name
- See also
- addProperty
◆ onValueChange()
int ime::PropertyContainer::onValueChange |
( |
const std::string & |
name, |
|
|
const Callback< Property *const > & |
callback |
|
) |
| |
Subscribe a callback to a value change event.
- Parameters
-
name | The name of the property to add the callback to |
callback | The function to be executed when the value changes |
- Returns
- The unique identification of the callback
Since the value can be of any type, the callback is passed a const pointer to the property instead of the new value, so that you can retrieve it
- See also
- getValue and unsubscribe
◆ propertyHasValue()
bool ime::PropertyContainer::propertyHasValue |
( |
const std::string & |
name | ) |
const |
Check if a property in the container has a value or not.
- Parameters
-
name | The name of the property to be checked |
- Returns
- True if property has value or false if the property does not have a value or the property does not exist in the container
- See also
- hasProperty
◆ removeProperty()
bool ime::PropertyContainer::removeProperty |
( |
const std::string & |
name | ) |
|
Remove a property from the container.
- Parameters
-
name | The name of the property to be removed |
- Returns
- True if the property was removed or false if the specified property doesn't exist
- See also
- addProperty
◆ setValue()
template<typename T >
void ime::PropertyContainer::setValue |
( |
const std::string & |
name, |
|
|
T && |
value |
|
) |
| |
Change the value of a property.
- Parameters
-
name | The name of the property to set a value for |
value | The new value of the property |
Note that the type of the value of the property need not match the previous value type
- See also
- getValue
◆ unsubscribe()
bool ime::PropertyContainer::unsubscribe |
( |
const std::string & |
name, |
|
|
int |
id |
|
) |
| |
Remove a callback from a value change event.
- Parameters
-
name | The name of the property to remove the callback from |
id | The unique identifier of the callback |
- Returns
- True if the callback was removed or false a callback with the given id does not exist
- See also
- onValueChange
The documentation for this class was generated from the following file: