1QPtrDict(3qt)                                                    QPtrDict(3qt)
2
3
4

NAME

6       QPtrDict - Template class that provides a dictionary based on void*
7       keys
8

SYNOPSIS

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

DESCRIPTION

43       The QPtrDict class is a template class that provides a dictionary based
44       on void* keys.
45
46       QPtrDict is implemented as a template class. Define a template instance
47       QPtrDict<X> to create a dictionary that operates on pointers to X (X*).
48
49       A dictionary is a collection of key-value pairs. The key is a void*
50       used for insertion, removal and lookup. The value is a pointer.
51       Dictionaries provide very fast insertion and lookup.
52
53       Example:
54
55           QPtrDict<char> fields; // void* keys, char* values
56           QLineEdit *le1 = new QLineEdit( this );
57           le1->setText( "Simpson" );
58           QLineEdit *le2 = new QLineEdit( this );
59           le2->setText( "Homer" );
60           QLineEdit *le3 = new QLineEdit( this );
61           le3->setText( "45" );
62           fields.insert( le1, "Surname" );
63           fields.insert( le2, "Forename" );
64           fields.insert( le3, "Age" );
65           QPtrDictIterator<char> it( fields );
66           for( ; it.current(); ++it )
67               cout << it.current() << endl;
68           cout << endl;
69           if ( fields[le1] ) // Prints "Surname: Simpson"
70               cout << fields[le1] << ": " << le1->text() << endl;
71           if ( fields[le2] ) // Prints "Forename: Homer"
72               cout << fields[le2] << ": " << le2->text() << endl;
73           fields.remove( le1 ); // Removes le1 from the dictionary
74           cout << le1->text() << endl; // Prints "Simpson"
75       In this example we use a dictionary to add an extra property (a char*)
76       to the line edits we're using.
77
78       See QDict for full details, including the choice of dictionary size,
79       and how deletions are handled.
80
81       See also QPtrDictIterator, QDict, QAsciiDict, QIntDict, Collection
82       Classes, Collection Classes, and Non-GUI Classes.
83

MEMBER FUNCTION DOCUMENTATION

QPtrDict::QPtrDict ( int size = 17 )

86       Constructs a dictionary using an internal hash array with the size
87       size.
88
89       Setting size to a suitably large prime number (equal to or greater than
90       the expected number of entries) makes the hash distribution better and
91       improves lookup performance.
92

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

94       Constructs a copy of dict.
95
96       Each item in dict is inserted into this dictionary. Only the pointers
97       are copied (shallow copy).
98

QPtrDict::~QPtrDict ()

100       Removes all items from the dictionary and destroys it.
101
102       All iterators that access this dictionary will be reset.
103
104       See also setAutoDelete().
105

bool QPtrCollection::autoDelete () const

107       Returns the setting of the auto-delete option. The default is FALSE.
108
109       See also setAutoDelete().
110

void QPtrDict::clear () [virtual]

112       Removes all items from the dictionary.
113
114       The removed items are deleted if auto-deletion is enabled.
115
116       All dictionary iterators that access this dictionary will be reset.
117
118       See also remove(), take(), and setAutoDelete().
119
120       Reimplemented from QPtrCollection.
121

uint QPtrDict::count () const [virtual]

123       Returns the number of items in the dictionary.
124
125       See also isEmpty().
126
127       Reimplemented from QPtrCollection.
128

type * QPtrDict::find ( void * key ) const

130       Returns the item associated with key, or 0 if the key does not exist in
131       the dictionary.
132
133       If there are two or more items with equal keys, then the most recently
134       inserted item will be found.
135
136       Equivalent to operator[].
137
138       See also operator[]().
139

void QPtrDict::insert ( void * key, const type * item )

141       Inserts the key with the item into the dictionary.
142
143       Multiple items can have the same key, in which case only the last item
144       will be accessible using operator[]().
145
146       item may not be 0.
147
148       See also replace().
149

bool QPtrDict::isEmpty () const

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

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

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

type * QPtrDict::operator[] ( void * key ) const

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

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

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

bool QPtrDict::remove ( void * key )

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

void QPtrDict::replace ( void * 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               QPtrDict<ItemType> 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

void QPtrDict::resize ( uint newsize )

219       Changes the size of the hash table to newsize. The contents of the
220       dictionary are preserved, but all iterators on the dictionary become
221       invalid.
222

void QPtrCollection::setAutoDelete ( bool enable )

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

uint QPtrDict::size () const

245       Returns the size of the internal hash table (as specified in the
246       constructor).
247
248       See also count().
249

void QPtrDict::statistics () const

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

type * QPtrDict::take ( void * key )

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

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

270       [virtual protected]
271       Writes a dictionary item to the stream s and returns a reference to the
272       stream.
273
274       See also read().
275
276

SEE ALSO

278       http://doc.trolltech.com/qptrdict.html
279       http://www.trolltech.com/faq/tech.html
280
282       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
283       license file included in the distribution for a complete license
284       statement.
285

AUTHOR

287       Generated automatically from the source code.
288

BUGS

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