-
Notifications
You must be signed in to change notification settings - Fork 8
/
CCataloguer.cpp
50 lines (38 loc) · 1.04 KB
/
CCataloguer.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
#include "CCataloguer.h"
#include <stdexcept>
#include "CUnit.h"
void CCataloguer::registerMatcher(const CategoryMatcher& m) {
if (cache.find(m) == cache.end()) {
cache[m];
}
}
void CCataloguer::addUnit(UnitType* type, int id) {
const unitCategory cats = type->cats;
for (CacheMapIt it = cache.begin(); it != cache.end(); ++it) {
if (it->first.test(cats)) {
it->second[id] = type;
}
}
}
void CCataloguer::addUnit(CUnit* unit) {
addUnit(unit->type, unit->key);
}
void CCataloguer::removeUnit(int id) {
for (CacheMapIt it = cache.begin(); it != cache.end(); ++it) {
it->second.erase(id);
}
}
std::map<int, UnitType*>& CCataloguer::getUnits(const CategoryMatcher& m) {
CacheMapIt it = cache.find(m);
if (it != cache.end())
return it->second;
throw std::runtime_error("No unit found for category");
}
std::map<int, UnitType*>* CCataloguer::getUnits(const unitCategory& inc, const unitCategory& exc) {
CacheMapIt it;
CategoryMatcher m(inc, exc);
it = cache.find(m);
if (it == cache.end())
return NULL;
return &it->second;
}