Member Functions |
container() key() operator()() operator++() reset() value() |
#include <rw/tvhdict.h> unsigned hashFun(const K&); RWTValHashDictionary<K,V> dictionary(hashFun); RWTValHashDictionaryIterator<K,V> iterator(dictionary);
If you do not have the Standard C++ Library, use the interface described here. Otherwise, use the interface to RWTValHashMapIterator described in the Class Reference.
Iterator for class RWTValHashDictionary<K,V>, allowing sequential access to all keys and values of a parameterized hash dictionary. 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/tvhdict.h> #include<iostream.h> #include<rw/cstring.h> int main(){ RWTValHashDictionary<RWCString,int> age(RWCString::hash); RWTValHashDictionaryIterator<RWCString,int> itr(age); age.insert(RWCString("John"), 30); age.insert(RWCString("Steve"),17); age.insert(RWCString("Mark"),24); //Duplicate insertion rejected age.insert(RWCString("Steve"),24); for(;itr();) cout << itr.key() << "\'s age is " << itr.value() << endl; return 0; } Program Output (not necessarily in this order) John's age is 30 Steve's age is 17 Mark's age is 24
RWTValHashDictionaryIterator(RWTValHashDictionary& c);
Constructs an iterator to be used with the dictionary c.
RWBoolean operator++();
Advances the iterator one position. Returns TRUE if the new position is valid, FALSE otherwise.
RWBoolean operator()();
Advances the iterator one position. Returns TRUE if the new position is valid, FALSE otherwise.
RWTValHashDictionary* container() const;
Returns a pointer to the collection over which this iterator is iterating.
K key() const;
Returns the key 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(RWTValHashDictionary& c);
Resets the iterator to iterate over the collection c.
V value() const;
Returns the value at the iterator's current position. The results are undefined if the iterator is no longer valid.