EventAnalysis  1.3.1
Classes | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
EA::Configurable Class Reference

Interface for a configurable class. More...

#include <Configurable.h>

Inheritance diagram for EA::Configurable:
EA::Algorithm EA::DataProvider EA::EventLoop EA::PersistenceService EA::AlgoSequence EA::PersistenceAlgo EA::RootDataProvider EA::RootDataProviderV0 EA::RootPersistenceService EA::AlgoSequenceDecorator EA::GarbageCollectorDecorator

Classes

class  Representation
 

Public Member Functions

 Configurable ()
 Constructor. More...
 
template<typename T >
bool SetParameter (const std::string &name, const T &value)
 Set the value of a parameter and then calls a callback function. More...
 
bool SetParameter (const std::string &name, const char *value)
 Set the value of a string parameter using a string literal and then calls an eventual callback function. More...
 
std::vector< std::string > GetParameters ()
 Get the names of the parameters. More...
 
bool AddSubConfigurable (EA::observer_ptr< Configurable > subConfigurable)
 Adds a sub-configurable. More...
 

Protected Member Functions

template<typename T >
bool DefineParameter (const std::string &name, T &variable, std::function< bool()> callBack={})
 Set a parameter. More...
 
 Configurable (const std::shared_ptr< Representation > &impl)
 
std::shared_ptr< Representation > & GetRepresentation ()
 

Private Attributes

std::shared_ptr< Representation_repr
 

Detailed Description

Interface for a configurable class.

This class provides the interface for defining a map between names (strings) and actual variables, and for setting values of the variables via their names. Children classes can expose their internal variables with DefineParameter, and users can set these values by calling SetParameter.

To ease the composition of configurable objects a set of sub-configurables can be defined: their parameters can be set as if they were parameter of the configurable object containing them.

Constructor & Destructor Documentation

◆ Configurable() [1/2]

EA::Configurable::Configurable ( )

Constructor.

◆ Configurable() [2/2]

EA::Configurable::Configurable ( const std::shared_ptr< Representation > &  impl)
inlineprotected

Member Function Documentation

◆ AddSubConfigurable()

bool EA::Configurable::AddSubConfigurable ( EA::observer_ptr< Configurable subConfigurable)

Adds a sub-configurable.

A sub-configurable is a configurable object to which the settings of parameters not belonging to this configurable will be forwarded. Several sub-configurables can be added to a configurable.

Parameters
subConfigurablePointer to the sub-configurable.
Returns
true if the sub-configurable has been successfully added.

◆ DefineParameter()

template<typename T >
bool EA::Configurable::DefineParameter ( const std::string &  name,
T &  variable,
std::function< bool()>  callBack = {} 
)
protected

Set a parameter.

This method associates a name with a variable, making it possible to set its value by means of SetValue. If a callback function is specified then it will be called by SetParameter after setting the parameter.

Parameters
nameThe name of the parameter.
variableThe variable that will store the parameter value.
callBackThe callback function.
Returns
true if the parameter has bee correctly defined.

◆ GetParameters()

std::vector< std::string > EA::Configurable::GetParameters ( )

Get the names of the parameters.

This method returns a list of the names of the parameters of the Configurable object and all its sub-configurables.

Returns
A vector containing the names of the parameters.
See also
AddSubConfigurable

◆ GetRepresentation()

std::shared_ptr<Representation>& EA::Configurable::GetRepresentation ( )
inlineprotected

◆ SetParameter() [1/2]

template<typename T >
bool EA::Configurable::SetParameter ( const std::string &  name,
const T &  value 
)

Set the value of a parameter and then calls a callback function.

The method sets the value for a parameter previously defined by DefineParameter and then calls an eventual callback function.

Parameters
nameThe name of the parameter.
valueThe new value for the parameter.
Returns
true if the new value has been correctly set and the callback function returns true, false otherwise.

◆ SetParameter() [2/2]

bool EA::Configurable::SetParameter ( const std::string &  name,
const char *  value 
)

Set the value of a string parameter using a string literal and then calls an eventual callback function.

Overload of template SetValue for setting the value of an std::string parameter using a const char* string literal (needed to circumvent troubles with template substitution and type mismatch) and then calling a callback function.

Parameters
nameThe name of the parameter.
valueThe new value for the parameter.
Returns
true if the new value has been correctly set and the callback function returns true, false otherwise.

Member Data Documentation

◆ _repr

std::shared_ptr<Representation> EA::Configurable::_repr
private

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