1 |
gezelter |
1250 |
#ifndef _CONSTRAINT_ITERATOR_H_ |
2 |
tim |
1232 |
#define _CONSTRAINT_ITERATOR_H_ |
3 |
|
|
#include <list> |
4 |
|
|
#include <vector> |
5 |
|
|
|
6 |
gezelter |
1250 |
using namespace std; |
7 |
|
|
//abstract iterator class |
8 |
tim |
1232 |
template<class Item> class IteratorBase{ |
9 |
|
|
public: |
10 |
|
|
virtual ~IteratorBase(){} |
11 |
|
|
virtual void first() = 0; |
12 |
|
|
virtual void next() = 0; |
13 |
gezelter |
1250 |
virtual bool isEnd() = 0; |
14 |
tim |
1232 |
|
15 |
gezelter |
1250 |
virtual Item* currentItem() =0; |
16 |
tim |
1232 |
|
17 |
|
|
protected: |
18 |
|
|
IteratorBase() {}; |
19 |
|
|
}; |
20 |
|
|
|
21 |
|
|
template <class Item> class ConstraintIterator{ |
22 |
|
|
public: |
23 |
|
|
ConstraintIterator(list<vector<Item*> >& aContainer) : container(aContainer){} |
24 |
|
|
|
25 |
gezelter |
1250 |
virtual void first(){ |
26 |
|
|
listIter = container.begin(); |
27 |
|
|
//the construction of the container will guarantee every vector in list will contain at least one element |
28 |
|
|
//so we don't need to worry about the empty vector problem |
29 |
|
|
//while (listIter->empty()) |
30 |
|
|
// ++listIter; |
31 |
tim |
1232 |
|
32 |
gezelter |
1250 |
vectorIter = listIter->begin(); |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
virtual void next(){ |
36 |
|
|
++vectorIter; |
37 |
|
|
if (vectorIter == listIter->end()){ |
38 |
tim |
1232 |
|
39 |
gezelter |
1250 |
//do{ |
40 |
|
|
//++listIter; |
41 |
|
|
//}while(listIter->empty()) |
42 |
|
|
++listIter; |
43 |
|
|
if (listIter != container.end()) |
44 |
|
|
vectorIter = listIter->begin(); |
45 |
|
|
} |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
virtual bool isEnd(){ |
49 |
|
|
return listIter == container.end(); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
Item* currentItem(){ |
53 |
|
|
return listIter ==container.end() ? NULL : *vectorIter; |
54 |
|
|
} |
55 |
|
|
|
56 |
gezelter |
1252 |
private: |
57 |
|
|
list<vector<Item*> >& container; |
58 |
tim |
1232 |
|
59 |
gezelter |
1252 |
list<vector<Item*> >::iterator listIter; |
60 |
|
|
vector<Item*>::iterator vectorIter; |
61 |
tim |
1232 |
}; |
62 |
|
|
|
63 |
|
|
typedef ConstraintIterator<ConstraintPair> ConstraintPairIterator; |
64 |
|
|
typedef ConstraintIterator<ConstraintElement> ConstraintElementIterator; |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
#endif //end ifndef _CONSTRAINT_ITERATOR_H_ |