Simple Graphics Library
0.9.5
SGL API
|
#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 |
Implements stopwatch objects that can be used to measure elapsed clock time in an executing program.
sgl::Stopwatch::Stopwatch | ( | ) |
Creates a Stopwatch object. A newly minted object is not running and is in a "reset" state.
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.
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.
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.
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.
|
protected |
The time when the stopwatch was stopped
|
protected |
A flag indicating if the stopwatch is running or stopped
|
protected |
The starting time