blob: a0a6d7daef19277368c1104081f4c15baaa8f490 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* File: gtimer.h
* --------------
* This file defines the <code>GTimer</code> class, which implements a
* general interval timer.
*/
#ifndef _gtimer_h
#define _gtimer_h
#include <string>
/*
* Friend type: GTimerData
* -----------------------
* This type maintains a reference count to determine when it is
* possible to free the timer. The address of this block is used
* as the timer id.
*/
struct GTimerData {
int refCount;
};
/*
* Class: GTimer
* -------------
* This class implements a simple interval timer that generates a
* <code>GTimerEvent</code> with a specified frequency. Copying
* a <code>GTimer</code> object is legal and creates an object that
* refers to the same internal timer.
*/
class GTimer {
public:
/*
* Constructor: GTimer
* Usage: GTimer timer(milliseconds);
* ----------------------------------
* Creates a timer object that generates a <code>GTimerEvent</code>
* each time the specified number of milliseconds has elapsed. No
* events are generated until the client calls <code>start</code>
* on the timer. For more details on using timers, see the documentation
* for the <a href="GTimerEvent-class.html"><code>GTimerEvent</code></a>
* class.
*/
GTimer(double milliseconds);
/*
* Destructor: ~GTimer
* -------------------
* Frees the resources associated with the timer.
*/
virtual ~GTimer();
/*
* Method: start
* Usage: timer.start();
* ---------------------
* Starts the timer. A timer continues to generate timer events until it
* is stopped; to achieve the effect of a one-shot timer, the simplest
* approach is to call the <code>stop</code> method inside the event
* handler.
*/
void start();
/*
* Method: stop
* Usage: timer.stop();
* --------------------
* Stops the timer so that it stops generating events until it is restarted.
*/
void stop();
/*
* Friend operator: ==
* Usage: if (t1 == t2) ...
* ------------------------
* Checks whether the two objects refer to the same timer.
*/
bool operator==(GTimer t2);
/*
* Friend operator: !=
* Usage: if (t1 != t2) ...
* ------------------------
* Checks whether the two objects refer to the different timers.
*/
bool operator!=(GTimer t2);
/* Private section */
GTimer(GTimerData *gtd);
GTimer(const GTimer & src);
GTimer & operator=(const GTimer & src);
private:
/* Instance variables */
GTimerData *gtd;
friend class Platform;
friend class GTimerEvent;
};
#endif
|