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.cpp | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 labb8/lib/StanfordCPPLib/gtimer.cpp (limited to 'labb8/lib/StanfordCPPLib/gtimer.cpp') diff --git a/labb8/lib/StanfordCPPLib/gtimer.cpp b/labb8/lib/StanfordCPPLib/gtimer.cpp new file mode 100755 index 0000000..20e160d --- /dev/null +++ b/labb8/lib/StanfordCPPLib/gtimer.cpp @@ -0,0 +1,62 @@ +/* + * File: gtimer.cpp + * ---------------- + * This file implements the gtimer.h interface. + */ + +#include +#include +#include +#include "platform.h" +using namespace std; + +/* Global variables */ + +static Platform *pp = getPlatform(); + +/* Implementation of the GTimer class */ + +GTimer::GTimer(double milliseconds) { + gtd = new GTimerData(); + gtd->refCount = 1; + pp->createTimer(*this, milliseconds); +} + +GTimer::~GTimer() { + if (--gtd->refCount == 0) delete gtd; +} + +void GTimer::start() { + pp->startTimer(*this); +} + +void GTimer::stop() { + pp->stopTimer(*this); +} + +bool GTimer::operator==(GTimer t2) { + return gtd == t2.gtd; +} + +bool GTimer::operator!=(GTimer t2) { + return gtd != t2.gtd; +} + +GTimer::GTimer(GTimerData *gtd) { + this->gtd = gtd; + gtd->refCount++; +} + +GTimer::GTimer(const GTimer & src) { + this->gtd = src.gtd; + this->gtd->refCount++; +} + +GTimer & GTimer::operator=(const GTimer & src) { + if (this != &src) { + if (--gtd->refCount == 0) delete gtd; + this->gtd = src.gtd; + this->gtd->refCount++; + } + return *this; +} -- cgit v1.2.1