changeset 7674070ccc92 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=7674070ccc92
description:
        stats: Add a wrapper class for the information side of things.
        This provides an easy way to provide the callbacks into the data side
        of things from the info side of things.  Rename Wrap to DataWrap so it
        is more easily distinguishable from InfoWrap

diffstat:

1 file changed, 98 insertions(+), 125 deletions(-)
src/base/statistics.hh |  223 +++++++++++++++++++++---------------------------

diffs (truncated from 538 to 300 lines):

diff -r 2c9823c60c8c -r 7674070ccc92 src/base/statistics.hh
--- a/src/base/statistics.hh    Thu Mar 05 19:09:53 2009 -0800
+++ b/src/base/statistics.hh    Thu Mar 05 19:09:53 2009 -0800
@@ -115,7 +115,7 @@
     virtual ~Info();
 
     /**
-     * Reset the corresponding stat to the default state.
+     * Reset the stat to the default state.
      */
     virtual void reset() = 0;
 
@@ -149,6 +149,20 @@
     static bool less(Info *stat1, Info *stat2);
 };
 
+template <class Stat, class Base>
+class InfoWrap : public Base
+{
+  protected:
+    Stat &s;
+
+  public:
+    InfoWrap(Stat &stat) : s(stat) {}
+
+    bool check() const { return s.check(); }
+    void reset() { s.reset(); }
+    bool zero() const { return s.zero(); }
+};
+
 class ScalarInfoBase : public Info
 {
   public:
@@ -159,20 +173,14 @@
 };
 
 template <class Stat>
-class ScalarInfo : public ScalarInfoBase
+class ScalarInfo : public InfoWrap<Stat, ScalarInfoBase>
 {
-  protected:
-    Stat &s;
+  public:
+    ScalarInfo(Stat &stat) : InfoWrap<Stat, ScalarInfoBase>(stat) {}
 
-  public:
-    ScalarInfo(Stat &stat) : s(stat) {}
-
-    bool check() const { return s.check(); }
-    Counter value() const { return s.value(); }
-    Result result() const { return s.result(); }
-    Result total() const { return s.total(); }
-    void reset() { s.reset(); }
-    bool zero() const { return s.zero(); }
+    Counter value() const { return this->s.value(); }
+    Result result() const { return this->s.result(); }
+    Result total() const { return this->s.total(); }
 };
 
 class VectorInfoBase : public Info
@@ -203,43 +211,38 @@
 };
 
 template <class Stat>
-class VectorInfo : public VectorInfoBase
+class VectorInfo : public InfoWrap<Stat, VectorInfoBase>
 {
   protected:
-    Stat &s;
     mutable VCounter cvec;
     mutable VResult rvec;
 
   public:
-    VectorInfo(Stat &stat) : s(stat) {}
+    VectorInfo(Stat &stat) : InfoWrap<Stat, VectorInfoBase>(stat) {}
 
-    bool check() const { return s.check(); }
-    bool zero() const { return s.zero(); }
-    void reset() { s.reset(); }
-
-    size_type size() const { return s.size(); }
+    size_type size() const { return this->s.size(); }
 
     VCounter &
     value() const
     {
-        s.value(cvec);
+        this->s.value(cvec);
         return cvec;
     }
 
     const VResult &
     result() const
     {
-        s.result(rvec);
+        this->s.result(rvec);
         return rvec;
     }
 
-    Result total() const { return s.total(); }
+    Result total() const { return this->s.total(); }
 
     void
     visit(Visit &visitor)
     {
-        update();
-        s.update(this);
+        this->update();
+        this->s.update(this);
         visitor.visit(*this);
     }
 };
@@ -266,22 +269,15 @@
 };
 
 template <class Stat>
-class DistInfo : public DistInfoBase
+class DistInfo : public InfoWrap<Stat, DistInfoBase>
 {
-  protected:
-    Stat &s;
-
   public:
-    DistInfo(Stat &stat) : s(stat) {}
-
-    bool check() const { return s.check(); }
-    void reset() { s.reset(); }
-    bool zero() const { return s.zero(); }
+    DistInfo(Stat &stat) : InfoWrap<Stat, DistInfoBase>(stat) {}
 
     void
     visit(Visit &visitor)
     {
-        s.update(this);
+        this->s.update(this);
         visitor.visit(*this);
     }
 };
@@ -315,24 +311,18 @@
 };
 
 template <class Stat>
-class VectorDistInfo : public VectorDistInfoBase
+class VectorDistInfo : public InfoWrap<Stat, VectorDistInfoBase>
 {
-  protected:
-    Stat &s;
+  public:
+    VectorDistInfo(Stat &stat) : InfoWrap<Stat, VectorDistInfoBase>(stat) {}
 
-  public:
-    VectorDistInfo(Stat &stat) : s(stat) {}
-
-    bool check() const { return s.check(); }
-    void reset() { s.reset(); }
-    size_type size() const { return s.size(); }
-    bool zero() const { return s.zero(); }
+    size_type size() const { return this->s.size(); }
 
     void
     visit(Visit &visitor)
     {
-        update();
-        s.update(this);
+        this->update();
+        this->s.update(this);
         visitor.visit(*this);
     }
 };
@@ -360,23 +350,16 @@
 };
 
 template <class Stat>
-class Vector2dInfo : public Vector2dInfoBase
+class Vector2dInfo : public InfoWrap<Stat, Vector2dInfoBase>
 {
-  protected:
-    Stat &s;
-
   public:
-    Vector2dInfo(Stat &stat) : s(stat) {}
-
-    bool check() const { return s.check(); }
-    void reset() { s.reset(); }
-    bool zero() const { return s.zero(); }
+    Vector2dInfo(Stat &stat) : InfoWrap<Stat, Vector2dInfoBase>(stat) {}
 
     void
     visit(Visit &visitor)
     {
-        update();
-        s.update(this);
+        this->update();
+        this->s.update(this);
         visitor.visit(*this);
     }
 };
@@ -395,10 +378,29 @@
     Info *info();
     /** Grab the information class for this statistic */
     const Info *info() const;
+
+  public:
+    /**
+     * Reset the stat to the default state.
+     */
+    void reset() {}
+
+    /**
+     * @return true if this stat has a value and satisfies its
+     * requirement as a prereq
+     */
+    bool zero() const { return true; }
+
+    /**
+     * Check that this stat has been set up properly and is ready for
+     * use
+     * @return true for success
+     */
+    bool check() const { return true; }
 };
 
 template <class Derived, class Base, template <class> class Info>
-class Wrap : public Base
+class DataWrap : public Base
 {
   public:
     typedef Derived DerivedType;
@@ -426,15 +428,15 @@
     /**
      * Copy constructor, copies are not allowed.
      */
-    Wrap(const Wrap &stat);
+    DataWrap(const DataWrap &stat);
 
     /**
      * Can't copy stats.
      */
-    void operator=(const Wrap &);
+    void operator=(const DataWrap &);
 
   public:
-    Wrap()
+    DataWrap()
     {
         this->setInfo(new InfoType(*this));
     }
@@ -506,7 +508,7 @@
 };
 
 template <class Derived, class Base, template <class Base> class Info>
-class WrapVec : public Wrap<Derived, Base, Info>
+class DataWrapVec : public DataWrap<Derived, Base, Info>
 {
   public:
     typedef Derived DerivedType;
@@ -555,7 +557,7 @@
 };
 
 template <class Derived, class Base, template <class Base> class Info>
-class WrapVec2d : public WrapVec<Derived, Base, Info>
+class DataWrapVec2d : public DataWrapVec<Derived, Base, Info>
 {
   public:
     typedef Derived DerivedType;
@@ -842,8 +844,6 @@
      */
     size_type size() const { return 1; }
 
-    bool check() const { return true; }
-
     /**
      * Reset stat value to default
      */
@@ -856,7 +856,6 @@
     Result total() { return result(); }
 
     bool zero() { return result() == 0.0; }
-
 };
 
 class ProxyInfo : public ScalarInfoBase
@@ -865,9 +864,9 @@
     void visit(Visit &visitor) { visitor.visit(*this); }
     std::string str() const { return to_string(value()); }
     size_type size() const { return 1; }
+    bool check() const { return true; }
+    void reset() {}
     bool zero() const { return value() == 0; }
-    bool check() const { return true; }
-    void reset() { }
 };
 
 template <class T>
@@ -1057,11 +1056,6 @@
      */
     size_type size() const { return 1; }
 
-    /**
-     * This stat has no state.  Nothing to reset
_______________________________________________
m5-dev mailing list
m5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to