virtual ~Info();
/**
- * Reset the corresponding stat to the default state.
+ * Reset the stat to the default state.
*/
virtual void reset() = 0;
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:
};
template <class Stat>
-class ScalarInfo : public ScalarInfoBase
+class ScalarInfo : public InfoWrap<Stat, ScalarInfoBase>
{
- protected:
- Stat &s;
-
public:
- ScalarInfo(Stat &stat) : s(stat) {}
+ ScalarInfo(Stat &stat) : InfoWrap<Stat, ScalarInfoBase>(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
};
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) {}
-
- bool check() const { return s.check(); }
- bool zero() const { return s.zero(); }
- void reset() { s.reset(); }
+ VectorInfo(Stat &stat) : InfoWrap<Stat, VectorInfoBase>(stat) {}
- 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);
}
};
};
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);
}
};
};
template <class Stat>
-class VectorDistInfo : public VectorDistInfoBase
+class VectorDistInfo : public InfoWrap<Stat, VectorDistInfoBase>
{
- protected:
- Stat &s;
-
public:
- VectorDistInfo(Stat &stat) : s(stat) {}
+ VectorDistInfo(Stat &stat) : InfoWrap<Stat, VectorDistInfoBase>(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);
}
};
};
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);
}
};
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;
/**
* 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));
}
};
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;
};
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;
*/
size_type size() const { return 1; }
- bool check() const { return true; }
-
/**
* Reset stat value to default
*/
Result total() { return result(); }
bool zero() { return result() == 0.0; }
-
};
class ProxyInfo : public ScalarInfoBase
void visit(Visit &visitor) { visitor.visit(*this); }
std::string str() const { return to_string(value()); }
size_type size() const { return 1; }
- bool zero() const { return value() == 0; }
bool check() const { return true; }
- void reset() { }
+ void reset() {}
+ bool zero() const { return value() == 0; }
};
template <class T>
*/
size_type size() const { return 1; }
- /**
- * This stat has no state. Nothing to reset
- */
- void reset() { }
-
public:
std::string
str() const
}
size_type size() const { return len; }
-
- /**
- * This stat has no state. Nothing to reset.
- */
- void reset() { }
};
template <class Stor>
}
bool
- check()
+ check() const
{
return storage != NULL;
}
{
data()->reset(info());
}
-
- bool
- check()
- {
- return true;
- }
};
template <class Stat>
}
bool
- check()
+ check() const
{
return storage != NULL;
}
* @sa Stat, ScalarBase, StatStor
*/
template<int N = 0>
-class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarInfo>
+class Scalar : public DataWrap<Scalar<N>, ScalarBase<StatStor>, ScalarInfo>
{
public:
/** The base implementation. */
void operator=(const U &v) { Base::operator=(v); }
};
-class Value : public Wrap<Value, ValueBase, ScalarInfo>
+class Value : public DataWrap<Value, ValueBase, ScalarInfo>
{
public:
/** The base implementation. */
* @sa Stat, ScalarBase, AvgStor
*/
template<int N = 0>
-class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarInfo>
+class Average : public DataWrap<Average<N>, ScalarBase<AvgStor>, ScalarInfo>
{
public:
/** The base implementation. */
* @sa Stat, VectorBase, StatStor
*/
template<int N = 0>
-class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorInfo>
+class Vector : public DataWrapVec<Vector<N>, VectorBase<StatStor>, VectorInfo>
{
public:
/** The base implementation. */
*/
template<int N = 0>
class AverageVector
- : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorInfo>
+ : public DataWrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorInfo>
{
public:
/**
*/
template<int N = 0>
class Vector2d
- : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dInfo>
+ : public DataWrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dInfo>
{
public:
Vector2d &
*/
template<int N = 0>
class Distribution
- : public Wrap<Distribution<N>, DistBase<DistStor>, DistInfo>
+ : public DataWrap<Distribution<N>, DistBase<DistStor>, DistInfo>
{
public:
/** Base implementation. */
*/
template<int N = 0>
class StandardDeviation
- : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistInfo>
+ : public DataWrap<StandardDeviation<N>, DistBase<FancyStor>, DistInfo>
{
public:
/** The base implementation */
*/
template<int N = 0>
class AverageDeviation
- : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistInfo>
+ : public DataWrap<AverageDeviation<N>, DistBase<AvgFancy>, DistInfo>
{
public:
/** The base implementation */
*/
template<int N = 0>
class VectorDistribution
- : public WrapVec<VectorDistribution<N>,
- VectorDistBase<DistStor>,
- VectorDistInfo>
+ : public DataWrapVec<VectorDistribution<N>,
+ VectorDistBase<DistStor>,
+ VectorDistInfo>
{
public:
/** The base implementation */
*/
template<int N = 0>
class VectorStandardDeviation
- : public WrapVec<VectorStandardDeviation<N>,
- VectorDistBase<FancyStor>,
- VectorDistInfo>
+ : public DataWrapVec<VectorStandardDeviation<N>,
+ VectorDistBase<FancyStor>,
+ VectorDistInfo>
{
public:
/** The base implementation */
*/
template<int N = 0>
class VectorAverageDeviation
- : public WrapVec<VectorAverageDeviation<N>,
- VectorDistBase<AvgFancy>,
- VectorDistInfo>
+ : public DataWrapVec<VectorAverageDeviation<N>,
+ VectorDistBase<AvgFancy>,
+ VectorDistInfo>
{
public:
/** The base implementation */
*/
size_type size() const;
- bool check() const { return true; }
-
/**
* Formulas don't need to be reset
*/
{
public:
virtual std::string str() const = 0;
- bool check() const { return true; }
};
template <class Stat>
-class FormulaInfo : public FormulaInfoBase
+class FormulaInfo : public InfoWrap<Stat, FormulaInfoBase>
{
protected:
- Stat &s;
mutable VResult vec;
mutable VCounter cvec;
public:
- FormulaInfo(Stat &stat) : s(stat) {}
-
- bool zero() const { return s.zero(); }
- void reset() { s.reset(); }
+ FormulaInfo(Stat &stat) : InfoWrap<Stat, FormulaInfoBase>(stat) {}
- size_type size() const { return s.size(); }
+ size_type size() const { return this->s.size(); }
const VResult &
result() const
{
- s.result(vec);
+ this->s.result(vec);
return vec;
}
- Result total() const { return s.total(); }
+ Result total() const { return this->s.total(); }
VCounter &value() const { return cvec; }
void
visit(Visit &visitor)
{
- update();
- s.update(this);
+ this->update();
+ this->s.update(this);
visitor.visit(*this);
}
- std::string str() const { return s.str(); }
+ std::string str() const { return this->s.str(); }
};
class Temp;
-class Formula
- : public WrapVec<Formula,
- FormulaBase,
- FormulaInfo>
+class Formula : public DataWrapVec<Formula, FormulaBase, FormulaInfo>
{
public:
/**