-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackermap.cpp
36 lines (28 loc) · 901 Bytes
/
trackermap.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
#include "trackermap.h"
#include <qstring.h>
// <keyUsed> adds 'value' to key. Creates the key if not present.
void TrackerMap::keyUsed (QString key, float value) {
trackees[key] += value;
}
// <keyUnused> subtracts 'value' from key but does not remove it.
void TrackerMap::keyUnused (QString key, float value) {
trackees[key] -= value;
}
// Completely remove a key, regardless of its value.
void TrackerMap::removeKey (QString key) {
trackees.erase(key);
}
bool TrackerMap::isUsed (QString key) const {
return ( trackees.find(key) != trackees.end() );
}
NameToVal::mapped_type TrackerMap::value (const QString& key) const {
return (trackees.find(key))->second;
}
NameToVal::mapped_type TrackerMap::total() const {
NameToVal::mapped_type total = 0;
for (NameToVal::const_iterator iter = trackees.begin();
iter != trackees.end(); iter++) {
total += iter->second;
}
return total;
}