Public Member Functions | List of all members
ime::Property Class Reference

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

Detailed Description

Class that can store a value of any type.

Definition at line 38 of file Property.h.

Constructor & Destructor Documentation

◆ Property() [1/2]

ime::Property::Property ( const std::string &  name)
explicit

Constructor.

Parameters
nameName of the property

The property will be created without a value

See also
setValue

◆ Property() [2/2]

template<typename T >
ime::Property::Property ( const std::string &  name,
T &&  value 
)

Constructor.

Parameters
nameName of the property
valueValue of the property

The value can be of any type (Primitive or custom).

Warning
the type of T must be remembered in order to retrieve the value later
See also
getValue

Member Function Documentation

◆ getName()

const std::string & ime::Property::getName ( ) const

Get the name of the property.

Returns
Name of the property

◆ getValue()

template<typename T >
T ime::Property::getValue ( ) const

Get the value of the property.

Exceptions
ime::InvalidArgumentif the stored value is not of type T
Returns
Value of the property
Warning
Don't call this function if the property does not have a value, otherwise it will throw an exception. In addition, always make sure that the template argument T matches the type of the stored value when calling this function

◆ hasValue()

bool ime::Property::hasValue ( ) const

Check if the property has a value or not.

Returns
True if the property contains a value or false if it does not contain a value

◆ onValueChange()

int ime::Property::onValueChange ( const Callback< Property *const > &  callback)

Subscribe a callback to a value change event.

Parameters
callbackThe 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

◆ setValue()

template<typename T >
void ime::Property::setValue ( T &&  value)

Set the value of the property.

Parameters
valueNew 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

See also
getValue

◆ unsubscribe()

bool ime::Property::unsubscribe ( int  id)

Remove a callback from a value change event.

Parameters
idThe 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: