Member Functions |
container() key() operator()() operator++() reset() |
#include <rw/tphasht.h> RWTPtrHashTable<T> table; RWTPtrHashTableIterator<T> iterator(table);
If you do not have the Standard C++ Library, use the interface described here. Otherwise, use the interface to RWTPtrHashMultiSetIterator described in the Class Reference.
Iterator for class RWTPtrHashTable<T>, allowing sequential access to all the elements of a hash table. Elements are not accessed in any particular order.
Like all Rogue Wave iterators, the "current item" is undefined immediately after construction -- you must define it by using operator() or some other (valid) operation.
Once the iterator has advanced beyond the end of the collection it is no longer valid -- continuing to use it will bring undefined results.
None
#include<rw/tphasht.h> #include<iostream.h> #include<rw/cstring.h> int main(){ RWTPtrHashTable<RWCString> age(RWCString::hash); RWTPtrHashTableIterator <RWCString> itr(age); age.insert(new RWCString("John")); age.insert(new RWCString("Steve")); age.insert(new RWCString("Mark")); age.insert(new RWCString("Steve")); for(;++itr;) cout << *itr.key() << endl; return 0; } Program Output (not necessarily in this order) John Mark Steve Steve
RWTPtrHashTableIterator(RWTPtrHashTable<T>& c);
Constructs an iterator to be used with the table c.
RWBoolean operator++();
Advances the iterator to the next item and returns TRUE. When the end of the collection is reached, returns FALSE and the position of the iterator will be undefined.
T* operator()();
Advances the iterator to the next item and returns a pointer to it. When the end of the collection is reached, returns nil and the position of the iterator will be undefined.
RWTPtrHashTable<T>* container() const;
Returns a pointer to the collection over which this iterator is iterating.
T* key() const;
Returns a pointer to the item at the iterator's current position. The results are undefined if the iterator is no longer valid.
void reset();
Resets the iterator to the state it had immediately after construction.
void reset(RWTPtrHashTable<T>& c);
Resets the iterator to iterate over the collection c.