#include <CNCL/HashIterator.h>
CN_HASHITERATOR
CNObject
None
CNHashTable, CNHashDynamic, CNHashStatic, CNKey, CNKeyString, CNKeyInt, CNManager
CNHashIterator
is an iterator to sequentially traverse a
CNHashTable
hash table.
Constructors:
CNHashIterator();
CNHashIterator(CNParam *param);
CNHashIterator
.
CNHashIterator(const CNHashTable *new_hash_table);
CNHashIterator(const CNHashTable &new_hash_table);
CNHashIterator
with hash table
new_hash_table
. The iterator is reset to the first element of the
hash table.
In addition to the member functions required by CNCL, CNHashIterator
provides:
void reset(const CNHashTable *new_hash_table);
void reset(const CNHashTable &new_hash_table);
void reset();
new_hash_table
and/or
sets the iterator to the first element of the hash table.
CNKey *key()
CNKey *get_key()
NIL
, if none is available.
CNKey *first_key();
CNKey *first();
NIL
, if none is available.
CNKey *last_key();
CNKey *last();
NIL
, if none is available.
CNKey *next_key();
CNKey *next();
CNKey *operator ++();
CNKey *operator ++(int);
NIL
, if none is available.
CNKey *prev_key();
CNKey *prev();
CNKey *operator --();
CNKey *operator --(int);
NIL
, if none is available.
CNObject *object()
CNObject *get_object()
NIL
, if none is available.
CNObject *first_object();
NIL
, if none is available.
CNObject *last_object();
NIL
, if none is available.
CNObject *next_object();
NIL
, if none is available.
CNObject *prev_object();
NIL
, if none is available.
The following examples show how to use a CNHashIterator
object to
traverse an hash table:
Forward:
CNHashDynamic hash_table; ... CNHashIterator trav(hash_table); CNKey *key; CNObject *obj; while(key = trav++) { // Do something with key ... obj = key->get_object(); }
Alternate forward:
for(trav.reset(hash_table); key = trav.key(); trav.next()) { // ... }
Forward with objects:
for(trav.first(); obj = trav.object(); trav.next_object()) { // ... }
Backward:
for(trav.last(); key = trav.key(); trav--) { // ... }
The only way to delete all entries of an hash table, that is guaranteed
to work with CNHashIterator
:
for(trav.reset(hash_table); key = trav.key(); trav.reset()) { // delete object associated with key delete key->get_object(); // delete hash table entry and key hash_table->delete_key_absolutely(key); }
Go to the first, previous, next, last section, table of contents.