48 independentParameters_(ap.independentParameters_),
49 aliasListenersRegister_()
107 if (getNumberOfParameters() > 0 && independentParameters_.size() == 0)
108 independentParameters_ = getParameters();
110 if (!hasParameter(p1))
112 if (!hasParameter(p2))
114 if (!independentParameters_.hasParameter(getNamespace() + p2))
115 throw Exception(
"AbstractParameterAliasable::aliasParameters. Parameter " + p2 +
" is already aliased to a parameter and can't be aliased twice.");
117 string id =
"__alias_" + p2 +
"_to_" + p1;
118 string idCheck =
"__alias_" + p1 +
"_to_" + p2;
120 if (aliasListenersRegister_.find(idCheck) != aliasListenersRegister_.end())
121 throw Exception(
"AbstractParameterAliasable::aliasParameters. Trying to alias parameter " + p2 +
" to " + p1 +
", but parameter " + p1 +
" is already aliased to parameter " + p2 +
".");
128 throw Exception(
"AbstractParameterAliasable::aliasParameters. Cannot alias parameter " + p2 +
" to " + p1 +
", because the constraints attached to these two parameters are different.");
133 throw Exception(
"AbstractParameterAliasable::aliasParameters. Cannot alias parameter " + p2 +
" to " + p1 +
", because the constraints attached to these two parameters are different.");
141 aliasListenersRegister_[id] = aliasListener;
147 independentParameters_.deleteParameter(getNamespace() + p2);
155 for (
size_t i=0; i< pl.
size(); i++)
157 if (unparsedParams.find(pl[i].getName())==unparsedParams.end())
161 size_t unp_s=unparsedParams.size();
164 map<string, string>::iterator it;
165 for (it=unparsedParams.begin(); it!=unparsedParams.end(); it++)
176 auto_ptr<Parameter> p2(pp->
clone());
177 p2->setName(it->first);
183 unparsedParams.erase(it);
186 if (unparsedParams.size()==unp_s)
187 throw Exception(
"Error, there is a cycle in aliasing");
189 unp_s=unparsedParams.size();
201 if (!hasParameter(p1))
203 if (!hasParameter(p2))
206 string id =
"__alias_" + p2 +
"_to_" + p1;
207 map<string, AliasParameterListener*>::iterator it = aliasListenersRegister_.find(
id);
208 if (it == aliasListenersRegister_.end())
209 throw Exception(
"AbstractParameterAliasable::unaliasParameters. Parameter " + p2 +
" is not aliased to parameter " + p1 +
".");
211 getParameter_(p1).removeParameterListener(
id);
213 aliasListenersRegister_.erase(it);
215 independentParameters_.addParameter(getParameter(p2));
235 currentName = it->second->getName();
237 it->second->rename(prefix + currentName.substr(
getNamespace().size()));
239 it->second->rename(prefix + currentName);
247 vector<string> aliases;
253 if (it->second->getFrom() == name)
255 string alias = it->second->getAlias();
256 aliases.push_back(alias);
258 vector<string> chainAliases =
getAlias(alias);
314 if (it->second->getName() == name)
316 from = it->second->getFrom();
Exception thrown when a parameter is not found, for instance in a ParameterList.
std::vector< std::string > getAlias(const std::string &name) const
Parameter * clone() const
Create a copy of this object and send a pointer to it.
virtual const Constraint * getConstraint() const
Return the constraint associated to this parameter if there is one.
This class allows to perform a correspondence analysis.
void unaliasParameters(const std::string &p1, const std::string &p2)
Detach two parameters previously set as 'aliased'.
A partial implementation of the Parametrizable interface.
virtual ~AbstractParameterAliasable()
This class is designed to facilitate the manipulation of parameters.
virtual void addParameterListener(ParameterListener *listener, bool attachListener=true)
Add a new listener to this parameter.
void aliasParameters(std::map< std::string, std::string > &unparsedParams, bool verbose)
alias the parameters following the links described in a map, and update the object accordingly...
size_t getNumberOfParameters() const
Get the number of parameters.
static std::string toString(T t)
General template method to convert to a string.
The parameter list object.
static bool startsWith(const std::string &s, const std::string &pattern)
Tell is a string begins with a certain motif.
virtual bool hasConstraint() const
Tells if this parameter has a constraint.
ParameterList & getParameters_()
A partial implementation of the Parametrizable interface.
std::map< std::string, AliasParameterListener * > aliasListenersRegister_
AliasParameterListener * clone() const
Create a copy of this object and send a pointer to it.
ParameterList * clone() const
Create a copy of this object and send a pointer to it.
virtual bool hasParameter(const std::string &name) const
virtual std::string getDescription() const =0
Give a short description on the type of constraint.
std::string getFrom(const std::string &name) const
bool matchParametersValues(const ParameterList ¶meters)
Update the parameters from parameters.
ParameterList independentParameters_
const Parameter & getParameter(const std::string &name) const
Get the parameter with specified name.
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
virtual void addParameter(const Parameter ¶m)
Add a new parameter at the end of the list.
const ParameterList & getParameters() const
Get all parameters available.
AbstractParameterAliasable(const std::string &prefix)
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
virtual const Parameter & getParameter(const std::string &name) const
Get the parameter with name name.
virtual double getValue() const
Get the value of this parameter.
void aliasParameters(const std::string &p1, const std::string &p2)
Set two parameters as 'aliased'.
void setParameterList(ParameterList *pl)
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
Inner listener class used by AbstractParameterAliasable.
std::string getNamespace() const
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...