giuliomoro@135: #ifndef VIRTUAL_CLOCK_H_INCLUDED giuliomoro@135: #define VIRTUAL_CLOCK_H_INCLUDED giuliomoro@135: giuliomoro@135: #include "stats.hpp" giuliomoro@135: #include "Clock.h" giuliomoro@135: giuliomoro@135: class VirtualClock{ giuliomoro@135: private: giuliomoro@135: myClock_t startTime; giuliomoro@135: myClock_t lastSync; giuliomoro@135: bool firstRun; giuliomoro@135: double period; giuliomoro@135: MovingAverage movingAverage; giuliomoro@135: public: giuliomoro@135: void init(); giuliomoro@135: VirtualClock(); giuliomoro@135: /** giuliomoro@135: Call this method at regular intervals to sync che virtual clock giuliomoro@135: */ giuliomoro@135: void sync(); giuliomoro@135: /** giuliomoro@135: Call this method asynchronously, passing a number of equally spaced events that have elapsed since the last call. giuliomoro@135: */ giuliomoro@135: void sync(double count); giuliomoro@135: /** giuliomoro@135: Get the current time according to the VirtualClock. giuliomoro@135: giuliomoro@135: @return Time elapsed since the first call to sync(), in period units. giuliomoro@135: */ giuliomoro@135: double getNow(); giuliomoro@135: /** giuliomoro@135: Get the length of the period. giuliomoro@135: giuliomoro@135: Get the length of the period (difference between calls to sync() after various filtering operations) giuliomoro@135: */ giuliomoro@135: double getPeriod(); giuliomoro@135: }; giuliomoro@135: giuliomoro@135: #endif /* VIRTUAL_CLOCK_H_INCLUDED */