9 #ifndef anna_core_util_Average_hpp 10 #define anna_core_util_Average_hpp 31 Average(
const char* name,
const char* measure = NULL) :
32 a_name(name), a_accumulator(0), a_n(0), a_measure(measure) {;}
38 bool isEmpty()
const {
return (a_n == 0); }
45 bool isZero()
const {
return a_n == 0 || a_accumulator == 0; }
51 int size()
const {
return a_n; }
64 T
value()
const {
return (
isEmpty() ==
true) ? T(0) : (a_accumulator / a_n); }
69 void clear() { a_accumulator = 0; a_n = 0; }
77 a_accumulator =
value;
86 operator T()
const {
return value(); }
95 a_accumulator =
value;
107 a_accumulator = other.a_accumulator;
119 const T backup(a_accumulator);
121 if((a_accumulator += v) < backup) {
137 if(a_accumulator > v && a_n > 1) {
154 std::string msg(a_name);
155 msg +=
" { Accumulate: ";
158 if(a_measure != NULL)
159 msg +=
" " + std::string(a_measure);
164 if(a_measure != NULL)
165 msg +=
" " + std::string(a_measure);
172 const char* a_measure;
T getAccumulator() const
Definition: Average.hpp:57
T value() const
Definition: Average.hpp:64
Average< T > & operator+=(const T &v)
Definition: Average.hpp:117
Definition: Average.hpp:24
static std::string asString(const int number)
Average(const char *name, const char *measure=NULL)
Definition: Average.hpp:31
int size() const
Definition: Average.hpp:51
bool isZero() const
Definition: Average.hpp:45
void setValue(const T &value, const unsigned int _n)
Definition: Average.hpp:76
Average< T > & operator-=(const T v)
Definition: Average.hpp:135
bool isEmpty() const
Definition: Average.hpp:38
std::string asString() const
Definition: Average.hpp:152
void clear()
Definition: Average.hpp:69
Average< T > & operator=(const T value)
Definition: Average.hpp:93