# HG changeset patch # User Giulio Moro # Date 1442239074 -3600 # Node ID 5edc6d0713ef26271897cc3bc387683ea353f37a # Parent 4e2dd3eb1d2886150a4d5ac013e99d7702125831 MovingAverage: added reset() method and edited getLength() to return current length diff -r 4e2dd3eb1d28 -r 5edc6d0713ef include/stats.hpp --- a/include/stats.hpp Sun Sep 13 21:34:47 2015 +0100 +++ b/include/stats.hpp Mon Sep 14 14:57:54 2015 +0100 @@ -28,8 +28,7 @@ if(array==NULL) printf("Error while allocating array\n"); memset(array, 0, sizeof(TYPE)*length); - pointer=0; - bufferFull=false; + reset(); } public: MovingAverage(){ @@ -42,7 +41,7 @@ dealloc(); } int getLength(){ - return length; + return bufferFull ? length : pointer; } void setLength(int aLength){ dealloc(); @@ -68,6 +67,10 @@ double getAverage(){ return average; } + void reset(){ + pointer=0; + bufferFull=false; + } }; #endif /* STATS_HPP_INCLUDED */