stats: clean up how templates are used on the data side.
This basically works by taking advantage of the curiously recurring template pattern in an intelligent way so as to reduce the number of lines of code and hopefully make things a little bit clearer.
This commit is contained in:
@@ -158,7 +158,7 @@ Info::less(Info *stat1, Info *stat2)
|
||||
bool
|
||||
Info::baseCheck() const
|
||||
{
|
||||
if (!(flags & init)) {
|
||||
if (!(flags & Stats::init)) {
|
||||
#ifdef DEBUG
|
||||
cprintf("this is stat number %d\n", id);
|
||||
#endif
|
||||
@@ -175,55 +175,6 @@ Info::baseCheck() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FormulaBase::result(VResult &vec) const
|
||||
{
|
||||
if (root)
|
||||
vec = root->result();
|
||||
}
|
||||
|
||||
Result
|
||||
FormulaBase::total() const
|
||||
{
|
||||
return root ? root->total() : 0.0;
|
||||
}
|
||||
|
||||
size_type
|
||||
FormulaBase::size() const
|
||||
{
|
||||
if (!root)
|
||||
return 0;
|
||||
else
|
||||
return root->size();
|
||||
}
|
||||
|
||||
void
|
||||
FormulaBase::reset()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
FormulaBase::zero() const
|
||||
{
|
||||
VResult vec;
|
||||
result(vec);
|
||||
for (off_t i = 0; i < vec.size(); ++i)
|
||||
if (vec[i] != 0.0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
FormulaBase::update(Info *)
|
||||
{
|
||||
}
|
||||
|
||||
string
|
||||
FormulaBase::str() const
|
||||
{
|
||||
return root ? root->str() : "";
|
||||
}
|
||||
|
||||
Formula::Formula()
|
||||
{
|
||||
setInit();
|
||||
@@ -255,6 +206,55 @@ Formula::operator+=(Temp r)
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
Formula::result(VResult &vec) const
|
||||
{
|
||||
if (root)
|
||||
vec = root->result();
|
||||
}
|
||||
|
||||
Result
|
||||
Formula::total() const
|
||||
{
|
||||
return root ? root->total() : 0.0;
|
||||
}
|
||||
|
||||
size_type
|
||||
Formula::size() const
|
||||
{
|
||||
if (!root)
|
||||
return 0;
|
||||
else
|
||||
return root->size();
|
||||
}
|
||||
|
||||
void
|
||||
Formula::reset()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
Formula::zero() const
|
||||
{
|
||||
VResult vec;
|
||||
result(vec);
|
||||
for (off_t i = 0; i < vec.size(); ++i)
|
||||
if (vec[i] != 0.0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Formula::update()
|
||||
{
|
||||
}
|
||||
|
||||
string
|
||||
Formula::str() const
|
||||
{
|
||||
return root ? root->str() : "";
|
||||
}
|
||||
|
||||
void
|
||||
check()
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user