41 #ifndef _rollingaverage_h
42 #define _rollingaverage_h
64 virtual void Insert(RecordType Datum) = 0;
105 typename std::vector<RecordType>::iterator
Current;
111 { Current = Records.begin(); }
122 Records.assign(RecordCount,RecordType(0));
123 Current = Records.begin();
128 {
return Records.size(); }
142 RecordType Results(0);
143 for(
typename std::vector<RecordType>::const_iterator Iter = Records.begin(); Iter!=Records.end(); ++Iter)
145 return Results/Records.size();
152 this->Current=this->Records.end() - (Rhs.
Records.end()-Rhs.
Current);
153 this->Records = std::vector<Type> (Rhs.
Records);
161 this->Current=this->Records.end() - (Rhs.
Records.end()-Rhs.
Current);
162 this->Records = std::vector<Type> (Rhs.
Records);
170 typename std::vector<RecordType>::iterator Iter = this->
Current;
172 for(
Whole C = 0; C<=Index; C++)
174 if(Records.end() == ++Iter)
175 { Iter = Records.begin(); }
186 typename std::vector<RecordType>::const_iterator Iter = this->
Current;
188 for(
Whole C = 0; C<=Index; C++)
190 if(Records.end() == ++Iter)
191 { Iter = Records.begin(); }
239 CurrentAverage = ( MathType(this->CurrentAverage) ? MathType(this->CurrentAverage) : MathType(1))
266 template<
class RecordType>
WeightedRollingAverage< RecordType, RecordType > Type
The Default rolling average for all types is currently BufferedRollingAverage, this could change with...
Use this to get the default rolling average for a given type.
virtual RecordType GetAverage() const =0
What is the current rolling average.
A weighted average that does math with every insertion and stores nothing.
virtual Whole RecordCapacity() const
Gets the capacity of this rolling average. How many records will this store.
virtual RecordType GetAverage() const
Add up all the records and divide by the count. A simple arithmetic mean.
WeightedRollingAverage(const Whole &Ignored=MEZZ_FRAMESTOTRACK)
Class Constructor.
BufferedRollingAverage(const Whole &RecordCount=MEZZ_FRAMESTOTRACK)
Constructor.
virtual Whole RecordCapacity() const =0
How many records does this use to calculate its wolling average.
All the definitions for datatypes as well as some basic conversion functions are defined here...
virtual RecordType & operator[](Whole Index)
Get an accurate record of insertions up to RecordCapacity()
std::vector< RecordType > Records
The collection of all the records that are being have been added going back as far as the capacity wi...
RecordType Type
Used for accessing the derived type when it may not be directly known.
virtual void IncrementIterator()
Move Current to the next place to be written.
virtual ~BufferedRollingAverage()
Deconstructor.
BufferedRollingAverage(const BufferedRollingAverage &Rhs)
Copy constructor, performs deep copy.
virtual RecordType & operator[](Whole)
Get the last insertion.
virtual ~WeightedRollingAverage()
Class Destructor.
RecordType LastEntry
Sometimes retrieving the value just inserted is too useful.
virtual void Insert(RecordType Datum)=0
Add another record.
The interface for rolling averages used in the Mezzanine, and threading library.
virtual RecordType GetAverage() const
Get the current rolling average.
RecordType CurrentAverage
What the math says the current avergage is.
virtual ~RollingAverage()
Empty virtual Destructor.
A RollingAverage that stores a copy of each record. and does the math when queried.
virtual void Insert(RecordType Datum)
Update the currently stored Rolling average with a new data point/record.
std::vector< RecordType >::iterator Current
The iterator used to treat an std::vector as a circular buffer.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
virtual RecordType & operator[](Whole Index)=0
Get a 0 indexed record of the past few insertions.
RecordType Type
Used for accessing the derived type when it may not be directly known.
RecordType Type
Used for accessing the derived type when it may not be directly known.
virtual void Insert(RecordType Datum)
Inserts a new record into the rolling average and if needed drops the oldest one out.
virtual Whole RecordCapacity() const
Returns how many records this is emulating.
BufferedRollingAverage & operator=(const BufferedRollingAverage &Rhs)
Assignment operator, performs deep copy.