24 template<
typename T,
typename List,
typename Node>
26 list->removeIterator(
this);
35 template<
typename T,
typename List,
typename Node>
37 : list(theList), current(at)
39 list->addIterator(
this);
46 template<
typename T,
typename List,
typename Node>
48 : list(rhs.list), current(rhs.current)
50 list->addIterator(
this);
57 template<
typename T,
typename List,
typename Node>
60 list->removeIterator(
this);
63 current = rhs.current;
65 list->addIterator(
this);
75 template<
typename T,
typename List,
typename Node>
77 return rhs.current == current;
85 template<
typename T,
typename List,
typename Node>
87 return !(*
this == rhs);
94 template<
typename T,
typename List,
typename Node>
96 current = current->getNext();
105 template<
typename T,
typename List,
typename Node>
108 current = current->getNext();
118 template<
typename T,
typename List,
typename Node>
121 positions = -positions;
122 for(
int i = 0; i < positions; ++i) {
123 current = current->getPrevious();
126 for(
int i = 0; i < positions; ++i) {
127 current = current->getNext();
137 template<
typename T,
typename List,
typename Node>
148 template<
typename T,
typename List,
typename Node>
150 current = current->getPrevious();
159 template<
typename T,
typename List,
typename Node>
162 current = current->getPrevious();
172 template<
typename T,
typename List,
typename Node>
174 (*this) += -positions;
182 template<
typename T,
typename List,
typename Node>
193 template<
typename T,
typename List,
typename Node>
195 if(!current->valid() || !other.current->valid()) {
199 current->swapWith(other.current);
200 list->notifyItersSwapOccurred(current, other.current);
207 template<
typename T,
typename List,
typename Node>
209 if(!current->valid()) {
213 Node* next = current->getNext();
214 current->moveBefore(other.current);
216 other.list->notifyItersInsertedBefore(1, current->getNext());
217 list->notifyItersRemovedBefore(1, next);
226 template<
typename T,
typename List,
typename Node>
228 if(NULL == current) {
229 throw std::out_of_range(
"this position has no value");
239 template<
typename T,
typename List,
typename Node>
252 template<
typename T,
typename List,
typename Node>
256 }
else if(b == current) {
269 template<
typename T,
typename List,
typename Node>
271 if(after == current) {
284 template<
typename T,
typename List,
typename Node>
286 if(after == current) {
Iterator class that works genericly on a List containing Node elements with data of type T.
~Iterator()
Destroy iterator.
void removedBefore(Node *after, int count)
Update this iterator, if appropriate, that count positions were removed before after.
bool operator!=(const Iterator &rhs) const
Iterator & operator=(const Iterator &rhs)
Update Iterator to be at the same position of the same list as rhs.
bool operator==(const Iterator &rhs) const
Iterator & operator-=(int positions)
Decrement this iterator positions, if possible, and return this iterator.
Iterator & operator++()
Advance this iterator one position and return this iterator.
Iterator operator+(int positions)
void insertedBefore(Node *after, int count)
Update this iterator, if appropriate, that count positions were added before after.
Iterator & operator+=(int positions)
Advance this iterator positions, if possible, and return this iterator.
void moveBefore(Iterator &other)
Move the value at this itherator before the value at other.
void swapWith(Iterator &other)
Swap the values at this and other iterators.
Iterator(List *theList, Node *at)
Create Iterator for theList at the value of at.
Iterator operator-(int positions)
void swapOccurred(Node *a, Node *b)
Update this iterator, if appropriate, that the values at a and b swapped positions.
Iterator & operator--()
Decrement this iterator one position and return this iterator.
This file is to be included at the end of Iterator.h.