13 independentParameters_(),
14 aliasListenersRegister_()
24 auto listener = shared_ptr<AliasParameterListener>(it.second->clone());
41 AbstractParametrizable::operator=(ap);
51 auto listener = shared_ptr<AliasParameterListener>(it.second->clone());
78 throw Exception(
"AbstractParameterAliasable::aliasParameters. Parameter " + p2 +
" does not exist in independent parameters. Perhaps it is already aliased to a parameter and can't be aliased twice.");
80 string id =
"__alias_" + p2 +
"_to_" + p1;
81 string idCheck =
"__alias_" + p1 +
"_to_" + p2;
84 throw Exception(
"AbstractParameterAliasable::aliasParameters. Trying to alias parameter " + p2 +
" to " + p1 +
", but parameter " + p1 +
" is already aliased to parameter " + p2 +
".");
101 ApplicationTools::displayWarning(
"Aliasing parameter " + p2 +
" to " + p1 +
" with different constraints. They get the intersection of both constraints : " + nc->getDescription());
125 for (
size_t i = 0; i < pl.
size(); i++)
127 if (unparsedParams.find(pl[i].getName()) == unparsedParams.end())
131 size_t unp_s = unparsedParams.size();
134 auto it = unparsedParams.begin();
135 while (it != unparsedParams.end())
148 unique_ptr<Parameter> p2(pp->
clone());
149 p2->setName(it->first);
155 it = unparsedParams.erase(it);
158 if (unparsedParams.size() == unp_s)
159 throw Exception(
"Error, there is a cycle in aliasing starting with " + unparsedParams.begin()->first);
161 unp_s = unparsedParams.size();
175 string id =
"__alias_" + p2 +
"_to_" + p1;
178 throw Exception(
"AbstractParameterAliasable::unaliasParameters. Parameter " + p2 +
" is not aliased to parameter " + p1 +
".");
193 currentName = it.second->getName();
195 it.second->rename(prefix + currentName.substr(
getNamespace().size()));
197 it.second->rename(prefix + currentName);
206 vector<string> aliases;
210 if (it.second->getFrom() == name)
212 string alias = it.second->getAlias();
213 aliases.push_back(alias);
216 vector<string> chainAliases =
getAlias(alias);
227 map<string, string> aliases;
231 string name = it.second->getFrom();
233 vector<string> alias =
getAlias(name);
265 for (
const auto& it : aliasListenersRegister_)
286 if (it.second->getName() == name)
288 from = it.second->getFrom();
318 for (
const auto& it : aliasListenersRegister_)
Exception thrown when a parameter is not found, for instance in a ParameterList.
virtual std::vector< std::string > getAlias(const std::string &name) const
std::string getNamespace() const override
virtual const Parameter & parameter(const std::string &name) const
Get the parameter with name name.
Parameter * clone() const
Create a copy of this object and send a pointer to it.
virtual void addParameterListener(std::shared_ptr< ParameterListener > listener)
Add a new listener to this parameter.
void unaliasParameters(const std::string &p1, const std::string &p2)
Detach two parameters previously set as 'aliased'.
A partial implementation of the Parametrizable interface.
void setNamespace(const std::string &prefix) override
Set the namespace for the parameter names.
virtual void shareParameter(const std::shared_ptr< Parameter > ¶m)
Share a parameter at the end of the list.
const std::shared_ptr< Parameter > & getParameter(const std::string &name) const
This class is designed to facilitate the manipulation of parameters.
ParameterList getFromParameters(const ParameterList &pl) const
Return the list of the names of the parameters from which the parameters of the list are aliased (dir...
virtual void setConstraint(std::shared_ptr< ConstraintInterface > constraint)
Set a constraint to this parameter.
virtual void deleteParameter(const std::string &name)
Delete a parameter from the list.
The parameter list object.
virtual bool hasConstraint() const
Tells if this parameter has a constraint.
virtual std::shared_ptr< const ConstraintInterface > getConstraint() const
Return the constraint associated to this parameter if there is one.
virtual void removeParameterListener(const std::string &listenerId)
Remove all listeners with a given id from this parameter.
A partial implementation of the Parametrizable interface.
bool matchParametersValues(const ParameterList ¶meters) override
Update the parameters from parameters.
virtual std::map< std::string, std::string > getAliases() const
std::map< std::string, std::shared_ptr< AliasParameterListener > > aliasListenersRegister_
ParameterList * clone() const
Create a copy of this object and send a pointer to it.
virtual bool hasParameter(const std::string &name) const
bool hasParameter(const std::string &name) const override
Tell if there is a parameter with specified name.
std::string getFrom(const std::string &name) const
virtual void shareParameters(const ParameterList ¶ms)
Share parameters with a given list. They are added the end of this list.
virtual size_t whichParameterHasName(const std::string &name) const
Get the position of a given parameter according to its name.
ParameterList & getParameters_() override
Get all parameters available.
ParameterList independentParameters_
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
virtual void addParameter(const Parameter ¶m)
Add a new parameter at the end of the list.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
std::string getParameterNameWithoutNamespace(const std::string &name) const override
Resolves a parameter name according to the current namespace.
AbstractParameterAliasable(const std::string &prefix)
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
virtual double getValue() const
Get the value of this parameter.
void aliasParameters(const std::string &p1, const std::string &p2)
alias the parameters.
Parameter & getParameter_(const std::string &name)
std::string toString(T t)
General template method to convert to a string.
size_t getNumberOfParameters() const override
Get the number of parameters.
bool startsWith(const std::string &s, const std::string &pattern)
Tell is a string begins with a certain motif.
ParameterList getAliasedParameters(const ParameterList &pl) const
Return the list of the names of the parameters that are aliased (directly or not) to one of the param...
const Parameter & parameter(const std::string &name) const override
Get the parameter with specified name.
const ParameterList & getParameters() const override
Get all parameters available.