41 #include "../Text/StringTokenizer.h" 52 parameters_(pl.size())
55 for (
unsigned int i = 0; i <
size(); i++)
72 for (
unsigned int i = 0; i < pl.
size(); i++)
91 for (
unsigned int i = 0; i < size(); i++)
94 if (p->
getName() == name)
return *p;
102 for (
unsigned int i = 0; i < size(); i++)
113 for (
unsigned int i = 0; i < size(); i++)
116 if (p->
getName() == name)
return *p;
125 for (
unsigned int i = 0; i < names.size(); i++)
127 Parameter param = getParameter(names[i]);
146 for (
unsigned int i = 0; i < parameters.size(); i++)
165 for (
unsigned int i = 0; i < params.
size(); i++)
180 vector<string> pNames(
size());
181 for (
unsigned int i = 0; i <
size(); i++)
192 vector<string> pNames;
193 for (
unsigned int i = 0; i <
size(); i++)
207 pos2=name.find(g,pos1);
208 if (pos2 == string::npos){
212 pos1=pos2+g.length();
215 ((g.length()==0) || (pos1==name.length()) || (name.rfind(g)==name.length()-g.length())))
216 pNames.push_back(name);
226 if (hasParameter(param.getName()))
227 throw ParameterException(
"ParameterList::addParameter. Parameter with name '" + param.getName() +
"' already exists.", ¶m);
228 parameters_.push_back(dynamic_cast<Parameter*>(param.clone()));
235 if (hasParameter(param->getName()))
236 throw ParameterException(
"ParameterList::addParameter. Parameter with name '" + param->getName() +
"' already exists.", param);
237 parameters_.push_back(param);
245 delete parameters_[index];
246 parameters_[index] =
dynamic_cast<Parameter*
>(param.clone());
253 for (
unsigned int i = 0; i < params.
size(); i++)
267 for (
unsigned int i = 0; i < params.size(); i++)
269 addParameter(params[i]);
288 for (vector<Parameter*>::iterator it = parameters_.begin(); it < parameters_.end(); it++)
290 const Parameter* p = ¶ms.getParameter((*it)->getName());
291 if ((*it)->hasConstraint() && !(*it)->getConstraint()->isCorrect(p->
getValue()))
296 for (vector<Parameter*>::iterator it = parameters_.begin(); it < parameters_.end(); it++)
298 const Parameter* p = ¶ms.getParameter((*it)->getName());
308 for (vector<Parameter*>::const_iterator it = params.
parameters_.begin(); it < params.
parameters_.end(); it++)
320 for (vector<Parameter*>::const_iterator it = params.
parameters_.begin(); it < params.
parameters_.end(); it++)
336 for (vector<Parameter*>::const_iterator it = params.
parameters_.begin(); it < params.
parameters_.end(); it++)
349 for (vector<Parameter*>::const_iterator it = params.
parameters_.begin(); it < params.
parameters_.end(); it++)
354 if (p->
getValue() != (*it)->getValue())
367 for (vector<Parameter*>::const_iterator it = params.parameters_.begin(); it < params.parameters_.end(); it++)
369 if (hasParameter((*it)->getName()))
371 Parameter* p = &getParameter((*it)->getName());
381 for (vector<Parameter*>::const_iterator it = params.parameters_.begin(); it < params.parameters_.end(); it++)
383 if (hasParameter((*it)->getName()))
385 Parameter* p = &getParameter((*it)->getName());
386 if (p->
getValue() != (*it)->getValue()) {
389 if (updatedParameters)
390 updatedParameters->push_back(pos);
402 for (vector<Parameter*>::iterator it = parameters_.begin(); it < parameters_.end(); it++)
404 const Parameter* p = ¶ms.getParameter((*it)->getName());
413 for (vector<Parameter*>::const_iterator it = params.parameters_.begin(); it < params.parameters_.end(); it++)
415 Parameter* p = &getParameter((*it)->getName());
423 for (
unsigned int i = 0; i <
size(); i++)
435 for (vector<Parameter*>::const_iterator it = params.
parameters_.begin(); it < params.
parameters_.end(); it++)
448 for (
unsigned int i = 0; i < size(); i++)
454 parameters_.erase(parameters_.begin() + i);
464 for (
unsigned int i = 0; i < names.size(); i++)
468 deleteParameter(names[i]);
486 parameters_.erase(parameters_.begin() +
static_cast<ptrdiff_t
>(index));
492 vector<size_t> tmp(indices);
493 sort(tmp.begin(), tmp.end());
494 for (vector<size_t>::reverse_iterator i = tmp.rbegin(); i != tmp.rend(); i++)
500 parameters_.erase(parameters_.begin() +
static_cast<ptrdiff_t
>(index));
507 for (
size_t i = 0; i < size(); i++)
509 if (parameters_[i]->getName() == name)
return i;
517 (out <<
"Name:\tValue:\tConstraint:").endLine();
518 (out <<
"_________________________________________________").endLine();
519 for (
unsigned int i = 0; i <
size(); i++)
523 out << (
parameters_[i]->hasConstraint() ?
"\t" +
parameters_[i]->getConstraint()->getDescription() : string(
""));
531 for (
unsigned int i = 0; i <
size(); i++)
Exception thrown when a parameter is not found, for instance in a ParameterList.
virtual ParameterList subList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
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.
virtual void includeParameters(const ParameterList ¶ms)
Add parameters to the list. If the parameter already exists, only the value is updated, otherwise the new parameter is added at the end of the list.
virtual bool testParametersValues(const ParameterList ¶ms) const
Tests the parameters from params.
virtual void reset()
Reset the list: delete all parameters.
virtual std::vector< std::string > getMatchingParameterNames(const std::string &pattern) const
Get all parameter names matching with the given name. Up to now, only "*" jokers are available...
virtual double getParameterValue(const std::string &name) const
Get the value of the parameter with name name.
This class allows to perform a correspondence analysis.
virtual bool matchParametersValues(const ParameterList ¶ms, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
bool hasMoreToken() const
Tell if some tokens are still available.
virtual void setAllParameters(const ParameterList ¶ms)
Set the parameters to be equals to params.
virtual void deleteParameters(const std::vector< std::string > &names, bool mustExist=true)
Delete several parameters from the list.
ParameterList & operator=(const ParameterList &pl)
ParameterList()
Build a new ParameterList object.
This class is designed to facilitate the manipulation of parameters.
virtual void setAllParametersValues(const ParameterList ¶ms)
Set the parameters to be equals to params.
const std::string & nextToken()
Get the next available token. If no token is availbale, throw an Exception.
virtual void deleteParameter(const std::string &name)
Delete a parameter from the list.
virtual void setParameterValue(const std::string &name, double value)
Set the value of parameter with name name to be equal to value.
virtual ParameterList getCommonParametersWith(const ParameterList ¶ms) const
Get the sublist containing all common parameter between this list and pl.
virtual bool isCorrect(double value) const =0
Tell if a given value is correct.
The parameter list object.
virtual void addParameters(const ParameterList ¶ms)
Add new parameters at the end of the list.
virtual bool hasConstraint() const
Tells if this parameter has a constraint.
virtual void setValue(double value)
Set the value of this parameter.
virtual std::vector< std::string > getParameterNames() const
Get all parameter names in the list.
ParameterList * clone() const
Create a copy of this object and send a pointer to it.
virtual bool hasParameter(const std::string &name) const
virtual size_t whichParameterHasName(const std::string &name) const
Get the position of a given parameter according to its name.
virtual const std::string & getName() const
Get the name of this parameter.
virtual OutputStream & endLine()=0
virtual void setParameter(size_t index, const Parameter ¶m)
Change given parameter.
virtual void setParameters(const ParameterList ¶ms)
Update the parameters from params.
virtual void addParameter(const Parameter ¶m)
Add a new parameter at the end of the list.
virtual void matchParameters(const ParameterList ¶ms)
Update the parameters from params.
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.
virtual void printParameters(OutputStream &out) const
Print all parameters.
std::vector< Parameter * > parameters_
Exception thrown when a value do not match a given constraint.
Index out of bounds exception class.
The parameter exception base class.
virtual void setParametersValues(const ParameterList ¶ms)
Update the parameters from the ones in params that have matching names.