LibreOffice Module canvas (master)  1
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
canvas::tools::ElapsedTime Class Reference

Calculate elapsed time. More...

#include <elapsedtime.hxx>

Public Member Functions

 ElapsedTime ()
 Create a new ElapsedTime object. More...
 
 ElapsedTime (std::shared_ptr< ElapsedTime > const &pTimeBase)
 Creates a new ElapsedTime object based on another timer. More...
 
void reset ()
 Reset the time. More...
 
double getElapsedTime () const
 Query the elapsed time. More...
 
void pauseTimer ()
 Pauses the running timer. More...
 
void continueTimer ()
 Continues the paused timer. More...
 
void adjustTimer (double fOffset)
 Adjusts the timer, hold and pause times. More...
 
void holdTimer ()
 Holds the current time. More...
 
void releaseTimer ()
 Releases a held timer. More...
 

Private Member Functions

double getCurrentTime () const
 
double getElapsedTimeImpl () const
 

Static Private Member Functions

static double getSystemTime ()
 

Private Attributes

const std::shared_ptr< ElapsedTimem_pTimeBase
 
double m_fLastQueriedTime
 To validate adjustTimer() calls with bLimitToLastQueriedTime=true. More...
 
double m_fStartTime
 Start time, from which the difference to the time base is returned. More...
 
double m_fFrozenTime
 Instant, when last pause or hold started, relative to m_fStartTime. More...
 
bool m_bInPauseMode
 True, when in pause mode. More...
 
bool m_bInHoldMode
 True, when in hold mode. More...
 

Detailed Description

Calculate elapsed time.

This class provides several time-measurement and -management functions. In its simplest use-case, it measures the time from its creation.

Definition at line 36 of file elapsedtime.hxx.

Constructor & Destructor Documentation

canvas::tools::ElapsedTime::ElapsedTime ( )

Create a new ElapsedTime object.

The moment of construction starts the time measurement. That means, a subsequent getElapsedTime() call will return the time difference between object creation and getElapsedTime() call.

Definition at line 37 of file elapsedtime.cxx.

canvas::tools::ElapsedTime::ElapsedTime ( std::shared_ptr< ElapsedTime > const &  pTimeBase)

Creates a new ElapsedTime object based on another timer.

The moment of construction starts the time measurement. That means, a subsequent getElapsedTime() call will return the time difference between object creation and getElapsedTime() call. All time values are not taken from the system's time base, but from the provided timer.

Definition at line 47 of file elapsedtime.cxx.

Member Function Documentation

void canvas::tools::ElapsedTime::adjustTimer ( double  fOffset)

Adjusts the timer, hold and pause times.

This method modifies the time as returned by this object by the specified amount. This affects the time as returned by getElapsedTime(), regardless of the mode (e.g. paused, or on hold).

Parameters
fOffsetThis value will be added to the current time, i.e. the next call to getElapsedTime() (when performed immediately) will be adjusted by fOffset.

Definition at line 67 of file elapsedtime.cxx.

References m_bInHoldMode, m_bInPauseMode, m_fFrozenTime, and m_fStartTime.

void canvas::tools::ElapsedTime::continueTimer ( )

Continues the paused timer.

This method re-enables the time flow, that is, time starts running again for clients calling getElapsedTime(). The (subtle) difference to the holdTimer/releaseTimer() methods below is, that there is no perceived time 'jump' between the pauseTimer() call and the continueTimer() call, i.e. the time starts over with the same value it has stopped on pauseTimer().

Definition at line 104 of file elapsedtime.cxx.

References getElapsedTimeImpl(), m_bInPauseMode, m_fFrozenTime, and m_fStartTime.

double canvas::tools::ElapsedTime::getCurrentTime ( ) const
private

Definition at line 79 of file elapsedtime.cxx.

References getSystemTime(), and m_pTimeBase.

Referenced by getElapsedTimeImpl(), and reset().

double canvas::tools::ElapsedTime::getElapsedTime ( ) const

Query the elapsed time.

