refactor: expose a eoHowMany::value function
This commit is contained in:
parent
728bc6e897
commit
90c3e8ffa1
1 changed files with 21 additions and 16 deletions
|
|
@ -83,22 +83,7 @@ public:
|
||||||
eoHowMany(double _rate = 0.0, bool _interpret_as_rate = true):
|
eoHowMany(double _rate = 0.0, bool _interpret_as_rate = true):
|
||||||
rate(_rate), count(0)
|
rate(_rate), count(0)
|
||||||
{
|
{
|
||||||
if (_interpret_as_rate)
|
this->value(_rate, _interpret_as_rate);
|
||||||
{
|
|
||||||
if (_rate<0)
|
|
||||||
{
|
|
||||||
rate = 1.0+_rate;
|
|
||||||
if (rate < 0) // was < -1
|
|
||||||
throw std::logic_error("rate<-1 in eoHowMany!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rate = 0.0; // just in case, but shoud be unused
|
|
||||||
count = int(_rate); // negative values are allowed here
|
|
||||||
if (count != _rate)
|
|
||||||
eo::log << eo::warnings << "Number was rounded in eoHowMany";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ctor from an int - both from int and unsigned int are needed
|
/** Ctor from an int - both from int and unsigned int are needed
|
||||||
|
|
@ -195,6 +180,26 @@ public:
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void value(double _rate, bool _interpret_as_rate)
|
||||||
|
{
|
||||||
|
if (_interpret_as_rate)
|
||||||
|
{
|
||||||
|
if (_rate<0)
|
||||||
|
{
|
||||||
|
rate = 1.0+_rate;
|
||||||
|
if (rate < 0) // was < -1
|
||||||
|
throw std::logic_error("rate < -1 in eoHowMany!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rate = 0.0; // just in case, but shoud be unused
|
||||||
|
count = int(_rate); // negative values are allowed here
|
||||||
|
if (count != _rate)
|
||||||
|
eo::log << eo::warnings << "Number was rounded in eoHowMany";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private :
|
private :
|
||||||
double rate;
|
double rate;
|
||||||
int count;
|
int count;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue