From 0c39051ba80f04b1177833a006f2d442a7170b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 3 Dec 2020 17:11:43 +0100 Subject: add initial files l8 --- labb8/lib/StanfordCPPLib/gtimer.h | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 labb8/lib/StanfordCPPLib/gtimer.h (limited to 'labb8/lib/StanfordCPPLib/gtimer.h') diff --git a/labb8/lib/StanfordCPPLib/gtimer.h b/labb8/lib/StanfordCPPLib/gtimer.h new file mode 100755 index 0000000..a0a6d7d --- /dev/null +++ b/labb8/lib/StanfordCPPLib/gtimer.h @@ -0,0 +1,116 @@ +/* + * File: gtimer.h + * -------------- + * This file defines the GTimer class, which implements a + * general interval timer. + */ + +#ifndef _gtimer_h +#define _gtimer_h + +#include + +/* + * 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 + * GTimerEvent with a specified frequency. Copying + * a GTimer 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 GTimerEvent + * each time the specified number of milliseconds has elapsed. No + * events are generated until the client calls start + * on the timer. For more details on using timers, see the documentation + * for the GTimerEvent + * 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 stop 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 -- cgit v1.2.1