|
| 1 | +#ifndef AGENTITERATOR_H |
| 2 | +#define AGENTITERATOR_H |
| 3 | + |
| 4 | +#include <utility> |
| 5 | + |
| 6 | +#include "Allocation.h" |
| 7 | + |
| 8 | +template <typename t_these, typename t_other> |
| 9 | +class AgentIteratorBase { |
| 10 | +public: |
| 11 | + AgentIteratorBase(const t_these & agent, const std::set<int> & candidates, const std::set<int> & positions, |
| 12 | + const std::vector<t_these> & these, const std::vector<t_other> & other, int group=0, int posn=0); |
| 13 | + virtual ~AgentIteratorBase() = 0; |
| 14 | + virtual void increment() = 0; |
| 15 | + virtual void begin() = 0; |
| 16 | + |
| 17 | + int get_position() const; |
| 18 | + int get_group() const; |
| 19 | + const t_these & get_agent() const; |
| 20 | + const std::vector<t_these> & get_these() const; |
| 21 | + const std::vector<t_other> & get_other() const; |
| 22 | + const std::set<int> & get_positions() const; |
| 23 | + const std::set<int> & get_candidates() const; |
| 24 | +protected: |
| 25 | + void regularIncrement(); |
| 26 | + |
| 27 | + const t_these & _agent; |
| 28 | + int _group; |
| 29 | + int _position; |
| 30 | + const std::vector<t_these> & _these; |
| 31 | + const std::vector<t_other> & _other; |
| 32 | + const std::set<int> & _positions; |
| 33 | + const std::set<int> & _candidates; |
| 34 | +}; |
| 35 | + |
| 36 | + |
| 37 | +template <typename t_these, typename t_other> |
| 38 | +class AgentIterator : public std::iterator<std::forward_iterator_tag, std::pair<int, int>, ptrdiff_t> { |
| 39 | +public: |
| 40 | + AgentIterator(const t_these & agent, const std::set<int> & candidates, const std::set<int> & positions, |
| 41 | + const std::vector<t_these> & these, const std::vector<t_other> & other, int mode); |
| 42 | + AgentIterator(AgentIterator *other, int group, int posn); |
| 43 | + AgentIterator(AgentIterator *other); |
| 44 | + ~AgentIterator(); |
| 45 | + bool operator==(const AgentIterator& other); |
| 46 | + bool operator!=(const AgentIterator& other); |
| 47 | + const std::pair<int, int> operator*(); |
| 48 | + AgentIterator& operator++() {base->increment(); return *this; } |
| 49 | + AgentIterator operator++(int) {AgentIterator res(this); base->increment(); return res; } |
| 50 | + |
| 51 | + AgentIterator begin(); |
| 52 | + AgentIterator end(); |
| 53 | + |
| 54 | + int get_position() const; |
| 55 | + int get_group() const; |
| 56 | + int get_mode() const; |
| 57 | + |
| 58 | + const t_these & get_agent() const { return base->get_agent(); } |
| 59 | + const std::vector<t_these> & get_these() const {return base->get_these(); } |
| 60 | + const std::vector<t_other> & get_other() const {return base->get_other(); } |
| 61 | + const std::set<int> & get_positions() const {return base->get_positions(); } |
| 62 | + const std::set<int> & get_candidates() const {return base->get_candidates(); } |
| 63 | +private: |
| 64 | + AgentIteratorBase<t_these, t_other> * base; |
| 65 | + int _mode; |
| 66 | +}; |
| 67 | + |
| 68 | + |
| 69 | +template <typename t_these, typename t_other> |
| 70 | +class DescendingIterator : public AgentIteratorBase<t_these, t_other> { |
| 71 | + public: |
| 72 | + DescendingIterator(const t_these & agent, const std::set<int> & candidates, |
| 73 | + const std::set<int> & positions, const std::vector<t_these> & these, |
| 74 | + const std::vector<t_other> & other, int group=0, int posn=0); |
| 75 | + ~DescendingIterator() {} |
| 76 | + void increment(); |
| 77 | + void begin(); |
| 78 | +}; |
| 79 | + |
| 80 | + |
| 81 | +template <typename t_these, typename t_other> |
| 82 | +class SkipBigIterator : public AgentIteratorBase<t_these, t_other> { |
| 83 | + public: |
| 84 | + SkipBigIterator(const t_these & agent, const std::set<int> & candidates, |
| 85 | + const std::set<int> & positions, const std::vector<t_these> & these, |
| 86 | + const std::vector<t_other> & other, int skip, int group, int posn); |
| 87 | + ~SkipBigIterator() {} |
| 88 | + void increment(); |
| 89 | + void begin(); |
| 90 | + private: |
| 91 | + int _skip; |
| 92 | +}; |
| 93 | + |
| 94 | +template <typename t_these, typename t_other> |
| 95 | +class BestIterator : public AgentIteratorBase<t_these, t_other> { |
| 96 | + public: |
| 97 | + BestIterator(const t_these & agent, const std::set<int> & candidates, |
| 98 | + const std::set<int> & positions, const std::vector<t_these> & these, |
| 99 | + const std::vector<t_other> & other, int group=0, int posn=0); |
| 100 | + ~BestIterator() {} |
| 101 | + void increment(); |
| 102 | + void begin(); |
| 103 | +}; |
| 104 | + |
| 105 | +template <typename t_these, typename t_other> |
| 106 | +class BestGroupIterator : public AgentIteratorBase<t_these, t_other> { |
| 107 | + public: |
| 108 | + BestGroupIterator(const t_these & agent, const std::set<int> & candidates, |
| 109 | + const std::set<int> & positions, const std::vector<t_these> & these, |
| 110 | + const std::vector<t_other> & other, int group=0, int posn=0); |
| 111 | + ~BestGroupIterator() {} |
| 112 | + void increment(); |
| 113 | + void begin(); |
| 114 | +}; |
| 115 | + |
| 116 | +#endif /* AGENTITERATOR_H */ |
0 commit comments