#ifndef _ITERADAPTER_H #define _ITERADAPTER_H template class iteradapter { public: // define typedefs expected by STL input iterators typedef input_iterator_tag iterator_category; typedef Entry value_type; typedef ptrdiff_t difference_type; typedef const Entry * pointer; typedef const Entry& reference; iteradapter() : myIterator(0), myPastEnd(true) // post: nothing to read, all done (one past end iterator) { } iteradapter(Iterator& ds) : myIterator(&ds), myPastEnd(false) // post: bound to ds, iterate over all entries { ds.Init(); getEntry(); } reference operator*() const // pre: ! myPastEnd // post: return current entry in stream { return myEntry; } pointer operator->() const // pre: ! myPastEnd // post: return pointer to current entry { return &myEntry; } iteradapter operator++() // post: entry updated (this is pre-increment) { getEntry(); return *this; } iteradapter operator++(int) // post: entry updated (this is post-increment) { iteradapter tmp = *this; getEntry(); return tmp; } bool operator==(const iteradapter& rhs) const // post: return true iff *this and *rhs both past end OR // if they share the same stream and have the same "end-ness" { return (myIterator == rhs.myIterator && myPastEnd == rhs.myPastEnd) || (myPastEnd == true && rhs.myPastEnd == true); } bool operator!=(const iteradapter& rhs) const { return !( *this == rhs); } private: void getEntry() { if (myIterator->HasMore()) { myEntry = myIterator->Current(); myIterator->Next(); } else { myPastEnd = true; } } Iterator * myIterator; // wrapper for this iterator Entry myEntry; // current entry bool myPastEnd; // true iff one past end }; #endif