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 > xTimeBase)
 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 34 of file elapsedtime.hxx.

Constructor & Destructor Documentation

◆ ElapsedTime() [1/2]

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 34 of file elapsedtime.cxx.

◆ ElapsedTime() [2/2]

canvas::tools::ElapsedTime::ElapsedTime ( std::shared_ptr< ElapsedTime xTimeBase)

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 44 of file elapsedtime.cxx.

Member Function Documentation

◆ adjustTimer()

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 64 of file elapsedtime.cxx.

References m_bInHoldMode, m_bInPauseMode, m_fFrozenTime, and m_fStartTime.

◆ continueTimer()

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 101 of file elapsedtime.cxx.

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

◆ getCurrentTime()

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

Definition at line 76 of file elapsedtime.cxx.

References getSystemTime(), and m_pTimeBase.

Referenced by getElapsedTimeImpl(), and reset().

◆ getElapsedTime()

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 81 of file elapsedtime.cxx.

References getElapsedTimeImpl(), and m_fLastQueriedTime.

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

◆ getElapsedTimeImpl()

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

◆ getSystemTime()

double canvas::tools::ElapsedTime::getSystemTime ( )
staticprivate

Definition at line 29 of file elapsedtime.cxx.

Referenced by getCurrentTime().

◆ holdTimer()

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 115 of file elapsedtime.cxx.

References getElapsedTimeImpl(), m_bInHoldMode, and m_fFrozenTime.

◆ pauseTimer()

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 95 of file elapsedtime.cxx.

References getElapsedTimeImpl(), m_bInPauseMode, and m_fFrozenTime.

◆ releaseTimer()

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

Releases a held timer.

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

Definition at line 123 of file elapsedtime.cxx.

References m_bInHoldMode.

◆ reset()

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

◆ m_bInHoldMode

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

True, when in hold mode.

Definition at line 156 of file elapsedtime.hxx.

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

◆ m_bInPauseMode

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

True, when in pause mode.

Definition at line 153 of file elapsedtime.hxx.

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

◆ m_fFrozenTime

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

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

Definition at line 150 of file elapsedtime.hxx.

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

◆ m_fLastQueriedTime

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

To validate adjustTimer() calls with bLimitToLastQueriedTime=true.

Definition at line 144 of file elapsedtime.hxx.

Referenced by getElapsedTime(), and reset().

◆ m_fStartTime

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

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

Definition at line 147 of file elapsedtime.hxx.

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

◆ m_pTimeBase

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

Definition at line 141 of file elapsedtime.hxx.

Referenced by getCurrentTime().


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