summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/gtimer.cpp
blob: 20e160d55f182efea3ed13fcee27fcde7c8afef7 (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
/*
 * File: gtimer.cpp
 * ----------------
 * This file implements the gtimer.h interface.
 */

#include <iostream>
#include <sstream>
#include <string>
#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;
}