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

A container for a group of properties. More...

#include <PropertyContainer.h>

Public Types

template<typename... Args>
using Callback = std::function< void(Args...)>
 Event listener. More...
 

Public Member Functions

bool addProperty (const Property &Property)
 Add a property. More...
 
bool addProperty (Property &&)
 
template<typename T >
void setValue (const std::string &name, T &&value)
 Set the value of a property. More...
 
template<typename T >
getValue (const std::string &name) const
 Get the value of a property. More...
 
bool removeProperty (const std::string &name)
 Remove a property. More...
 
bool hasProperty (const std::string &name) const
 Check if container has a given property. More...
 
bool propertyHasValue (const std::string &name) const
 Check if a property has a value or not. More...
 
std::size_t getSize () const
 Get the number of properties in the container. More...
 
void forEachProperty (const Callback< Property & > &callback)
 Execute a callback for each property in the container. More...
 
void clear ()
 Remove all the stored properties from the container. More...
 

Detailed Description

A container for a group of properties.

Definition at line 38 of file PropertyContainer.h.

Member Typedef Documentation

◆ Callback

template<typename... Args>
using ime::PropertyContainer::Callback = std::function<void(Args...)>

Event listener.

Definition at line 41 of file PropertyContainer.h.

Member Function Documentation

◆ addProperty()

bool ime::PropertyContainer::addProperty ( const Property Property)

Add a property.

Parameters
PropertyProperty to add
Returns
True if the property was added or false if a property with the same name already exits

◆ clear()

void ime::PropertyContainer::clear ( )

Remove all the stored properties from the container.

◆ forEachProperty()

void ime::PropertyContainer::forEachProperty ( const Callback< Property & > &  callback)

Execute a callback for each property in the container.

Parameters
callbackThe function to be executed

The callback is passed the property on each invocation

◆ getSize()

std::size_t ime::PropertyContainer::getSize ( ) 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
nameName of the property to get value for
Exceptions
std::bad_any_castif 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
propertyHasValue
setValue

◆ hasProperty()

bool ime::PropertyContainer::hasProperty ( const std::string &  name) const

Check if container has a given property.

Parameters
nameName of the property to check
Returns
True if property exists, otherwise false

◆ propertyHasValue()

bool ime::PropertyContainer::propertyHasValue ( const std::string &  name) const

Check if a property has a value or not.

Parameters
nameName of the property to be checked
Returns
True if property has value or false if the property does not have a value or does not exist
See also
hasProperty

◆ removeProperty()

bool ime::PropertyContainer::removeProperty ( const std::string &  name)

Remove a property.

Parameters
nameName of the property to remove
Returns
True if the property was removed or false if the specified property doesnt exist

◆ setValue()

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

Set the value of a property.

Parameters
nameName of the property to set value for
valueNew value of the property

The type of

Template Parameters
Tmust be remembered in order to retrieve the value later
See also
getValue

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