Qt Toolkit - QPtrDictIterator Class

# QPtrDictIterator Class Reference

The QPtrDictIterator class provides an iterator for QPtrDict collections. More...

`#include <qptrdict.h>`

Inherits QGDictIterator.

List of all member functions.

## Public Members

- QPtrDictIterator ( const QPtrDict<type> & dict )
- ~QPtrDictIterator ()
- uint count () const
- bool isEmpty () const
- type* toFirst ()
- operator type* ()const
- type* current () const
- void* currentKey () const
- type* operator ()
- type* operator++ ()
- type* operator+= ( uint jump )

## Detailed Description

The QPtrDictIterator class provides an iterator for QPtrDict collections.

QPtrDictIterator is implemented as both a template and a macro class. Define a template instance QPtrDictIterator<X> to create a dictionary iterator that operates on QPtrDict<X> (dictionary of X*).

Example:

        #include <qptrdict.h>
        #include <stdio.h>

        void main()
        {
            int *a = new int[12];
            int *b = new int[10];
            int *c = new int[18];
            int *d = new int[13];

            QPtrDict<char> dict;               // maps void* -> char*

            dict.insert( a, "a is int[12]" );  // descripe pointers
            dict.insert( b, "b is int[10]" );
            dict.insert( c, "c is int[18]" );

            QPtrDictIterator<char> it( dict ); // iterator for dict

            while ( it.current() ) {
                printf( "%x -> %s\n", it.currentKey(), it.current() );
                ++it;
            }
        }

Program output:

            804a788 -> a is int[12]
            804a7f0 -> c is int[18]
            804a7c0 -> b is int[10]

Note that the traversal order is arbitrary, you are not guaranteed the order above.

A QPtrDictIterator can also be instantiated through a macro expansion, but this is necessary only for compilers that do not support templates. See the collection classes documentation for a general discussion on template-based versus macro-based collections.

Multiple iterators may independently traverse the same dictionary. A QPtrDict knows about all iterators that are operating on the dictionary. When an item is removed from the dictionary, QPtrDict update all iterators that are referring the removed item to point to the next item in the traversing order.

See also: QPtrDict and Collection Classes

## Member Function Documentation

### QPtrDictIterator::QPtrDictIterator ( const QPtrDict<type> & dict )

Constructs an iterator for dict. The current iterator item is set to point on the first item in the dict.

### QPtrDictIterator::~QPtrDictIterator ()

Destroys the iterator.

### QPtrDictIterator::operator type * () const

Cast operator. Returns a pointer to the current iterator item. Same as current().

### uint QPtrDictIterator::count () const

Returns the number of items in the dictionary this iterator operates on.

See also: isEmpty().

### type * QPtrDictIterator::current () const

Returns a pointer to the current iterator item.

### void * QPtrDictIterator::currentKey () const

Returns the key for the current iterator item.

### bool QPtrDictIterator::isEmpty () const

Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE otherwise.

See also: count().

### type * QPtrDictIterator::operator() ()

Makes the succeeding item current and returns the original current item.

If the current iterator item was the last item in the dictionary or if it was null, null is returned.

### type * QPtrDictIterator::operator++ ()

Prefix ++ makes the succeeding item current and returns the new current item.

If the current iterator item was the last item in the dictionary or if it was null, null is returned.

### type * QPtrDictIterator::operator+= ( uint jump )

Sets the current item to the item jump positions after the current item, and returns a pointer to that item.

If that item is beyond the last item or if the dictionary is empty, it sets the current item to null and returns null.

### type * QPtrDictIterator::toFirst ()

Sets the current iterator item to point to the first item in the dictionary and returns a pointer to the item. If the dictionary is empty it sets the current item to null and returns null.

Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):

This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.

It was generated from the following files:

- qptrdict.h: 1998/08/27
- qptrdict.doc: 1998/03/17