source: trunk/src/qt3support/tools/q3ptrdict.qdoc@ 890

Last change on this file since 890 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 9.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \class Q3PtrDict
30 \brief The Q3PtrDict class is a template class that provides a dictionary based on void* keys.
31 \compat
32
33 Q3PtrDict is implemented as a template class. Define a template
34 instance Q3PtrDict\<X\> to create a dictionary that operates on
35 pointers to X (X*).
36
37 A dictionary is a collection of key-value pairs. The key is a
38 void* used for insertion, removal and lookup. The value is a
39 pointer. Dictionaries provide very fast insertion and lookup.
40
41 Example:
42 \snippet doc/src/snippets/code/doc_src_q3ptrdict.qdoc 0
43 In this example we use a dictionary to add an extra property (a
44 char*) to the line edits we're using.
45
46 See Q3Dict for full details, including the choice of dictionary
47 size, and how deletions are handled.
48
49 \sa Q3PtrDictIterator, Q3Dict, Q3AsciiDict, Q3IntDict
50*/
51
52
53/*!
54 \fn Q3PtrDict::Q3PtrDict( int size )
55
56 Constructs a dictionary using an internal hash array with the size
57 \a size.
58
59 Setting \a size to a suitably large prime number (equal to or
60 greater than the expected number of entries) makes the hash
61 distribution better and improves lookup performance.
62*/
63
64/*!
65 \fn Q3PtrDict::Q3PtrDict( const Q3PtrDict<type> &dict )
66
67 Constructs a copy of \a dict.
68
69 Each item in \a dict is inserted into this dictionary. Only the
70 pointers are copied (shallow copy).
71*/
72
73/*!
74 \fn Q3PtrDict::~Q3PtrDict()
75
76 Removes all items from the dictionary and destroys it.
77
78 All iterators that access this dictionary will be reset.
79
80 \sa setAutoDelete()
81*/
82
83/*!
84 \fn Q3PtrDict<type> &Q3PtrDict::operator=(const Q3PtrDict<type> &dict)
85
86 Assigns \a dict to this dictionary and returns a reference to this
87 dictionary.
88
89 This dictionary is first cleared and then each item in \a dict is
90 inserted into the dictionary. Only the pointers are copied
91 (shallow copy), unless newItem() has been reimplemented.
92*/
93
94/*!
95 \fn uint Q3PtrDict::count() const
96
97 Returns the number of items in the dictionary.
98
99 \sa isEmpty()
100*/
101
102/*!
103 \fn uint Q3PtrDict::size() const
104
105 Returns the size of the internal hash table (as specified in the
106 constructor).
107
108 \sa count()
109*/
110
111/*!
112 \fn void Q3PtrDict::resize( uint newsize )
113
114 Changes the size of the hash table to \a newsize. The contents of
115 the dictionary are preserved, but all iterators on the dictionary
116 become invalid.
117*/
118
119/*!
120 \fn bool Q3PtrDict::isEmpty() const
121
122 Returns TRUE if the dictionary is empty; otherwise returns FALSE.
123
124 \sa count()
125*/
126
127/*!
128 \fn void Q3PtrDict::insert( void *key, const type *item )
129
130 Inserts the \a key with the \a item into the dictionary.
131
132 Multiple items can have the same key, in which case only the last
133 item will be accessible using \l operator[]().
134
135 \a item may not be 0.
136
137 \sa replace()
138*/
139
140/*!
141 \fn void Q3PtrDict::replace( void *key, const type *item )
142
143 If the dictionary has key \a key, this key's item is replaced with
144 \a item. If the dictionary doesn't contain key \a key, \a item is
145 inserted into the dictionary using key \a key.
146
147 \a item may not be 0.
148
149 Equivalent to
150 \snippet doc/src/snippets/code/doc_src_q3ptrdict.qdoc 1
151
152 If there are two or more items with equal keys, then the most
153 recently inserted item will be replaced.
154
155 \sa insert()
156*/
157
158/*!
159 \fn bool Q3PtrDict::remove( void *key )
160
161 Removes the item associated with \a key from the dictionary.
162 Returns TRUE if successful, i.e. if \a key is in the dictionary;
163 otherwise returns FALSE.
164
165 If there are two or more items with equal keys, then the most
166 recently inserted item will be removed.
167
168 The removed item is deleted if \link
169 Q3PtrCollection::setAutoDelete() auto-deletion\endlink is enabled.
170
171 All dictionary iterators that refer to the removed item will be
172 set to point to the next item in the dictionary traversal order.
173
174 \sa take(), clear(), setAutoDelete()
175*/
176
177/*!
178 \fn type *Q3PtrDict::take( void *key )
179
180 Takes the item associated with \a key out of the dictionary
181 without deleting it (even if \link Q3PtrCollection::setAutoDelete()
182 auto-deletion\endlink is enabled).
183
184 If there are two or more items with equal keys, then the most
185 recently inserted item will be removed.
186
187 Returns a pointer to the item taken out, or 0 if the key does not
188 exist in the dictionary.
189
190 All dictionary iterators that refer to the taken item will be set
191 to point to the next item in the dictionary traversal order.
192
193 \sa remove(), clear(), setAutoDelete()
194*/
195
196/*!
197 \fn void Q3PtrDict::clear()
198
199 Removes all items from the dictionary.
200
201 The removed items are deleted if \link
202 Q3PtrCollection::setAutoDelete() auto-deletion\endlink is enabled.
203
204 All dictionary iterators that access this dictionary will be
205 reset.
206
207 \sa remove(), take(), setAutoDelete()
208*/
209
210/*!
211 \fn type *Q3PtrDict::find( void *key ) const
212
213 Returns the item associated with \a key, or 0 if the key does not
214 exist in the dictionary.
215
216 If there are two or more items with equal keys, then the most
217 recently inserted item will be found.
218
219 Equivalent to operator[].
220
221 \sa operator[]()
222*/
223
224/*!
225 \fn type *Q3PtrDict::operator[]( void *key ) const
226
227 Returns the item associated with \a key, or 0 if the key does not
228 exist in the dictionary.
229
230 If there are two or more items with equal keys, then the most
231 recently inserted item will be found.
232
233 Equivalent to the find() function.
234
235 \sa find()
236*/
237
238/*!
239 \fn void Q3PtrDict::statistics() const
240
241 Debugging-only function that prints out the dictionary
242 distribution using qDebug().
243*/
244
245/*!
246 \fn QDataStream& Q3PtrDict::read( QDataStream &s, Q3PtrCollection::Item &item )
247
248 Reads a dictionary item from the stream \a s and returns a
249 reference to the stream.
250
251 The default implementation sets \a item to 0.
252
253 \sa write()
254*/
255
256/*!
257 \fn QDataStream& Q3PtrDict::write( QDataStream &s, Q3PtrCollection::Item item) const
258
259 Writes a dictionary \a item to the stream \a s and returns a
260 reference to the stream.
261
262 \sa read()
263*/
264
265/*!
266 \class Q3PtrDictIterator
267 \brief The Q3PtrDictIterator class provides an iterator for Q3PtrDict collections.
268 \compat
269
270 Q3PtrDictIterator is implemented as a template class. Define a
271 template instance Q3PtrDictIterator\<X\> to create a dictionary
272 iterator that operates on Q3PtrDict\<X\> (dictionary of X*).
273
274 Example:
275 \snippet doc/src/snippets/code/doc_src_q3ptrdict.qdoc 2
276 In the example we insert some line edits into a dictionary,
277 associating a string with each. We then iterate over the
278 dictionary printing the associated strings.
279
280 Multiple iterators may independently traverse the same dictionary.
281 A Q3PtrDict knows about all the iterators that are operating on the
282 dictionary. When an item is removed from the dictionary, Q3PtrDict
283 updates all iterators that refer the removed item to point to the
284 next item in the traversing order.
285
286 \sa Q3PtrDict
287*/
288
289/*!
290 \fn Q3PtrDictIterator::Q3PtrDictIterator( const Q3PtrDict<type> &dict )
291
292 Constructs an iterator for \a dict. The current iterator item is
293 set to point on the first item in the \a dict.
294*/
295
296/*!
297 \fn Q3PtrDictIterator::~Q3PtrDictIterator()
298
299 Destroys the iterator.
300*/
301
302/*!
303 \fn uint Q3PtrDictIterator::count() const
304
305 Returns the number of items in the dictionary this iterator
306 operates on.
307
308 \sa isEmpty()
309*/
310
311/*!
312 \fn bool Q3PtrDictIterator::isEmpty() const
313
314 Returns TRUE if the dictionary is empty; otherwise returns FALSE.
315
316 \sa count()
317*/
318
319/*!
320 \fn type *Q3PtrDictIterator::toFirst()
321
322 Sets the current iterator item to point to the first item in the
323 dictionary and returns a pointer to the item. If the dictionary is
324 empty, it sets the current item to 0 and returns 0.
325*/
326
327/*!
328 \fn Q3PtrDictIterator::operator type *() const
329
330 Cast operator. Returns a pointer to the current iterator item.
331 Same as current().
332*/
333
334/*!
335 \fn type *Q3PtrDictIterator::current() const
336
337 Returns a pointer to the current iterator item's value.
338*/
339
340/*!
341 \fn void *Q3PtrDictIterator::currentKey() const
342
343 Returns the current iterator item's key.
344*/
345
346/*!
347 \fn type *Q3PtrDictIterator::operator()()
348
349 Makes the succeeding item current and returns the original current
350 item.
351
352 If the current iterator item was the last item in the dictionary
353 or if it was 0, 0 is returned.
354*/
355
356/*!
357 \fn type *Q3PtrDictIterator::operator++()
358
359 Prefix ++ makes the succeeding item current and returns the new
360 current item.
361
362 If the current iterator item was the last item in the dictionary
363 or if it was 0, 0 is returned.
364*/
365
366/*!
367 \fn type *Q3PtrDictIterator::operator+=( uint jump )
368
369 Sets the current item to the item \a jump positions after the
370 current item and returns a pointer to that item.
371
372 If that item is beyond the last item or if the dictionary is
373 empty, it sets the current item to 0 and returns 0.
374*/
Note: See TracBrowser for help on using the repository browser.