This method returns the elapsed time in seconds between either the construction of this object, or the last reset() call, if any (but see the time modulation methods below, for means to modify the otherwise continuous flow of time).

Returns
the elapsed time in seconds.

Definition at line 84 of file elapsedtime.cxx.

References getElapsedTimeImpl(), and m_fLastQueriedTime.

Referenced by vclcanvas::SpriteCanvasHelper::renderFrameCounter().

double canvas::tools::ElapsedTime::getElapsedTimeImpl ( ) const
private
double canvas::tools::ElapsedTime::getSystemTime ( )
staticprivate

Definition at line 32 of file elapsedtime.cxx.

Referenced by getCurrentTime().

void canvas::tools::ElapsedTime::holdTimer ( )

Holds the current time.

This call makes the timer hold the current time (e.g. getElapsedTime() will return the time when holdTimer() was called), while the underlying time is running on. When releaseTimer() is called, the time will 'jump' to the then-current, underlying time. This is equivalent to pressing the "interim time" button on a stop watch, which shows this stopped time, while the clock keeps running internally.

Definition at line 118 of file elapsedtime.cxx.

References getElapsedTimeImpl(), m_bInHoldMode, and m_fFrozenTime.

void canvas::tools::ElapsedTime::pauseTimer ( )

Pauses the running timer.

This method stops the time, as returned by this object, until continueTimer() is called. During this period, getElapsedTime() will always return the same time value (i.e. the instant when pauseTimer() was called).

Definition at line 98 of file elapsedtime.cxx.

References getElapsedTimeImpl(), m_bInPauseMode, and m_fFrozenTime.

void canvas::tools::ElapsedTime::releaseTimer ( )

Releases a held timer.

After this call, the timer again returns the running time on getElapsedTime().

Definition at line 126 of file elapsedtime.cxx.

References m_bInHoldMode.

void canvas::tools::ElapsedTime::reset ( )

Reset the time.

The instance of the reset() call starts the time measurement from scratch. That means, a subsequent getElapsedTime() call will return the time difference between reset() and getElapsedTime() call.

Definition at line 58 of file elapsedtime.cxx.

References getCurrentTime(), m_bInHoldMode, m_bInPauseMode, m_fFrozenTime, m_fLastQueriedTime, and m_fStartTime.

Referenced by vclcanvas::SpriteCanvasHelper::renderFrameCounter().

Member Data Documentation

bool canvas::tools::ElapsedTime::m_bInHoldMode
private

True, when in hold mode.

Definition at line 158 of file elapsedtime.hxx.

Referenced by adjustTimer(), getElapsedTimeImpl(), holdTimer(), releaseTimer(), and reset().

bool canvas::tools::ElapsedTime::m_bInPauseMode
private

True, when in pause mode.

Definition at line 155 of file elapsedtime.hxx.

Referenced by adjustTimer(), continueTimer(), getElapsedTimeImpl(), pauseTimer(), and reset().

double canvas::tools::ElapsedTime::m_fFrozenTime
private

Instant, when last pause or hold started, relative to m_fStartTime.

Definition at line 152 of file elapsedtime.hxx.

Referenced by adjustTimer(), continueTimer(), getElapsedTimeImpl(), holdTimer(), pauseTimer(), and reset().

double canvas::tools::ElapsedTime::m_fLastQueriedTime
mutableprivate

To validate adjustTimer() calls with bLimitToLastQueriedTime=true.

Definition at line 146 of file elapsedtime.hxx.

Referenced by getElapsedTime(), and reset().

double canvas::tools::ElapsedTime::m_fStartTime
private

Start time, from which the difference to the time base is returned.

Definition at line 149 of file elapsedtime.hxx.

Referenced by adjustTimer(), continueTimer(), getElapsedTimeImpl(), and reset().

const std::shared_ptr<ElapsedTime> canvas::tools::ElapsedTime::m_pTimeBase
private

Definition at line 143 of file elapsedtime.hxx.

Referenced by getCurrentTime().


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