diff options
author | Nathan Binkert <nate@binkert.org> | 2009-03-05 19:09:53 -0800 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2009-03-05 19:09:53 -0800 |
commit | 9f45fbaaa6e5f0fc63c63162b756c44b33e367f5 (patch) | |
tree | 69e036df5d4aca7d57e27eace024b495c7faa3c3 /src/base/statistics.cc | |
parent | cc95b5739097e31fdaa36a3ff443861969e338b1 (diff) | |
download | gem5-9f45fbaaa6e5f0fc63c63162b756c44b33e367f5.tar.xz |
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.
Diffstat (limited to 'src/base/statistics.cc')
-rw-r--r-- | src/base/statistics.cc | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/src/base/statistics.cc b/src/base/statistics.cc index 032cbf689..c77816f23 100644 --- a/src/base/statistics.cc +++ b/src/base/statistics.cc @@ -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,21 +175,52 @@ Info::baseCheck() const } +Formula::Formula() +{ + setInit(); +} + +Formula::Formula(Temp r) +{ + root = r; + assert(size()); +} + +const Formula & +Formula::operator=(Temp r) +{ + assert(!root && "Can't change formulas"); + root = r; + assert(size()); + return *this; +} + +const Formula & +Formula::operator+=(Temp r) +{ + if (root) + root = NodePtr(new BinaryNode<std::plus<Result> >(root, r)); + else + root = r; + assert(size()); + return *this; +} + void -FormulaBase::result(VResult &vec) const +Formula::result(VResult &vec) const { if (root) vec = root->result(); } Result -FormulaBase::total() const +Formula::total() const { return root ? root->total() : 0.0; } size_type -FormulaBase::size() const +Formula::size() const { if (!root) return 0; @@ -198,12 +229,12 @@ FormulaBase::size() const } void -FormulaBase::reset() +Formula::reset() { } bool -FormulaBase::zero() const +Formula::zero() const { VResult vec; result(vec); @@ -214,47 +245,16 @@ FormulaBase::zero() const } void -FormulaBase::update(Info *) +Formula::update() { } string -FormulaBase::str() const +Formula::str() const { return root ? root->str() : ""; } -Formula::Formula() -{ - setInit(); -} - -Formula::Formula(Temp r) -{ - root = r; - assert(size()); -} - -const Formula & -Formula::operator=(Temp r) -{ - assert(!root && "Can't change formulas"); - root = r; - assert(size()); - return *this; -} - -const Formula & -Formula::operator+=(Temp r) -{ - if (root) - root = NodePtr(new BinaryNode<std::plus<Result> >(root, r)); - else - root = r; - assert(size()); - return *this; -} - void check() { |