some more refactoring for stopwatch
This commit is contained in:
@ -8,6 +8,11 @@
|
||||
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
||||
#include <framework/timemanager/Clock.h>
|
||||
|
||||
enum class StopwatchDisplayMode {
|
||||
MS_DOUBLE,
|
||||
MS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Simple Stopwatch implementation to measure elapsed time
|
||||
* @details
|
||||
@ -15,24 +20,38 @@
|
||||
* times automatically on destruction if not explicitely deactivated in the
|
||||
* constructor. The default time format is the elapsed time in miliseconds
|
||||
* as a float.
|
||||
* This class caches the value
|
||||
*/
|
||||
class Stopwatch {
|
||||
enum class DisplayMode {
|
||||
MS_DOUBLE,
|
||||
MS
|
||||
};
|
||||
|
||||
Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode =
|
||||
DisplayMode::MS_DOUBLE);
|
||||
Stopwatch(bool displayOnDestruction = true,
|
||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE);
|
||||
virtual~ Stopwatch();
|
||||
|
||||
/**
|
||||
* Caches the start time
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in milliseconds (rounded)
|
||||
*/
|
||||
ms_normal_t stop();
|
||||
|
||||
/**
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in milliseconds (doulbe precision)
|
||||
*/
|
||||
ms_double_t stopPrecise();
|
||||
|
||||
/**
|
||||
* Displays the elapsed times on the osstream, depending on internal display
|
||||
* mode.
|
||||
*/
|
||||
void display();
|
||||
|
||||
StopwatchDisplayMode getDisplayMode() const;
|
||||
void setDisplayMode(StopwatchDisplayMode displayMode);
|
||||
private:
|
||||
|
||||
timeval startTime {0, 0};
|
||||
@ -40,7 +59,7 @@ private:
|
||||
double elapsedTimeMsDouble = 0;
|
||||
|
||||
bool displayOnDestruction = true;
|
||||
DisplayMode displayMode = DisplayMode::MS_DOUBLE;
|
||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE;
|
||||
|
||||
void stopInternal();
|
||||
};
|
||||
|
Reference in New Issue
Block a user