PSimpleTimer Class Reference

A class represeting a simple timer. More...

`#include <timer.h>`

Inheritance diagram for PSimpleTimer:

## 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. More...
| PSimpleTimer (const PTimeInterval &time)
| PSimpleTimer (const PSimpleTimer &timer)
PSimpleTimer & | operator= (DWORD milliseconds)
| Restart the timer using the specified time value. More...
PSimpleTimer & | operator= (const PTimeInterval &time)
PSimpleTimer & | operator= (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. More...
void | Stop ()
| Stop the timer. More...
PTimeInterval | GetElapsed () const
| Return the real time elapsed since instantiation. More...
PTimeInterval | GetRemaining () const
| Return the real time remaining before expiry. More...
bool | IsRunning () const
| Indicate timer has not expired. More...
bool | HasExpired () const
| Indicate timer has expired. More...
| operator bool () const
| Indicate timer has expired. More...
Public Member Functions inherited from PTimeInterval
| PTimeInterval (PInt64 millisecs=0)
| Create a new time interval object. More...
| PTimeInterval (long millisecs, long seconds, long minutes=0, long hours=0, int days=0)
| PTimeInterval (const PString &str)
PObject * | Clone () const
| Create a new copy of the time interval. More...
virtual Comparison | Compare (const PObject &obj) const
| Rank the two time intervals. More...
virtual void | PrintOn (ostream &strm) const
| Output the time interval to the I/O stream. More...
virtual void | ReadFrom (istream &strm)
| Input the time interval from the I/O stream. More...
virtual PInt64 | GetMilliSeconds () const
| Get the number of milliseconds for the time interval. More...
virtual void | SetMilliSeconds (PInt64 msecs)
| Set the number of milliseconds for the time interval. More...
long | GetSeconds () const
| Get the number of whole seconds for the time interval. More...
long | GetMinutes () const
| Get the number of whole minutes for the time interval. More...
int | GetHours () const
| Get the number of whole hours for the time interval. More...
int | GetDays () const
| Get the number of whole days for the time interval. More...
DWORD | GetInterval () const
| Get the number of milliseconds for the time interval. More...
PTimeInterval | operator- () const
| Unary minus, get negative of time interval. More...
PTimeInterval | operator+ (const PTimeInterval &interval) const
| Add the two time intervals yielding a third time interval. More...
PTimeInterval & | operator+= (const PTimeInterval &interval)
| Add the second time interval to the first time interval. More...
PTimeInterval | operator- (const PTimeInterval &interval) const
| Subtract the two time intervals yielding a third time interval. More...
PTimeInterval & | operator-= (const PTimeInterval &interval)
| Subtract the second time interval from the first time interval. More...
PTimeInterval | operator* (int factor) const
| Multiply the time interval by a factor yielding a third time interval. More...
PTimeInterval & | operator*= (int factor)
| Multiply the time interval by a factor. More...
int | operator/ (const PTimeInterval &smaller) const
| Divide the time interval by another interval yielding a count. More...
PTimeInterval | operator/ (int factor) const
| Divide the time interval by a factor yielding a third time interval. More...
PTimeInterval & | operator/= (int factor)
| Divide the time interval by a factor. More...
bool | operator== (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator== (long msecs) const
bool | operator!= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator!= (long msecs) const
bool | operator> (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator> (long msecs) const
bool | operator>= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator>= (long msecs) const
bool | operator< (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator< (long msecs) const
bool | operator<= (const PTimeInterval &interval) const
| Compare to the two time intervals. More...
bool | operator<= (long msecs) const
PString | AsString (int decimals=3, Formats format=NormalFormat, int width=1) const
Public Member Functions inherited from PObject
virtual | ~PObject ()
virtual PINDEX | HashFunction () const
| This function yields a hash value required by the `PDictionary` class. More...
virtual const char * | GetClass (unsigned ancestor=0) const
| Get the current dynamic type of the object instance. More...
PBoolean | IsClass (const char *cls) const
virtual PBoolean | InternalIsDescendant (const char *clsName) const
| Determine if the dynamic type of the current instance is a descendent of the specified class. More...
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const
| Determine the byte wise comparison of two objects. More...
bool | operator== (const PObject &obj) const
| Compare the two objects. More...
bool | operator!= (const PObject &obj) const
| Compare the two objects. More...
bool | operator< (const PObject &obj) const
| Compare the two objects. More...
bool | operator> (const PObject &obj) const
| Compare the two objects. More...
bool | operator<= (const PObject &obj) const
| Compare the two objects. More...
bool | operator>= (const PObject &obj) const
| Compare the two objects. More...

## Protected Attributes

PTimeInterval | m_startTick

## Additional Inherited Members

Public Types inherited from PTimeInterval
enum | Formats { NormalFormat, IncludeDays, SecondsOnly }
Public Types inherited from PObject
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
| Result of the comparison operation performed by the `Compare()` function. More...
Static Public Member Functions inherited from PObject
static const char * | Class ()
| Get the name of the class as a C string. More...
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
| Internal function caled from CompareObjectMemoryDirect() More...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...

## 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

  milliseconds | Number of milliseconds for timer.
  seconds | Number of seconds for timer.
  minutes | Number of minutes for timer.
  hours | Number of hours for timer.
  days | Number of days for timer.

PSimpleTimer::PSimpleTimer | ( | const PTimeInterval & | time | ) |

Parameters

  time | New time interval for timer.

PSimpleTimer::PSimpleTimer | ( | const PSimpleTimer & | timer | ) |

Parameters

  timer | Timer to copy.

## Member Function Documentation

PTimeInterval PSimpleTimer::GetElapsed | ( |  | ) | const

Return the real time elapsed since instantiation.

PTimeInterval PSimpleTimer::GetRemaining | ( |  | ) | const

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

  milliseconds | New time interval for timer.

PSimpleTimer& PSimpleTimer::operator= | ( | const PTimeInterval & | time | ) |

Parameters

  time | New time interval for timer.

PSimpleTimer& PSimpleTimer::operator= | ( | const PSimpleTimer & | timer | ) |

Parameters

  timer | New 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

  milliseconds | Number of milliseconds for interval.
  seconds | Number of seconds for interval.
  minutes | Number of minutes for interval.
  hours | Number of hours for interval.
  days | Number of days for interval.

Reimplemented from PTimeInterval.

void PSimpleTimer::Stop | ( |  | ) |

Stop the timer.

## Member Data Documentation

PTimeInterval PSimpleTimer::m_startTick

protected

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

- timer.h