RobWorkProject
24.12.4-
|
The timer class provides an easy to use platform independent timer. More...
#include <Timer.hpp>
Public Member Functions | |
Timer () | |
Constructor. More... | |
Timer (long timems) | |
constructor - initialize the timer to a specified value. This does not start the timer. More... | |
Timer (int hh, int mm, int ss=0, int ms=0) | |
constructor - initialize the timer to a specified value. This does not start the timer. More... | |
virtual | ~Timer () |
Destructor. | |
bool | isPaused () |
Returns true if the timer is paused. More... | |
void | reset () |
Reset the timer. More... | |
void | resetAndPause () |
Resets and pauses the timer. More... | |
void | resetAndResume () |
Resets and stats the timer. More... | |
void | pause () |
Pause the timer. More... | |
void | resume () |
Resume the timer after a pause. More... | |
double | getTime () const |
The time the timer has been running. More... | |
long | getTimeSec () const |
The time the timer has been running in hole seconds. More... | |
long | getTimeMs () const |
The time the timer has been running in mili seconds. More... | |
std::string | toString (const std::string &format="hh:mm:ss") |
returns a string describing the time. The format of the time is described using format More... | |
Static Public Member Functions | |
static long | currentTimeSec () |
Returns system clock in hole seconds. More... | |
static long | currentTimeMs () |
Returns system clock in milli-seconds. More... | |
static long | currentTimeUs () |
Returns system clock in micro-seconds. More... | |
static double | currentTime () |
Returns system clock in seconds. More... | |
static void | sleepMs (int period) |
Sleeps for a period of time. More... | |
static void | sleepUs (int period) |
Sleeps for a period of time. More... | |
The timer class provides an easy to use platform independent timer.
In Windows the expected resolution is approx. 16ms. In Linux the expected resolution is approx. 1ms
Timer | ( | ) |
Constructor.
This implicitly starts the timer.
Timer | ( | long | timems | ) |
constructor - initialize the timer to a specified value. This does not start the timer.
timems | [in] time in ms |
Timer | ( | int | hh, |
int | mm, | ||
int | ss = 0 , |
||
int | ms = 0 |
||
) |
constructor - initialize the timer to a specified value. This does not start the timer.
hh | [in] hours |
mm | [in] minutes |
ss | [in] seconds |
ms | [in] milli seconds |
|
inlinestatic |
Returns system clock in seconds.
|
inlinestatic |
Returns system clock in milli-seconds.
|
inlinestatic |
Returns system clock in hole seconds.
|
inlinestatic |
Returns system clock in micro-seconds.
Notice: The timer cannot hold times longer than approx. 2100second.
double getTime | ( | ) | const |
The time the timer has been running.
The time passed while the timer has been paused are not included in the running time. The timer is paused when pause() has been called and counting is resumed when resume() has been called.
It is perfectly OK and natural to call getTime() on a running timer, i.e. a timer that has not been paused.
A call of reset() resets the running time to zero.
long getTimeMs | ( | ) | const |
The time the timer has been running in mili seconds.
see getTime
long getTimeSec | ( | ) | const |
The time the timer has been running in hole seconds.
see getTime
bool isPaused | ( | ) |
Returns true if the timer is paused.
void pause | ( | ) |
Pause the timer.
The timer stops counting. As long as the timer has not been resumed (see resume()) or restarted (see reset()) the timer value (see getTime()) will stay the same.
Is is OK to call pause() on a timer that has already been paused: The timer will just stay paused and nothing is changed.
void reset | ( | ) |
Reset the timer.
The timer is set back to zero and starts counting.
It is OK to call reset() on a timer that has already been started: The time will just be set back to zero again.
void resetAndPause | ( | ) |
Resets and pauses the timer.
The timer is set to zero and paused
It is OK to call reset() on a timer that has already been started: The time will just be set back to zero again.
void resetAndResume | ( | ) |
void resume | ( | ) |
Resume the timer after a pause.
The timer starts counting again.
It is OK to call resume() on a timer that is already counting: The timer keeps counting and nothing is done.
|
inlinestatic |
Sleeps for a period of time.
period | [in] the time in miliseconds to sleep |
|
inlinestatic |
Sleeps for a period of time.
period | [in] the time in microseconds to sleep |
std::string toString | ( | const std::string & | format = "hh:mm:ss" | ) |
returns a string describing the time. The format of the time is described using format
format | [in] the format is on the form: hh:mm:ss --> 05:06:08 h:m:s --> 5:6:8 |