1QIntDict(3qt)                                                    QIntDict(3qt)
2
3
4

NAME

6       QIntDict - Template class that provides a dictionary based on long keys
7

SYNOPSIS

9       #include <qintdict.h>
10
11       Inherits QPtrCollection.
12
13   Public Members
14       QIntDict ( int size = 17 )
15       QIntDict ( const QIntDict<type> & dict )
16       ~QIntDict ()
17       QIntDict<type> & operator= ( const QIntDict<type> & dict )
18       virtual uint count () const
19       uint size () const
20       bool isEmpty () const
21       void insert ( long key, const type * item )
22       void replace ( long key, const type * item )
23       bool remove ( long key )
24       type * take ( long key )
25       type * find ( long key ) const
26       type * operator[] ( long key ) const
27       virtual void clear ()
28       void resize ( uint newsize )
29       void statistics () const
30
31   Important Inherited Members
32       bool autoDelete () const
33       void setAutoDelete ( bool enable )
34
35   Protected Members
36       virtual QDataStream & read ( QDataStream & s, QPtrCollection::Item &
37           item )
38       virtual QDataStream & write ( QDataStream & s, QPtrCollection::Item )
39           const
40

DESCRIPTION

42       The QIntDict class is a template class that provides a dictionary based
43       on long keys.
44
45       QMap is an STL-compatible alternative to this class.
46
47       QIntDict is implemented as a template class. Define a template instance
48       QIntDict<X> to create a dictionary that operates on pointers to X (X*).
49
50       A dictionary is a collection of key-value pairs. The key is an long
51       used for insertion, removal and lookup. The value is a pointer.
52       Dictionaries provide very fast insertion and lookup.
53
54       Example:
55
56           QIntDict<QLineEdit> fields; // long int keys, QLineEdit* values
57           for ( int i = 0; i < 3; i++ )
58               fields.insert( i, new QLineEdit( this ) );
59           fields[0]->setText( "Homer" );
60           fields[1]->setText( "Simpson" );
61           fields[2]->setText( "45" );
62           QIntDictIterator<QLineEdit> it( fields );
63           for ( ; it.current(); ++it )
64               cout << it.currentKey() << ": " << it.current()->text() << endl;
65           for ( int i = 0; i < 3; i++ )
66               cout << fields[i]->text() << " "; // Prints "Homer Simpson 45"
67           cout << endl;
68           fields.remove( 1 ); // Does not delete the line edit
69           for ( int i = 0; i < 3; i++ )
70               if ( fields[i] )
71                   cout << fields[i]->text() << " "; // Prints "Homer 45"
72
73       See QDict for full details, including the choice of dictionary size,
74       and how deletions are handled.
75
76       See also QIntDictIterator, QDict, QAsciiDict, QPtrDict, Collection
77       Classes, Collection Classes, and Non-GUI Classes.
78

MEMBER FUNCTION DOCUMENTATION

QIntDict::QIntDict ( int size = 17 )

81       Constructs a dictionary using an internal hash array of size size.
82
83       Setting size to a suitably large prime number (equal to or greater than
84       the expected number of entries) makes the hash distribution better
85       which leads to faster lookup.
86

QIntDict::QIntDict ( const QIntDict<type> & dict )

88       Constructs a copy of dict.
89
90       Each item in dict is inserted into this dictionary. Only the pointers
91       are copied (shallow copy).
92

QIntDict::~QIntDict ()

94       Removes all items from the dictionary and destroys it.
95
96       All iterators that access this dictionary will be reset.
97
98       See also setAutoDelete().
99

bool QPtrCollection::autoDelete () const

101       Returns the setting of the auto-delete option. The default is FALSE.
102
103       See also setAutoDelete().
104

void QIntDict::clear () [virtual]

106       Removes all items from the dictionary.
107
108       The removed items are deleted if auto-deletion is enabled.
109
110       All dictionary iterators that access this dictionary will be reset.
111
112       See also remove(), take(), and setAutoDelete().
113
114       Reimplemented from QPtrCollection.
115

uint QIntDict::count () const [virtual]

117       Returns the number of items in the dictionary.
118
119       See also isEmpty().
120
121       Reimplemented from QPtrCollection.
122

type * QIntDict::find ( long key ) const

124       Returns the item associated with key, or 0 if the key does not exist in
125       the dictionary.
126
127       If there are two or more items with equal keys, then the most recently
128       inserted item will be found.
129
130       Equivalent to operator[].
131
132       See also operator[]().
133
134       Example: table/bigtable/main.cpp.
135

void QIntDict::insert ( long key, const type * item )

137       Insert item item into the dictionary using key key.
138
139       Multiple items can have the same key, in which case only the last item
140       will be accessible using operator[]().
141
142       item may not be 0.
143
144       See also replace().
145
146       Example: scribble/scribble.cpp.
147

bool QIntDict::isEmpty () const

149       Returns TRUE if the dictionary is empty; otherwise returns FALSE.
150
151       See also count().
152

QIntDict<type> & QIntDict::operator= ( const QIntDict<type> & dict )

154       Assigns dict to this dictionary and returns a reference to this
155       dictionary.
156
157       This dictionary is first cleared and then each item in dict is inserted
158       into this dictionary. Only the pointers are copied (shallow copy),
159       unless newItem() has been reimplemented.
160

type * QIntDict::operator[] ( long key ) const

162       Returns the item associated with key, or 0 if the key does not exist in
163       the dictionary.
164
165       If there are two or more items with equal keys, then the most recently
166       inserted item will be found.
167
168       Equivalent to the find() function.
169
170       See also find().
171

QDataStream & QIntDict::read ( QDataStream & s, QPtrCollection::Item & item )

173       [virtual protected]
174       Reads a dictionary item from the stream s and returns a reference to
175       the stream.
176
177       The default implementation sets item to 0.
178
179       See also write().
180

bool QIntDict::remove ( long key )

182       Removes the item associated with key from the dictionary. Returns TRUE
183       if successful, i.e. if the key is in the dictionary; otherwise returns
184       FALSE.
185
186       If there are two or more items with equal keys, then the most recently
187       inserted item will be removed.
188
189       The removed item is deleted if auto-deletion is enabled.
190
191       All dictionary iterators that refer to the removed item will be set to
192       point to the next item in the dictionary's traversal order.
193
194       See also take(), clear(), and setAutoDelete().
195
196       Example: table/bigtable/main.cpp.
197

void QIntDict::replace ( long key, const type * item )

199       If the dictionary has key key, this key's item is replaced with item.
200       If the dictionary doesn't contain key key, item is inserted into the
201       dictionary using key key.
202
203       item may not be 0.
204
205       Equivalent to:
206
207               QIntDict<char> dict;
208               //      ...
209               if ( dict.find(key) )
210                   dict.remove( key );
211               dict.insert( key, item );
212
213       If there are two or more items with equal keys, then the most recently
214       inserted item will be replaced.
215
216       See also insert().
217
218       Example: table/bigtable/main.cpp.
219

void QIntDict::resize ( uint newsize )

221       Changes the size of the hashtable to newsize. The contents of the
222       dictionary are preserved, but all iterators on the dictionary become
223       invalid.
224

void QPtrCollection::setAutoDelete ( bool enable )

226       Sets the collection to auto-delete its contents if enable is TRUE and
227       to never delete them if enable is FALSE.
228
229       If auto-deleting is turned on, all the items in a collection are
230       deleted when the collection itself is deleted. This is convenient if
231       the collection has the only pointer to the items.
232
233       The default setting is FALSE, for safety. If you turn it on, be careful
234       about copying the collection - you might find yourself with two
235       collections deleting the same items.
236
237       Note that the auto-delete setting may also affect other functions in
238       subclasses. For example, a subclass that has a remove() function will
239       remove the item from its data structure, and if auto-delete is enabled,
240       will also delete the item.
241
242       See also autoDelete().
243
244       Examples:
245

uint QIntDict::size () const

247       Returns the size of the internal hash array (as specified in the
248       constructor).
249
250       See also count().
251

void QIntDict::statistics () const

253       Debugging-only function that prints out the dictionary distribution
254       using qDebug().
255

type * QIntDict::take ( long key )

257       Takes the item associated with key out of the dictionary without
258       deleting it (even if auto-deletion is enabled).
259
260       If there are two or more items with equal keys, then the most recently
261       inserted item will be taken.
262
263       Returns a pointer to the item taken out, or 0 if the key does not exist
264       in the dictionary.
265
266       All dictionary iterators that refer to the taken item will be set to
267       point to the next item in the dictionary's traversing order.
268
269       See also remove(), clear(), and setAutoDelete().
270
271       Example: table/bigtable/main.cpp.
272

QDataStream & QIntDict::write ( QDataStream & s, QPtrCollection::Item ) const

274       [virtual protected]
275       Writes a dictionary item to the stream s and returns a reference to the
276       stream.
277
278       See also read().
279
280

SEE ALSO

282       http://doc.trolltech.com/qintdict.html
283       http://www.trolltech.com/faq/tech.html
284
286       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
287       license file included in the distribution for a complete license
288       statement.
289

AUTHOR

291       Generated automatically from the source code.
292

BUGS

294       If you find a bug in Qt, please report it as described in
295       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
296       help you. Thank you.
297
298       The definitive Qt documentation is provided in HTML format; it is
299       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
300       web browser. This man page is provided as a convenience for those users
301       who prefer man pages, although this format is not officially supported
302       by Trolltech.
303
304       If you find errors in this manual page, please report them to qt-
305       bugs@trolltech.com.  Please include the name of the manual page
306       (qintdict.3qt) and the Qt version (3.3.8).
307
308
309
310Trolltech AS                    2 February 2007                  QIntDict(3qt)
Impressum