2001-10-06 18:13:28 +04:00
|
|
|
#ifndef CSTOPWATCH_H
|
|
|
|
#define CSTOPWATCH_H
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
//! A timer class
|
|
|
|
/*!
|
|
|
|
This class measures time intervals. All time interval measurement
|
|
|
|
should use this class.
|
|
|
|
*/
|
2001-10-06 18:13:28 +04:00
|
|
|
class CStopwatch {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2002-07-26 22:28:18 +04:00
|
|
|
/*!
|
|
|
|
The default constructor does an implicit reset() or setTrigger().
|
|
|
|
If triggered == false then the clock starts ticking.
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
CStopwatch(bool triggered = false);
|
|
|
|
~CStopwatch();
|
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2002-04-29 18:40:01 +04:00
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
//! Reset the timer to zero
|
|
|
|
/*!
|
|
|
|
Set the start time to the current time, returning the time since
|
|
|
|
the last reset. This does not remove the trigger if it's set nor
|
|
|
|
does it start a stopped clock. If the clock is stopped then
|
|
|
|
subsequent reset()'s will return 0.
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
double reset();
|
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
//! Stop the timer
|
|
|
|
/*!
|
|
|
|
Stop the stopwatch. The time interval while stopped is not
|
|
|
|
counted by the stopwatch. stop() does not remove the trigger.
|
|
|
|
Has no effect if already stopped.
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
void stop();
|
2002-07-26 22:28:18 +04:00
|
|
|
|
|
|
|
//! Start the timer
|
|
|
|
/*!
|
|
|
|
Start the stopwatch. start() removes the trigger, even if the
|
|
|
|
stopwatch was already started.
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
void start();
|
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
//! Stop the timer and set the trigger
|
|
|
|
/*!
|
|
|
|
setTrigger() stops the clock like stop() except there's an
|
|
|
|
implicit start() the next time (non-const) getTime() is called.
|
|
|
|
This is useful when you want the clock to start the first time
|
|
|
|
you check it.
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
void setTrigger();
|
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
//! Get elapsed time
|
|
|
|
/*!
|
|
|
|
Returns the time since the last reset() (or calls reset() and
|
|
|
|
returns zero if the trigger is set).
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
double getTime();
|
2002-07-26 22:28:18 +04:00
|
|
|
//! Same as getTime()
|
2001-10-06 18:13:28 +04:00
|
|
|
operator double();
|
2002-07-26 22:28:18 +04:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
//! Check if timer is stopped
|
|
|
|
/*!
|
|
|
|
Returns true if the stopwatch is stopped.
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
bool isStopped() const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-26 22:28:18 +04:00
|
|
|
// return the time since the last reset().
|
|
|
|
//! Get elapsed time
|
|
|
|
/*!
|
|
|
|
Returns the time since the last reset(). This cannot trigger the
|
|
|
|
stopwatch to start and will not clear the trigger.
|
|
|
|
*/
|
2002-04-29 18:40:01 +04:00
|
|
|
double getTime() const;
|
2002-07-26 22:28:18 +04:00
|
|
|
//! Same as getTime() const
|
2001-10-06 18:13:28 +04:00
|
|
|
operator double() const;
|
2002-07-26 22:28:18 +04:00
|
|
|
//@}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
|
|
|
double getClock() const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
|
|
|
double m_mark;
|
|
|
|
bool m_triggered;
|
|
|
|
bool m_stopped;
|
2001-10-06 18:13:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|