File: CCataloguer.cpp

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (50 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download | duplicates (4)
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;
}