-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathItemsList.h
42 lines (34 loc) · 826 Bytes
/
ItemsList.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
/*
* ItemsList.h
*
* Created on: 19/lug/2013
* Author: Stefano Ceccherini ([email protected])
*/
#ifndef ITEMSLIST_H_
#define ITEMSLIST_H_
#include <list>
template<typename T>
class ItemsList {
public:
ItemsList() { fIterator = fItems.end(); };
virtual ~ItemsList() {};
void Rewind() { fIterator = fItems.begin(); };
bool GetNext(T& item) {
if (fIterator == fItems.end())
return false;
item = *fIterator;
fIterator++;
return true;
};
// Those are O(n) but added because they're handy
T& operator[](int i) const {
typename std::list<T>::const_iterator it = fItems.begin();
std::advance(it, i);
return *it;
}
std::size_t Count() const { return fItems.size(); };
protected:
std::list<T> fItems;
typename std::list<T>::iterator fIterator;
};
#endif /* ITEMSLIST_H_ */