| 1 |
#ifndef _PROTO_AVERAGE |
| 2 |
#define _PROTO_AVERAGE |
| 3 |
|
| 4 |
/** |
| 5 |
* @class ProtoAverage |
| 6 |
* |
| 7 |
* @brief The ProtoAverage uses the proto list class to keep |
| 8 |
* a sub averaged record of numbers to be averaged. This will |
| 9 |
* allow for averaging of VERY large sets of numbers with minimal |
| 10 |
* rounding and overflow errors along with minimal memory storage. |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "protoDefs.h" |
| 14 |
#include "protoList.h" |
| 15 |
|
| 16 |
class ProtoAverage |
| 17 |
{ |
| 18 |
public: |
| 19 |
ProtoAverage(); |
| 20 |
~ProtoAverage(); |
| 21 |
void Reset(); |
| 22 |
bool AddNumber(double number); |
| 23 |
double GetAverage(); |
| 24 |
unsigned long GetCount() const; |
| 25 |
void Print(); |
| 26 |
private: |
| 27 |
class AverageItem : public ProtoList::Item |
| 28 |
{ |
| 29 |
friend class ProtoAverage; |
| 30 |
public: |
| 31 |
AverageItem(double v) : value(v) , depth(0) , factor(1) {} |
| 32 |
double GetValue() const {return value;} |
| 33 |
double GetDepth() const {return depth;} |
| 34 |
double GetFactor() const {return factor;} |
| 35 |
bool Merge(const ProtoAverage::AverageItem &otherItem); |
| 36 |
private: |
| 37 |
double value; |
| 38 |
double depth; |
| 39 |
double factor; |
| 40 |
void SetValue(double v); |
| 41 |
void SetDepth(double d); |
| 42 |
}; |
| 43 |
//this is the list used to store the values along with depth information on the values |
| 44 |
class AverageList : public ProtoListTemplate<AverageItem> {}; |
| 45 |
AverageList list; |
| 46 |
unsigned long count; |
| 47 |
}; |
| 48 |
#endif |