StanfordCPPLib
gtimer.h
1 /*
2  * File: gtimer.h
3  * --------------
4  * This file defines the <code>GTimer</code> class, which implements a
5  * general interval timer.
6  *
7  * @version 2019/01/23
8  * - added destructor
9  * @version 2018/09/09
10  * - updated to use new Qt GUI timer interface
11  * - added doc comments for new documentation generation
12  */
13 
14 #include "private/init.h" // ensure that Stanford C++ lib is initialized
15 
16 #ifndef INTERNAL_INCLUDE
17 // signal that GUI system is in use (so it will be initialized)
18 #define SPL_QT_GUI_IN_USE 1
19 #include "private/initstudent.h" // insert necessary included code by student
20 #endif // INTERNAL_INCLUDE
21 
22 #ifndef _gtimer_h
23 #define _gtimer_h
24 
25 #include <string>
26 
31 class GTimer {
32 public:
44  GTimer(double milliseconds);
45 
49  ~GTimer();
50 
54  double getDelay() const;
55 
64  bool isStarted() const;
65 
69  void restart();
70 
78  void setDelay(double ms);
79 
86  void start();
87 
91  void stop();
92 
93 private:
94  double _ms;
95  int _id;
96 };
97 
98 #endif // _gtimer_h
double getDelay() const
Returns the delay in milliseconds between each tick of this timer.
Definition: gtimer.cpp:39
void start()
Starts the timer.
Definition: gtimer.cpp:60
void stop()
Stops the timer so that it stops generating events until it is restarted.
Definition: gtimer.cpp:71
void setDelay(double ms)
Changes the delay in milliseconds between each tick of this timer.
Definition: gtimer.cpp:52
void restart()
Stops the timer (if it was started) and then starts it again.
Definition: gtimer.cpp:47
This class implements a simple interval timer that generates a GTimerEvent with a specified frequency...
Definition: gtimer.h:31
GTimer(double milliseconds)
Creates a timer object that generates a GTimerEvent each time the specified number of milliseconds ha...
Definition: gtimer.cpp:29
~GTimer()
Destroys the timer, stopping it if it&#39;s currently running.
Definition: gtimer.cpp:35
bool isStarted() const
Method: isStarted Usage: if (timer.isStarted()) { ...
Definition: gtimer.cpp:43