1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | *
|
---|
5 | * This package is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * found in the file COPYING that should have accompanied this file.
|
---|
8 | *
|
---|
9 | * This package is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #ifndef CSTOPWATCH_H
|
---|
16 | #define CSTOPWATCH_H
|
---|
17 |
|
---|
18 | #include "common.h"
|
---|
19 |
|
---|
20 | //! A timer class
|
---|
21 | /*!
|
---|
22 | This class measures time intervals. All time interval measurement
|
---|
23 | should use this class.
|
---|
24 | */
|
---|
25 | class CStopwatch {
|
---|
26 | public:
|
---|
27 | /*!
|
---|
28 | The default constructor does an implicit reset() or setTrigger().
|
---|
29 | If triggered == false then the clock starts ticking.
|
---|
30 | */
|
---|
31 | CStopwatch(bool triggered = false);
|
---|
32 | ~CStopwatch();
|
---|
33 |
|
---|
34 | //! @name manipulators
|
---|
35 | //@{
|
---|
36 |
|
---|
37 | //! Reset the timer to zero
|
---|
38 | /*!
|
---|
39 | Set the start time to the current time, returning the time since
|
---|
40 | the last reset. This does not remove the trigger if it's set nor
|
---|
41 | does it start a stopped clock. If the clock is stopped then
|
---|
42 | subsequent reset()'s will return 0.
|
---|
43 | */
|
---|
44 | double reset();
|
---|
45 |
|
---|
46 | //! Stop the timer
|
---|
47 | /*!
|
---|
48 | Stop the stopwatch. The time interval while stopped is not
|
---|
49 | counted by the stopwatch. stop() does not remove the trigger.
|
---|
50 | Has no effect if already stopped.
|
---|
51 | */
|
---|
52 | void stop();
|
---|
53 |
|
---|
54 | //! Start the timer
|
---|
55 | /*!
|
---|
56 | Start the stopwatch. start() removes the trigger, even if the
|
---|
57 | stopwatch was already started.
|
---|
58 | */
|
---|
59 | void start();
|
---|
60 |
|
---|
61 | //! Stop the timer and set the trigger
|
---|
62 | /*!
|
---|
63 | setTrigger() stops the clock like stop() except there's an
|
---|
64 | implicit start() the next time (non-const) getTime() is called.
|
---|
65 | This is useful when you want the clock to start the first time
|
---|
66 | you check it.
|
---|
67 | */
|
---|
68 | void setTrigger();
|
---|
69 |
|
---|
70 | //! Get elapsed time
|
---|
71 | /*!
|
---|
72 | Returns the time since the last reset() (or calls reset() and
|
---|
73 | returns zero if the trigger is set).
|
---|
74 | */
|
---|
75 | double getTime();
|
---|
76 | //! Same as getTime()
|
---|
77 | operator double();
|
---|
78 | //@}
|
---|
79 | //! @name accessors
|
---|
80 | //@{
|
---|
81 |
|
---|
82 | //! Check if timer is stopped
|
---|
83 | /*!
|
---|
84 | Returns true if the stopwatch is stopped.
|
---|
85 | */
|
---|
86 | bool isStopped() const;
|
---|
87 |
|
---|
88 | // return the time since the last reset().
|
---|
89 | //! Get elapsed time
|
---|
90 | /*!
|
---|
91 | Returns the time since the last reset(). This cannot trigger the
|
---|
92 | stopwatch to start and will not clear the trigger.
|
---|
93 | */
|
---|
94 | double getTime() const;
|
---|
95 | //! Same as getTime() const
|
---|
96 | operator double() const;
|
---|
97 | //@}
|
---|
98 |
|
---|
99 | private:
|
---|
100 | double getClock() const;
|
---|
101 |
|
---|
102 | private:
|
---|
103 | double m_mark;
|
---|
104 | bool m_triggered;
|
---|
105 | bool m_stopped;
|
---|
106 | };
|
---|
107 |
|
---|
108 | #endif
|
---|