-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovingMean.h
65 lines (54 loc) · 1.07 KB
/
MovingMean.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* File: MovingMean.h
*
* Author: Giacomo Benincasa (me@gbenin.casa)
*
* Created on October 30, 2011, 1:22 AM
*/
#ifndef ADS_MOVING_MEAN_H
#define ADS_MOVING_MEAN_H
namespace ADS
{
template<class T>
class MovingMean
{
public:
MovingMean (void);
virtual ~MovingMean (void);
void add (T val);
double getMean (void);
void reset (void);
private:
T _total;
unsigned long int _uiNValues;
};
template<class T>
MovingMean<T>::MovingMean()
{
reset();
}
template<class T>
MovingMean<T>::~MovingMean()
{
}
template<class T>
void MovingMean<T>::add (T val)
{
_total += val;
_uiNValues++;
}
template<class T>
double MovingMean<T>::getMean()
{
if (_uiNValues == 0)
return 0;
return (_total / _uiNValues);
}
template<class T>
void MovingMean<T>::reset()
{
_total = 0;
_uiNValues = 0;
}
}
#endif /* ADS_MOVING_MEAN_H */