Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCTimer Class Reference

Milli-second timer. More...

#include <mcllib/MCTimer.h>

List of all members.

Public Member Functions

void elapse (mcinterval_t ms)
 If ms milli-seconds have already elapsed it does not wait.
mcinterval_t getElapsed () const
 Obtain the number of milli-seconds since the timer was created or since it was reset by either a call to the elapse() method (which implicitly calls reset()) or by an explicit call to the reset() method.
 MCTimer ()
 Construct a timer with current system value.
mcinterval_t reset ()
 Obtain the number of mill-seconds since the timer was created or since it was reset.
void wait (mcinterval_t ms) const
 Wait until a number of milliseconds have elapsed since the timer was created or reset.


Detailed Description

Milli-second timer.

Use for calculating elapsed times between operations. Example

   MCTimer t;
   ... do some activity ...
   cout << "That took " << t.getElapsed() << " milliseconds" << endl;
 
(use reset instead of getElapsed if you are doing it repeatedly) or for implemeting "polling" types of operations e.g.
   MCTimer t;
   while (...) {
    ... do some activity ...
    // if the activity took less that 5.000 secs sleep until
    // 5.000 secs since the loop started
    t.elapse(5000);
 
} The use of millisecond as the unit gives a maximum interval of about 24 days.


Member Function Documentation

void elapse mcinterval_t  ms  ) 
 

If ms milli-seconds have already elapsed it does not wait.

Wait until a number of milliseconds have elapsed since the timer was created or reset. Unlike the wait() method, the timer is reset to the current system value. If ms milli-seconds have already elapsed the call returns immediately without waiting.

Parameters:
ms the number of milliseconds to wait since the timer was created or reset.

mcinterval_t getElapsed  )  const
 

Obtain the number of milli-seconds since the timer was created or since it was reset by either a call to the elapse() method (which implicitly calls reset()) or by an explicit call to the reset() method.

The value of the timer is not changed.

Returns:
the milli-seconds since the timer was created or reset

mcinterval_t reset  ) 
 

Obtain the number of mill-seconds since the timer was created or since it was reset.

The timer is reset to the current system value.

Returns:
the milli-seconds since the timer was created or reset

void wait mcinterval_t  ms  )  const
 

Wait until a number of milliseconds have elapsed since the timer was created or reset.

The timer is not reset - waiting again for the same or lower time will return immediately. If ms milli-seconds have already elapsed the call returns immediately without waiting.

Parameters:
ms the number of milliseconds to wait since the timer was created or reset.


Generated on Wed Jan 12 19:05:50 2005 for MCLLIB by  doxygen 1.3.9.1