// Iterator // // Douglas Thrift // // $Id$ #ifndef _Iterator_hpp_ #define _Iterator_hpp_ #include "NullNode.hpp" template class DoublyLinkedList; template class Iterator { private: NullNode* front; NullNode* back; Node* here; public: Iterator(NullNode* front, NullNode* back, bool forward = true) : front(front), back(back) { here = forward ? front->getNext() : back->getPrevious(); } bool end(void) { return here == back; } bool begin(void) { return here == front; } Iterator& operator++() { here = here->getNext(); return *this; } Iterator operator++(int); Iterator& operator--() { here = here->getPrevious(); return *this; } Iterator operator--(int); const Type& operator*() { return here->getValue(); } const Type* operator->() { return &here->getValue(); } }; template Iterator Iterator::operator++(int) { Iterator itor(*this); ++*this; return itor; } template Iterator Iterator::operator--(int) { Iterator itor(*this); --*this; return itor; } #endif // _Iterator_hpp_