Class that can store a value of any type. More...
#include <Property.h>
Public Member Functions | |
Property (const std::string &name) | |
Constructor. More... | |
template<typename T > | |
Property (const std::string &name, T &&value) | |
Constructor. More... | |
const std::string & | getName () const |
Get the name of the property. More... | |
template<typename T > | |
void | setValue (T &&value) |
Set the value of the property. More... | |
template<typename T > | |
T | getValue () const |
Get the value of the property. More... | |
bool | hasValue () const |
Check if the property has a value or not. More... | |
int | onValueChange (const Callback< Property *const > &callback) |
Subscribe a callback to a value change event. More... | |
bool | unsubscribe (int id) |
Remove a callback from a value change event. More... | |
Class that can store a value of any type.
Definition at line 38 of file Property.h.
|
explicit |
Constructor.
name | Name of the property |
The property will be created without a value
ime::Property::Property | ( | const std::string & | name, |
T && | value | ||
) |
Constructor.
name | Name of the property |
value | Value of the property |
The value can be of any type (Primitive or custom).
const std::string & ime::Property::getName | ( | ) | const |
Get the name of the property.
T ime::Property::getValue | ( | ) | const |
Get the value of the property.
ime::InvalidArgument | if the stored value is not of type T |
bool ime::Property::hasValue | ( | ) | const |
Check if the property has a value or not.
Subscribe a callback to a value change event.
callback | The function to be executed when the value changes |
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
void ime::Property::setValue | ( | T && | value | ) |
Set the value of the property.
value | New value of the property |
This function will overwrite the previous value. The new value need not be the same type as the previous value and it can be of any type (Primitive or custom). However, the type of T must be remembered in order to retrieve the value later
bool ime::Property::unsubscribe | ( | int | id | ) |
Remove a callback from a value change event.
id | The unique identifier of the callback |