Replaced stupid eoRateParam by eoValueParam<eoHowMnay>
Had to transform eoHowMany into an eoPersistent ...
This commit is contained in:
parent
5508869d00
commit
0aa6a235ef
7 changed files with 88 additions and 129 deletions
|
|
@ -297,97 +297,6 @@ void eoValueParam<std::vector<eoMinimizingFitness> >::setValue(std::string _valu
|
|||
std::copy(std::istream_iterator<eoMinimizingFitness>(is), std::istream_iterator<eoMinimizingFitness>(), repValue.begin());
|
||||
}
|
||||
|
||||
/* ABANDONNED - See class eoRateType below
|
||||
///////////////////////////////////////
|
||||
Specialization for "rate_or_absolute-number"
|
||||
|
||||
typedef std::pair<double,bool> eoRateType;
|
||||
template <>
|
||||
std::string eoValueParam<eoRateType>::getValue(void) const
|
||||
{
|
||||
std::ostrstream os;
|
||||
if (repValue.second)
|
||||
os << 100*repValue.first << "% " << std::ends;
|
||||
else
|
||||
os << repValue.first << " " << std::ends;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
void eoValueParam<eoRateType>::setValue(std::string _value)
|
||||
{
|
||||
double rate;
|
||||
// check for %
|
||||
bool interpret_as_rate = false; // == no %
|
||||
size_t pos = _value.find('%');
|
||||
if (pos < _value.size()) // found a %
|
||||
{
|
||||
interpret_as_rate = true;
|
||||
_value.resize(pos); // get rid of %
|
||||
}
|
||||
std::istrstream is(_value.c_str());
|
||||
is >> rate;
|
||||
repValue.first = (interpret_as_rate ? rate/100 : floor(rate));
|
||||
repValue.second = interpret_as_rate;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* A helper class for the parsing of parameters that can be either a rate
|
||||
* or an absolute value (integer)
|
||||
* See eoHowMany.h
|
||||
*/
|
||||
class eoRateParamType : public std::pair<double,bool>
|
||||
{
|
||||
public:
|
||||
eoRateParamType(std::pair<double,bool> _p) : std::pair<double,bool>(_p) {}
|
||||
eoRateParamType(std::string _value)
|
||||
{
|
||||
readFrom(_value);
|
||||
}
|
||||
|
||||
ostream & printOn(ostream & _os) const
|
||||
{
|
||||
if (second)
|
||||
_os << 100*first << "% " << std::ends;
|
||||
else
|
||||
_os << first << " " << std::ends;
|
||||
return _os;
|
||||
}
|
||||
|
||||
istream & readFrom(istream & _is)
|
||||
{
|
||||
string value;
|
||||
_is >> value;
|
||||
readFrom(value);
|
||||
return _is;
|
||||
}
|
||||
|
||||
void readFrom(std::string _value)
|
||||
{
|
||||
double rate;
|
||||
// check for %
|
||||
bool interpret_as_rate = false; // == no %
|
||||
size_t pos = _value.find('%');
|
||||
if (pos < _value.size()) // found a %
|
||||
{
|
||||
interpret_as_rate = true;
|
||||
_value.resize(pos); // get rid of %
|
||||
}
|
||||
std::istrstream is(_value.c_str());
|
||||
is >> rate;
|
||||
first = (interpret_as_rate ? rate/100 : floor(rate));
|
||||
second = interpret_as_rate;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
// at the moment, the following are defined in eoParser.cpp
|
||||
ostream & operator<<(ostream & _os, const eoRateParamType & _rate);
|
||||
istream & operator>>(istream & _is, eoRateParamType & _rate);
|
||||
|
||||
|
||||
|
||||
/*template <class ContainerType>
|
||||
class eoContainerParam : public eoParam
|
||||
{
|
||||
|
|
|
|||
Reference in a new issue