forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity_set.cpp
97 lines (75 loc) · 2.38 KB
/
entity_set.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
95
/* Copyright (C) 2013-2014 Michal Brzozowski ([email protected])
This file is part of KeeperRL.
KeeperRL is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
KeeperRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/ . */
#include "stdafx.h"
#include "entity_set.h"
#include "item.h"
#include "task.h"
#include "creature.h"
#include "level.h"
template<class T>
template<class Container>
EntitySet<T>::EntitySet(const Container& v) {
for (const T* e : v)
insert(e);
}
template
EntitySet<Item>::EntitySet(const vector<Item*>&);
template
EntitySet<Creature>::EntitySet(const vector<Creature*>&);
template <class T>
void EntitySet<T>::insert(const T* e) {
elems.insert(e->getUniqueId());
}
template <class T>
void EntitySet<T>::erase(const T* e) {
elems.erase(e->getUniqueId());
}
template <class T>
bool EntitySet<T>::contains(const T* e) const {
return elems.count(e->getUniqueId());
}
template <class T>
bool EntitySet<T>::empty() const {
return elems.empty();
}
template <class T>
void EntitySet<T>::insert(typename UniqueEntity<T>::Id e) {
elems.insert(e);
}
template <class T>
void EntitySet<T>::erase(typename UniqueEntity<T>::Id e) {
elems.erase(e);
}
template <class T>
bool EntitySet<T>::contains(typename UniqueEntity<T>::Id e) const {
return elems.count(e);
}
template <class T>
template <class Archive>
void EntitySet<T>::serialize(Archive& ar, const unsigned int version) {
ar & SVAR(elems);
}
template <class T>
typename EntitySet<T>::Iter EntitySet<T>::begin() const {
return elems.begin();
}
template <class T>
typename EntitySet<T>::Iter EntitySet<T>::end() const {
return elems.end();
}
template <>
ItemPredicate EntitySet<Item>::containsPredicate() const {
return [this](const Item* it) { return contains(it); };
}
SERIALIZABLE_TMPL(EntitySet, Item);
SERIALIZABLE_TMPL(EntitySet, Task);
SERIALIZABLE_TMPL(EntitySet, Creature);
SERIALIZABLE_TMPL(EntitySet, Level);