-
Notifications
You must be signed in to change notification settings - Fork 20
/
timerManager.cpp
94 lines (77 loc) · 1.63 KB
/
timerManager.cpp
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
#include "timerManager.h"
#include "timer.h"
TimerManager& TimerManager::instance() {
static TimerManager instance;
return instance;
}
TimerManager::TimerManager() {
last = NULL;
first = NULL;
}
void TimerManager::update() {
TimerNode *current = first;
while (current != NULL) {
current->value->update();
current = current->next;
}
}
void TimerManager::start() {
TimerNode *current = first;
while (current != NULL) {
current->value->start();
current = current->next;
}
}
void TimerManager::stop() {
TimerNode *current = first;
while (current != NULL) {
current->value->stop();
current = current->next;
}
}
void TimerManager::pause() {
TimerNode *current = first;
while (current != NULL) {
current->value->pause();
current = current->next;
}
}
void TimerManager::reset() {
TimerNode *current = first;
while (current != NULL) {
current->value->reset();
current = current->next;
}
}
void TimerManager::add(Timer *timer) {
TimerNode* node = new TimerNode(timer);
if (last == NULL) {
last = node;
first = node;
} else {
last->next = node;
last = node;
}
}
bool TimerManager::remove(Timer *timer) {
TimerNode *current = first;
TimerNode *previous = NULL;
while (current != NULL) {
if (current->value == timer) {
if (previous != NULL) {
previous->next = current->next;
}
if (current == last) {
last = previous;
}
if (current == first) {
first = current->next;
}
delete current;
return true;
}
previous = current;
current = current->next;
}
return false;
}