PTLib  Version 2.10.4
PSimpleTimer Class Reference

A class represeting a simple timer. More...

#include <timer.h>

Inheritance diagram for PSimpleTimer:
PTimeInterval PObject

List of all members.

Public Member Functions

Construction
 PSimpleTimer (long milliseconds=0, int seconds=0, int minutes=0, int hours=0, int days=0)
 Create a new timer object which will be expired the specified time interval after "now" in real time.
 PSimpleTimer (const PTimeInterval &time)
 PSimpleTimer (const PSimpleTimer &timer)
PSimpleTimeroperator= (DWORD milliseconds)
 Restart the timer using the specified time value.
PSimpleTimeroperator= (const PTimeInterval &time)
PSimpleTimeroperator= (const PSimpleTimer &timer)
Control functions
virtual void SetInterval (PInt64 milliseconds=0, long seconds=0, long minutes=0, long hours=0, int days=0)
 Set the value of the time interval.
void Stop ()
 Stop the timer.
PTimeInterval GetElapsed () const
 Return the real time elapsed since instantiation.
PTimeInterval GetRemaining () const
 Return the real time remaining before expiry.
bool IsRunning () const
 Indicate timer has not expired.
bool HasExpired () const
 Indicate timer has expired.
 operator bool () const
 Indicate timer has expired.

Protected Attributes

PTimeInterval m_startTick

Detailed Description

A class represeting a simple timer.

Unlike the PTimer class this does not support call back operations, nor is it startable and stoppable. It is intended for very simple real time operations where an elapsed time from a starting point is required. For example:

PSimpleTimer timeout(0, 10); // 10 seconds while (!timeout) { DoStuff(); }


Constructor & Destructor Documentation

PSimpleTimer::PSimpleTimer ( long  milliseconds = 0,
int  seconds = 0,
int  minutes = 0,
int  hours = 0,
int  days = 0 
)

Create a new timer object which will be expired the specified time interval after "now" in real time.

Parameters:
millisecondsNumber of milliseconds for timer.
secondsNumber of seconds for timer.
minutesNumber of minutes for timer.
hoursNumber of hours for timer.
daysNumber of days for timer.
Parameters:
timeNew time interval for timer.
Parameters:
timerTimer to copy.

Member Function Documentation

Return the real time elapsed since instantiation.

Return the real time remaining before expiry.

bool PSimpleTimer::HasExpired ( ) const

Indicate timer has expired.

bool PSimpleTimer::IsRunning ( ) const

Indicate timer has not expired.

PSimpleTimer::operator bool ( ) const

Indicate timer has expired.

PSimpleTimer& PSimpleTimer::operator= ( DWORD  milliseconds)

Restart the timer using the specified time value.

It will be expired the specified time interval after "now" in real time.

Returns:
reference to the timer.
Parameters:
millisecondsNew time interval for timer.
PSimpleTimer& PSimpleTimer::operator= ( const PTimeInterval time)
Parameters:
timeNew time interval for timer.
PSimpleTimer& PSimpleTimer::operator= ( const PSimpleTimer timer)
Parameters:
timerNew time interval for timer.
virtual void PSimpleTimer::SetInterval ( PInt64  milliseconds = 0,
long  seconds = 0,
long  minutes = 0,
long  hours = 0,
int  days = 0 
) [virtual]

Set the value of the time interval.

The time interval, in milliseconds, is the sum of all of the parameters. For example all of the following are equivalent:


              SetInterval(120000)
              SetInterval(60000, 60)
              SetInterval(60000, 0, 1)
              SetInterval(0, 60, 1)
              SetInterval(0, 0, 2)

The timer will be expired the specified time interval after "now" in real time.

Parameters:
millisecondsNumber of milliseconds for interval.
secondsNumber of seconds for interval.
minutesNumber of minutes for interval.
hoursNumber of hours for interval.
daysNumber of days for interval.

Reimplemented from PTimeInterval.

Stop the timer.


Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines