RobWorkProject  24.12.4-
Public Member Functions | Static Public Member Functions | List of all members
Timer Class Reference

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...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Timer() [1/3]

Timer ( )

Constructor.

This implicitly starts the timer.

◆ Timer() [2/3]

Timer ( long  timems)

constructor - initialize the timer to a specified value. This does not start the timer.

Parameters
timems[in] time in ms

◆ Timer() [3/3]

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.

Parameters
hh[in] hours
mm[in] minutes
ss[in] seconds
ms[in] milli seconds

Member Function Documentation

◆ currentTime()

static double currentTime ( )
inlinestatic

Returns system clock in seconds.

Warning
The date/time at which this timer counts from is platform-specific, so you should not use it for getting the calendar time. It's really only meant for calculating wall time differences.

◆ currentTimeMs()

static long currentTimeMs ( )
inlinestatic

Returns system clock in milli-seconds.

Warning
The date/time at which this timer counts from is platform-specific, so you should not use it for getting the calendar time. It's really only meant for calculating wall time differences.

◆ currentTimeSec()

static long currentTimeSec ( )
inlinestatic

Returns system clock in hole seconds.

Warning
The date/time at which this timer counts from is platform-specific, so you should not use it for getting the calendar time. It's really only meant for calculating wall time differences.

◆ currentTimeUs()

static long currentTimeUs ( )
inlinestatic

Returns system clock in micro-seconds.

Warning
The date/time at which this timer counts from is platform-specific, so you should not use it for getting the calendar time. It's really only meant for calculating wall time differences.

Notice: The timer cannot hold times longer than approx. 2100second.

◆ getTime()

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.

Returns
Time in seconds

◆ getTimeMs()

long getTimeMs ( ) const

The time the timer has been running in mili seconds.

see getTime

Returns
Time in mili seconds

◆ getTimeSec()

long getTimeSec ( ) const

The time the timer has been running in hole seconds.

see getTime

Returns
Time in hole seconds

◆ isPaused()

bool isPaused ( )

Returns true if the timer is paused.

Returns
True is paused

◆ pause()

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.

◆ reset()

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.

◆ resetAndPause()

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.

◆ resetAndResume()

void resetAndResume ( )

Resets and stats the timer.

Same as reset()

The timer is set 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.

◆ resume()

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.

◆ sleepMs()

static void sleepMs ( int  period)
inlinestatic

Sleeps for a period of time.

Parameters
period[in] the time in miliseconds to sleep

◆ sleepUs()

static void sleepUs ( int  period)
inlinestatic

Sleeps for a period of time.

Parameters
period[in] the time in microseconds to sleep

◆ toString()

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

Parameters
format[in] the format is on the form: hh:mm:ss --> 05:06:08 h:m:s --> 5:6:8
Returns
a formated time string

The documentation for this class was generated from the following file: