|
Packit |
1c1d7e |
/****************************************************************************
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** QDict and QDictIterator class documentation
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file is part of the Qt GUI Toolkit.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file may be distributed under the terms of the Q Public License
|
|
Packit |
1c1d7e |
** as defined by Trolltech AS of Norway and appearing in the file
|
|
Packit |
1c1d7e |
** LICENSE.QPL included in the packaging of this file.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file may be distributed and/or modified under the terms of the
|
|
Packit |
1c1d7e |
** GNU General Public License version 2 as published by the Free Software
|
|
Packit |
1c1d7e |
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
Packit |
1c1d7e |
** packaging of this file.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
|
Packit |
1c1d7e |
** licenses may use this file in accordance with the Qt Commercial License
|
|
Packit |
1c1d7e |
** Agreement provided with the Software.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
Packit |
1c1d7e |
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|
Packit |
1c1d7e |
** information about Qt Commercial License Agreements.
|
|
Packit |
1c1d7e |
** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|
Packit |
1c1d7e |
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Contact info@trolltech.com if any conditions of this licensing are
|
|
Packit |
1c1d7e |
** not clear to you.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
**********************************************************************/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*****************************************************************************
|
|
Packit |
1c1d7e |
QDict documentation
|
|
Packit |
1c1d7e |
*****************************************************************************/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\class QDict qdict.h
|
|
Packit |
1c1d7e |
\brief The QDict class is a template class that provides a dictionary based on \c QString keys.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\ingroup collection
|
|
Packit |
1c1d7e |
\ingroup tools
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
QDict is implemented as a template class. Define a template instance
|
|
Packit |
1c1d7e |
QDict\<X\> to create a dictionary that operates on pointers to X, or X*.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
A dictionary is a collection that associates an item with a key.
|
|
Packit |
1c1d7e |
The key is used for inserting and looking up an item. QDict has
|
|
Packit |
1c1d7e |
\l QString keys, which are Unicode strings. If you want to use
|
|
Packit |
1c1d7e |
non-Unicode, plain 8-bit \c char* keys, use the QAsciiDict template.
|
|
Packit |
1c1d7e |
A QDict has the same performance as a QAsciiDict.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
The dictionary has very fast insertion and lookup.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Example:
|
|
Packit |
1c1d7e |
\code
|
|
Packit |
1c1d7e |
#include <qdict.h>
|
|
Packit |
1c1d7e |
#include <stdio.h>
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
void main()
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
// Creates a dictionary that maps QString ==> char* (case insensitive)
|
|
Packit |
1c1d7e |
QDict<char> dict( 17, FALSE );
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
dict.insert( "France", "Paris" );
|
|
Packit |
1c1d7e |
dict.insert( "Russia", "Moscow" );
|
|
Packit |
1c1d7e |
dict.insert( "Norway", "Oslo" );
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
printf( "%s\n", dict["Norway"] );
|
|
Packit |
1c1d7e |
printf( "%s\n", dict["FRANCE"] );
|
|
Packit |
1c1d7e |
printf( "%s\n", dict["russia"] );
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
if ( !dict["Italy"] )
|
|
Packit |
1c1d7e |
printf( "Italy not defined\n" );
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
\endcode
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Program output:
|
|
Packit |
1c1d7e |
\code
|
|
Packit |
1c1d7e |
Oslo
|
|
Packit |
1c1d7e |
Paris
|
|
Packit |
1c1d7e |
Moscow
|
|
Packit |
1c1d7e |
Italy not defined
|
|
Packit |
1c1d7e |
\endcode
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
The dictionary in our example maps \c QString keys to \c char* items.
|
|
Packit |
1c1d7e |
Note that the mapping is case insensitive (specified in the
|
|
Packit |
1c1d7e |
\link QDict::QDict() constructor\endlink).
|
|
Packit |
1c1d7e |
QDict implements the \link operator[] [] operator\endlink to lookup an item.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
QDict is implemented by QGDict as a hash array with a fixed number of
|
|
Packit |
1c1d7e |
entries. Each array entry points to a singly linked list of buckets, in
|
|
Packit |
1c1d7e |
which the dictionary items are stored.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
When an item is inserted with a key, the key is converted (hashed) to
|
|
Packit |
1c1d7e |
an integer index into the hash array. The item is inserted before the
|
|
Packit |
1c1d7e |
first bucket in the list of buckets.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Looking up an item is normally very fast. The key is again hashed to an
|
|
Packit |
1c1d7e |
array index. Then QDict scans the list of buckets and returns the item
|
|
Packit |
1c1d7e |
found or null if the item was not found. You cannot insert null pointers
|
|
Packit |
1c1d7e |
into a dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
The size of the hash array is very important. In order to get good
|
|
Packit |
1c1d7e |
performance, you should use a suitably large \link primes.html prime
|
|
Packit |
1c1d7e |
number\endlink. Suitable means equal to or larger than the maximum
|
|
Packit |
1c1d7e |
expected number of dictionary items.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Items with equal keys are allowed. When inserting two items with the
|
|
Packit |
1c1d7e |
same key, only the last inserted item will be visible (last in, first out)
|
|
Packit |
1c1d7e |
until it is removed.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Example:
|
|
Packit |
1c1d7e |
\code
|
|
Packit |
1c1d7e |
#include <qdict.h>
|
|
Packit |
1c1d7e |
#include <stdio.h>
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
void main()
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
// Creates a dictionary that maps QString ==> char* (case sensitive)
|
|
Packit |
1c1d7e |
QDict<char> dict;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
dict.insert( "Germany", "Berlin" );
|
|
Packit |
1c1d7e |
dict.insert( "Germany", "Bonn" );
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
printf( "%s\n", dict["Germany"] );
|
|
Packit |
1c1d7e |
dict.remove( "Germany" ); // Oct 3rd 1990
|
|
Packit |
1c1d7e |
printf( "%s\n", dict["Germany"] );
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
\endcode
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Program output:
|
|
Packit |
1c1d7e |
\code
|
|
Packit |
1c1d7e |
Bonn
|
|
Packit |
1c1d7e |
Berlin
|
|
Packit |
1c1d7e |
\endcode
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
The QDictIterator class can traverse the dictionary contents, but only
|
|
Packit |
1c1d7e |
in an arbitrary order. Multiple iterators may independently traverse the
|
|
Packit |
1c1d7e |
same dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Calling setAutoDelete(TRUE) for a dictionary tells it to delete items
|
|
Packit |
1c1d7e |
that are removed . The default is to not delete items when they are
|
|
Packit |
1c1d7e |
removed.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
When inserting an item into a dictionary, only the pointer is copied, not
|
|
Packit |
1c1d7e |
the item itself. This is called a shallow copy. It is possible to make the
|
|
Packit |
1c1d7e |
dictionary copy all of the item's data (known as a deep copy) when an
|
|
Packit |
1c1d7e |
item is inserted. insert() calls the virtual function
|
|
Packit |
1c1d7e |
QCollection::newItem() for the item to be inserted.
|
|
Packit |
1c1d7e |
Inherit a dictionary and reimplement it if you want deep copies.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
When removing a dictionary item, the virtual function
|
|
Packit |
1c1d7e |
QCollection::deleteItem() is called. QDict's default implementation
|
|
Packit |
1c1d7e |
is to delete the item if auto-deletion is enabled.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa QDictIterator, QAsciiDict, QIntDict, QPtrDict,
|
|
Packit |
1c1d7e |
\link collection.html Collection Classes\endlink
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QDict::QDict( int size, bool caseSensitive )
|
|
Packit |
1c1d7e |
Constructs a dictionary with the following properties:
|
|
Packit |
1c1d7e |
\arg \e size is the size of the internal hash array.
|
|
Packit |
1c1d7e |
\arg \e caseSensitive specifies whether to use case sensitive lookup or not.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Setting \e size to a suitably large \link primes.html prime
|
|
Packit |
1c1d7e |
number\endlink (equal to or greater than the expected number of entries)
|
|
Packit |
1c1d7e |
makes the hash distribution better and hence the loopup faster.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Setting \e caseSensitive to TRUE will treat "abc" and "Abc" as different
|
|
Packit |
1c1d7e |
keys. Setting it to FALSE will make the dictionary ignore case.
|
|
Packit |
1c1d7e |
Case insensitive comparison includes the whole Unicode alphabeth.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QDict::QDict( const QDict<type> &dict )
|
|
Packit |
1c1d7e |
Constructs a copy of \e dict.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Each item in \e dict are inserted into this dictionary.
|
|
Packit |
1c1d7e |
Only the pointers are copied (shallow copy).
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QDict::~QDict()
|
|
Packit |
1c1d7e |
Removes all items from the dictionary and destroys it.
|
|
Packit |
1c1d7e |
All iterators that access this dictionary will be reset.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa setAutoDelete()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QDict<type> &QDict::operator=(const QDict<type> &dict)
|
|
Packit |
1c1d7e |
Assigns \e dict to this dictionary and returns a reference to this
|
|
Packit |
1c1d7e |
dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
This dictionary is first cleared, then each item in \e dict is inserted
|
|
Packit |
1c1d7e |
into this dictionary.
|
|
Packit |
1c1d7e |
Only the pointers are copied (shallow copy), unless newItem() has been
|
|
Packit |
1c1d7e |
reimplemented().
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn uint QDict::count() const
|
|
Packit |
1c1d7e |
Returns the number of items in the dictionary.
|
|
Packit |
1c1d7e |
\sa isEmpty()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn uint QDict::size() const
|
|
Packit |
1c1d7e |
Returns the size of the internal hash array (as specified in the
|
|
Packit |
1c1d7e |
constructor).
|
|
Packit |
1c1d7e |
\sa count()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn void QDict::resize( uint newsize )
|
|
Packit |
1c1d7e |
Changes the size of the hashtable the \a newsize.
|
|
Packit |
1c1d7e |
The contents of the dictionary are preserved,
|
|
Packit |
1c1d7e |
but all iterators on the dictionary become invalid.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn bool QDict::isEmpty() const
|
|
Packit |
1c1d7e |
Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE
|
|
Packit |
1c1d7e |
otherwise.
|
|
Packit |
1c1d7e |
\sa count()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn void QDict::insert( const QString &key, const type *item )
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Inserts the \e key with the \e item into the dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
The key does not have to be a unique dictionary key. If multiple items
|
|
Packit |
1c1d7e |
are inserted with the same key, only the last item will be visible.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Null items are not allowed.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa replace()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn void QDict::replace( const QString &key, const type *item )
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Replaces an item which has a key equal to \e key with \e item.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If the item does not already exist, it will be inserted.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Null items are not allowed.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Equivalent to:
|
|
Packit |
1c1d7e |
\code
|
|
Packit |
1c1d7e |
QDict<char> dict;
|
|
Packit |
1c1d7e |
...
|
|
Packit |
1c1d7e |
if ( dict.find(key) )
|
|
Packit |
1c1d7e |
dict.remove( key );
|
|
Packit |
1c1d7e |
dict.insert( key, item );
|
|
Packit |
1c1d7e |
\endcode
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If there are two or more items with equal keys, then the last inserted
|
|
Packit |
1c1d7e |
of these will be replaced.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa insert()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn bool QDict::remove( const QString &key )
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Removes the item associated with \e key from the dictionary.
|
|
Packit |
1c1d7e |
Returns TRUE if successful, or FALSE if the key does not exist in the
|
|
Packit |
1c1d7e |
dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If there are two or more items with equal keys, then the last inserted
|
|
Packit |
1c1d7e |
of these will be removed.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
The removed item is deleted if \link QCollection::setAutoDelete()
|
|
Packit |
1c1d7e |
auto-deletion\endlink is enabled.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
All dictionary iterators that refer to the removed item will be set to
|
|
Packit |
1c1d7e |
point to the next item in the dictionary traversing order.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa take(), clear(), setAutoDelete()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDict::take( const QString &key )
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Takes the item associated with \e key out of the dictionary without
|
|
Packit |
1c1d7e |
deleting it (even if \link QCollection::setAutoDelete()
|
|
Packit |
1c1d7e |
auto-deletion\endlink is enabled).
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If there are two or more items with equal keys, then the last inserted
|
|
Packit |
1c1d7e |
of these will be taken.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Returns a pointer to the item taken out, or null if the key does not
|
|
Packit |
1c1d7e |
exist in the dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
All dictionary iterators that refer to the taken item will be set to
|
|
Packit |
1c1d7e |
point to the next item in the dictionary traversal order.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa remove(), clear(), setAutoDelete()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn void QDict::clear()
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Removes all items from the dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
The removed items are deleted if \link QCollection::setAutoDelete()
|
|
Packit |
1c1d7e |
auto-deletion\endlink is enabled.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
All dictionary iterators that operate on dictionary are reset.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa remove(), take(), setAutoDelete()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDict::find( const QString &key ) const
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Returns the item associated with \e key, or null if the key does not
|
|
Packit |
1c1d7e |
exist in the dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
This function uses an internal hashing algorithm to optimize lookup.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If there are two or more items with equal keys, then the last inserted
|
|
Packit |
1c1d7e |
of these will be found.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Equivalent to the [] operator.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa operator[]()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDict::operator[]( const QString &key ) const
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Returns the item associated with \e key, or null if the key does not
|
|
Packit |
1c1d7e |
exist in the dictionary.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
This function uses an internal hashing algorithm to optimize lookup.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If there are two or more items with equal keys, then the last inserted
|
|
Packit |
1c1d7e |
of these will be found.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Equivalent to the find() function.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa find()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn void QDict::statistics() const
|
|
Packit |
1c1d7e |
Debugging-only function that prints out the dictionary distribution
|
|
Packit |
1c1d7e |
using qDebug().
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*****************************************************************************
|
|
Packit |
1c1d7e |
QDictIterator documentation
|
|
Packit |
1c1d7e |
*****************************************************************************/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\class QDictIterator qdict.h
|
|
Packit |
1c1d7e |
\brief The QDictIterator class provides an iterator for QDict collections.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\ingroup collection
|
|
Packit |
1c1d7e |
\ingroup tools
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
QDictIterator is implemented as a template class.
|
|
Packit |
1c1d7e |
Define a template instance QDictIterator\<X\> to create a
|
|
Packit |
1c1d7e |
dictionary iterator that operates on QDict\<X\> (dictionary of X*).
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Example:
|
|
Packit |
1c1d7e |
\code
|
|
Packit |
1c1d7e |
#include <qdict.h>
|
|
Packit |
1c1d7e |
#include <stdio.h>
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
void main()
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
// Creates a dictionary that maps QString ==> char* (case insensitive)
|
|
Packit |
1c1d7e |
QDict<char> dict( 17, FALSE );
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
dict.insert( "France", "Paris" );
|
|
Packit |
1c1d7e |
dict.insert( "Russia", "Moscow" );
|
|
Packit |
1c1d7e |
dict.insert( "Norway", "Oslo" );
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
QDictIterator<char> it( dict ); // iterator for dict
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
while ( it.current() ) {
|
|
Packit |
1c1d7e |
printf( "%s -> %s\n", it.currentKey().latin1(), it.current() );
|
|
Packit |
1c1d7e |
++it;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
\endcode
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Program output:
|
|
Packit |
1c1d7e |
\code
|
|
Packit |
1c1d7e |
Russia -> Moscow
|
|
Packit |
1c1d7e |
Norway -> Oslo
|
|
Packit |
1c1d7e |
France -> Paris
|
|
Packit |
1c1d7e |
\endcode
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Note that the traversal order is arbitrary, you are not guaranteed the
|
|
Packit |
1c1d7e |
order above.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
Multiple iterators may independently traverse the same dictionary.
|
|
Packit |
1c1d7e |
A QDict knows about all iterators that are operating on the dictionary.
|
|
Packit |
1c1d7e |
When an item is removed from the dictionary, QDict update all iterators
|
|
Packit |
1c1d7e |
that are referring the removed item to point to the next item in the
|
|
Packit |
1c1d7e |
traversing order.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
\sa QDict, \link collection.html Collection Classes\endlink
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QDictIterator::QDictIterator( const QDict<type> &dict )
|
|
Packit |
1c1d7e |
Constructs an iterator for \e dict. The current iterator item is
|
|
Packit |
1c1d7e |
set to point on the first item in the \e dict.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QDictIterator::~QDictIterator()
|
|
Packit |
1c1d7e |
Destroys the iterator.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn uint QDictIterator::count() const
|
|
Packit |
1c1d7e |
Returns the number of items in the dictionary this iterator operates on.
|
|
Packit |
1c1d7e |
\sa isEmpty()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn bool QDictIterator::isEmpty() const
|
|
Packit |
1c1d7e |
Returns TRUE if the dictionary is empty, i.e. count() == 0, otherwise FALSE.
|
|
Packit |
1c1d7e |
\sa count()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDictIterator::toFirst()
|
|
Packit |
1c1d7e |
Sets the current iterator item to point to the first item in the
|
|
Packit |
1c1d7e |
dictionary and returns a pointer to the item.
|
|
Packit |
1c1d7e |
If the dictionary is empty it sets the current item to null and
|
|
Packit |
1c1d7e |
returns null.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QDictIterator::operator type *() const
|
|
Packit |
1c1d7e |
Cast operator. Returns a pointer to the current iterator item.
|
|
Packit |
1c1d7e |
Same as current().
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDictIterator::current() const
|
|
Packit |
1c1d7e |
Returns a pointer to the current iterator item.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn QString QDictIterator::currentKey() const
|
|
Packit |
1c1d7e |
Returns a pointer to the key for the current iterator item.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDictIterator::operator()()
|
|
Packit |
1c1d7e |
Makes the succeeding item current and returns the original current item.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If the current iterator item was the last item in the dictionary or if it
|
|
Packit |
1c1d7e |
was null, null is returned.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDictIterator::operator++()
|
|
Packit |
1c1d7e |
Prefix ++ makes the succeeding item current and returns the new current
|
|
Packit |
1c1d7e |
item.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If the current iterator item was the last item in the dictionary or if it
|
|
Packit |
1c1d7e |
was null, null is returned.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/*!
|
|
Packit |
1c1d7e |
\fn type *QDictIterator::operator+=( uint jump )
|
|
Packit |
1c1d7e |
Sets the current item to the item \e jump positions after the current item,
|
|
Packit |
1c1d7e |
and returns a pointer to that item.
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
If that item is beyond the last item or if the dictionary is empty,
|
|
Packit |
1c1d7e |
it sets the current item to null and returns null.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|