Om  1.0.0
A universal framework for multimedia simulation
Public Member Functions | List of all members
om::time::Timer Class Reference

A timer class that behaves like a stopwatch. More...

#include <omTimer.h>

Public Member Functions

 Timer ()
 Create a new timer and start it's first interval (by calling update()). More...
 
Time update ()
 Update the timer to the current time and store the interval between updates. More...
 
const TimegetLastInterval () const
 Return the time interval of the last update. More...
 
Time getElapsedTime () const
 Return the time interval since the last update without updating the timer. More...
 
Bool getIsPaused () const
 Get whether or not the timer is currently paused. More...
 
void setIsPaused (Bool newIsPaused)
 Set whether or not the timer is paused with a boolean flag. More...
 
void pause ()
 Pause the timer. More...
 
void resume ()
 Resume the timer if it is currently paused. More...
 

Detailed Description

A timer class that behaves like a stopwatch.

This class serves to provide a way for the user to mark times and to measure the intervals between them. This can be used to do application profiling/timing, to provide a frame time interval counter for games, etc. It uses the highest performance timers availible on the system it is compiled under, and therefore should have sub-millisecond accuracy. The timer is also able to be paused, such that it then behaves as if it was stuck in that instance in which it was paused. It can later be resumed and carry on as if it had never been paused, reflecting this in it's attributes accordingly.

Constructor & Destructor Documentation

om::time::Timer::Timer ( )
inline

Create a new timer and start it's first interval (by calling update()).

This constructor creates a new timer, and then initializes the timer by starting it's first time interval, done by calling the timer's update() function internally.

Member Function Documentation

Time om::time::Timer::update ( )

Update the timer to the current time and store the interval between updates.

This method updates the timer, and then returns and stores the time between the last update and this update. If the timer is paused when this function is called, the the method does nothing.

const Time& om::time::Timer::getLastInterval ( ) const
inline

Return the time interval of the last update.

This method retrieves the time interval (in seconds) of the elapsed time between the last call to the update() method and the second to last call to the update() method.

Returns
the time interval between the last two timer updates
Time om::time::Timer::getElapsedTime ( ) const
inline

Return the time interval since the last update without updating the timer.

This method gets the time passed since the last call to the update() method in seconds. The method does not reset the timer, and therefore can be used to get a running total of the time since some arbitrary moment (set by calling the update method). If the timer is paused, this method returns the time between the last call to update() and the time when the timer was paused.

Returns
the time since the last call to update()
Bool om::time::Timer::getIsPaused ( ) const
inline

Get whether or not the timer is currently paused.

If the timer is paused, then this means that the timer is no longer keeping track of time, and will behave as if it is stuck in the instant that it was paused in until it is unpaused. This can be useful in many situations where one needs to stop timing and later resume timing as if the timer has never been stopped.

Returns
whether or not the timer is currently paused.
void om::time::Timer::setIsPaused ( Bool  newIsPaused)

Set whether or not the timer is paused with a boolean flag.

If the timer is paused, then this means that the timer is no longer keeping track of time, and will behave as if it is stuck in the instant that it was paused in until it is unpaused. This can be useful in many situations where one needs to stop timing and later resume timing as if the timer has never been stopped. If this method is called with a parameter that is equal to the return value of getIsPaused(), then it does nothing (the timer's state doesn't need to change).

Parameters
newIsPaused- whether or not the timer should be paused.
void om::time::Timer::pause ( )
inline

Pause the timer.

If the timer is already paused, then this method does nothing (the timer's state doesn't need to change to reflect the function call).

void om::time::Timer::resume ( )
inline

Resume the timer if it is currently paused.

If the timer is not paused, then this method does nothing (the timer's state doesn't need to change to reflect the function call).


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