10 #ifndef CONFIGURABLE_H_ 11 #define CONFIGURABLE_H_ 47 template <
typename T>
bool SetParameter(
const std::string &name,
const T &value);
59 bool SetParameter(
const std::string &name,
const char *value);
93 template <
typename T>
bool DefineParameter(
const std::string &name, T &variable, std::function<
bool()> callBack = {});
98 std::unordered_map<std::string, std::function<bool()>>
callBackMap;
106 std::shared_ptr<Representation>
_repr;
113 auto firstPointPos = name.find(
'.');
114 if (firstPointPos == std::string::npos) {
118 auto callBackIter =
_repr->callBackMap.find(name);
119 if (callBackIter !=
_repr->callBackMap.end()) {
120 return (callBackIter->second)();
128 std::string subConfName = name.substr(0, firstPointPos);
130 std::find_if(
_repr->subConfigurables.begin(),
_repr->subConfigurables.end(),
131 [&subConfName](
const std::pair<std::string, observer_ptr<Configurable>> &subConfEntry) {
132 if (subConfName == subConfEntry.first) {
137 if (subConfIter !=
_repr->subConfigurables.end()) {
138 return subConfIter->second->SetParameter(name.substr(firstPointPos + 1), value);
145 template <
typename T>
148 static_assert(!(std::is_array<T>::value),
"Can't use array as parameter");
149 static_assert(!(std::is_same<T, const char *>::value),
"Can't use const char * as parameter; use std::string");
153 _repr->callBackMap.emplace(name, callBack);
Configurable(const std::shared_ptr< Representation > &impl)
Definition: Configurable.h:102
Class describing a pointer to an object retrieved from an ObjectMap.
Definition: ObjPtr.h:31
bool SetParameter(const std::string &name, const T &value)
Set the value of a parameter and then calls a callback function.
Definition: Configurable.h:111
std::shared_ptr< Representation > _repr
Definition: Configurable.h:106
std::vector< std::pair< std::string, observer_ptr< Configurable > > > subConfigurables
Definition: Configurable.h:99
bool DefineParameter(const std::string &name, T &variable, std::function< bool()> callBack={})
Set a parameter.
Definition: Configurable.h:146
A smart pointer not owning the wrapped object.
Definition: ObserverPtr.h:28
std::unordered_map< std::string, std::function< bool()> > callBackMap
Definition: Configurable.h:98
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
Definition: Configurable.h:95
A map between strings and objects of ObjectWrapper kind.
Definition: ObjectMap.h:32
Configurable()
Constructor.
Definition: Configurable.cpp:14
std::vector< std::string > GetParameters()
Get the names of the parameters.
Definition: Configurable.cpp:20
ObjectMap paramsMap
Definition: Configurable.h:97
bool AddSubConfigurable(std::string name, EA::observer_ptr< Configurable > subConfigurable)
Adds a sub-configurable.
Definition: Configurable.cpp:33
Interface for a configurable class.
Definition: Configurable.h:33
std::shared_ptr< Representation > & GetRepresentation()
Definition: Configurable.h:103