StanfordCPPLib
Public Member Functions | List of all members
GTimer Class Reference

This class implements a simple interval timer that generates a GTimerEvent with a specified frequency. More...

#include "gtimer.h"

Public Member Functions

 GTimer(double milliseconds)
 Creates a timer object that generates a GTimerEvent each time the specified number of milliseconds has elapsed. More...
 
 ~GTimer()
 Destroys the timer, stopping it if it's currently running. More...
 
double getDelay() const
 Returns the delay in milliseconds between each tick of this timer. More...
 
bool isStarted() const
 Method: isStarted Usage: if (timer.isStarted()) { ... More...
 
void restart()
 Stops the timer (if it was started) and then starts it again. More...
 
void setDelay(double ms)
 Changes the delay in milliseconds between each tick of this timer. More...
 
void start()
 Starts the timer. More...
 
void stop()
 Stops the timer so that it stops generating events until it is restarted. More...
 

Detailed Description

This class implements a simple interval timer that generates a GTimerEvent with a specified frequency.

Constructor & Destructor Documentation

◆ GTimer()

GTimer ( double  milliseconds)

Creates a timer object that generates a GTimerEvent each time the specified number of milliseconds has elapsed.

No events are generated until the client calls start on the timer.

Due to implementation details, you must create at least one GWindow before you can start() a GTimer object.

Exceptions
ErrorExceptionif milliseconds is negative

◆ ~GTimer()

~GTimer ( )

Destroys the timer, stopping it if it's currently running.

Member Function Documentation

◆ getDelay()

double getDelay ( ) const

Returns the delay in milliseconds between each tick of this timer.

◆ isStarted()

bool isStarted ( ) const

Method: isStarted Usage: if (timer.isStarted()) { ...

}

Returns true if the given timer has been started (via start()). If you stop the timer or have not started it yet, this method will return false.

◆ restart()

void restart ( )

Stops the timer (if it was started) and then starts it again.

◆ setDelay()

void setDelay ( double  ms)

Changes the delay in milliseconds between each tick of this timer.

If the timer is currently running, calling this method will stop and restart the timer with the new delay.

Exceptions
ErrorExceptionif milliseconds is negative

◆ start()

void start ( )

Starts the timer.

A timer continues to generate timer events until it is stopped; to achieve the effect of a one-shot timer, the simplest approach is to call the stop method inside the event handler.

◆ stop()

void stop ( )

Stops the timer so that it stops generating events until it is restarted.