forked from Dremora/foo_musicbrainz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntityList.h
48 lines (39 loc) · 836 Bytes
/
EntityList.h
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
#pragma once
#include "foo_musicbrainz.h"
namespace foo_musicbrainz {
template <class T>
class EntityList {
public:
void add(T *item) {
items.add_item(item);
};
size_t count() const{
return items.get_count();
}
T *operator[](t_size index) const {
if (index >= items.get_count()) {
throw pfc::exception_overflow();
}
return items[index];
}
inline T *get(t_size index) const {
return (*this)[index];
}
T *extract(t_size index) {
T *item = (*this)[index];
items.remove_by_idx(index);
return item;
}
void remove(t_size index) {
delete extract(index);
}
EntityList() {};
~EntityList() {
for (unsigned int i = 0; i < items.get_count(); i++) {
delete items[i];
}
}
protected:
pfc::list_t<T *> items;
};
}