Simple Graphics Library  0.9.5
SGL API
Public Member Functions | Protected Attributes | List of all members
sgl::Stopwatch Class Reference

#include <sgl.h>

Public Member Functions

 Stopwatch ()
 
void start ()
 
void stop ()
 
void reset ()
 
double elapsed () const
 

Protected Attributes

clock_t start_time
 
clock_t end_time
 
bool running
 

Detailed Description

Implements stopwatch objects that can be used to measure elapsed clock time in an executing program.

Constructor & Destructor Documentation

◆ Stopwatch()

sgl::Stopwatch::Stopwatch ( )

Creates a Stopwatch object. A newly minted object is not running and is in a "reset" state.

Member Function Documentation

◆ elapsed()

double sgl::Stopwatch::elapsed ( ) const

If the stopwatch is stopped, the elapsed method reports the time elapsed between the starting time and the stop time. If the stopwatch is running, the elapsed method reports the time elapsed since the stopwatch was started. The time is reported in seconds.

Returns
the time elapsed in seconds

◆ reset()

void sgl::Stopwatch::reset ( )

Resets the stopwatch so a subsequent start begins recording a new time. An attempt to reset a running stopwatch produces an error message.

Returns
nothing

◆ start()

void sgl::Stopwatch::start ( )

Starts the stopwatch. If there is no current start time, the stopwatch has not been used or has just been reset, so we record the current system time to begin a new timing. If there is a valid start time, we merely resume the current timing. Puts the stopwatch object in the 'running' state.

Returns
nothing

◆ stop()

void sgl::Stopwatch::stop ( )

Stops the stopwatch. Records the current system time and puts the stopwatch object in the 'not running' state. If the stopwatch is already stopped, a diagnostic message is issued, but the stored elapsed time is unaffected.

Returns
nothing

Member Data Documentation

◆ end_time

clock_t sgl::Stopwatch::end_time
protected

The time when the stopwatch was stopped

◆ running

bool sgl::Stopwatch::running
protected

A flag indicating if the stopwatch is running or stopped

◆ start_time

clock_t sgl::Stopwatch::start_time
protected

The starting time


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