1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/qintdict.doc:41 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QIntDict Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QIntDict Class Reference</h1>
|
---|
33 |
|
---|
34 | <p>The QIntDict class is a template class that provides a dictionary based on long keys.
|
---|
35 | <a href="#details">More...</a>
|
---|
36 | <p><tt>#include <<a href="qintdict-h.html">qintdict.h</a>></tt>
|
---|
37 | <p>Inherits <a href="qptrcollection.html">QPtrCollection</a>.
|
---|
38 | <p><a href="qintdict-members.html">List of all member functions.</a>
|
---|
39 | <h2>Public Members</h2>
|
---|
40 | <ul>
|
---|
41 | <li class=fn><a href="#QIntDict"><b>QIntDict</b></a> ( int size = 17 )</li>
|
---|
42 | <li class=fn><a href="#QIntDict-2"><b>QIntDict</b></a> ( const QIntDict<type> & dict )</li>
|
---|
43 | <li class=fn><a href="#~QIntDict"><b>~QIntDict</b></a> ()</li>
|
---|
44 | <li class=fn>QIntDict<type> & <a href="#operator-eq"><b>operator=</b></a> ( const QIntDict<type> & dict )</li>
|
---|
45 | <li class=fn>virtual uint <a href="#count"><b>count</b></a> () const</li>
|
---|
46 | <li class=fn>uint <a href="#size"><b>size</b></a> () const</li>
|
---|
47 | <li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
|
---|
48 | <li class=fn>void <a href="#insert"><b>insert</b></a> ( long key, const type * item )</li>
|
---|
49 | <li class=fn>void <a href="#replace"><b>replace</b></a> ( long key, const type * item )</li>
|
---|
50 | <li class=fn>bool <a href="#remove"><b>remove</b></a> ( long key )</li>
|
---|
51 | <li class=fn>type * <a href="#take"><b>take</b></a> ( long key )</li>
|
---|
52 | <li class=fn>type * <a href="#find"><b>find</b></a> ( long key ) const</li>
|
---|
53 | <li class=fn>type * <a href="#operator[]"><b>operator[]</b></a> ( long key ) const</li>
|
---|
54 | <li class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</li>
|
---|
55 | <li class=fn>void <a href="#resize"><b>resize</b></a> ( uint newsize )</li>
|
---|
56 | <li class=fn>void <a href="#statistics"><b>statistics</b></a> () const</li>
|
---|
57 | </ul>
|
---|
58 | <h2>Important Inherited Members</h2>
|
---|
59 | <ul>
|
---|
60 | <li class=fn>bool <a href="#autoDelete"><b>autoDelete</b></a> () const</li>
|
---|
61 | <li class=fn>void <a href="#setAutoDelete"><b>setAutoDelete</b></a> ( bool enable )</li>
|
---|
62 | </ul>
|
---|
63 | <h2>Protected Members</h2>
|
---|
64 | <ul>
|
---|
65 | <li class=fn>virtual QDataStream & <a href="#read"><b>read</b></a> ( QDataStream & s, QPtrCollection::Item & item )</li>
|
---|
66 | <li class=fn>virtual QDataStream & <a href="#write"><b>write</b></a> ( QDataStream & s, QPtrCollection::Item ) const</li>
|
---|
67 | </ul>
|
---|
68 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
69 |
|
---|
70 |
|
---|
71 | The QIntDict class is a template class that provides a dictionary based on long keys.
|
---|
72 | <p>
|
---|
73 |
|
---|
74 | <p>
|
---|
75 | <p> <a href="qmap.html">QMap</a> is an STL-compatible alternative to this class.
|
---|
76 | <p> QIntDict is implemented as a template class. Define a template
|
---|
77 | instance QIntDict<X> to create a dictionary that operates on
|
---|
78 | pointers to X (X*).
|
---|
79 | <p> A dictionary is a collection of key-value pairs. The key is an <tt>long</tt> used for insertion, removal and lookup. The value is a
|
---|
80 | pointer. Dictionaries provide very fast insertion and lookup.
|
---|
81 | <p> Example:
|
---|
82 | <pre>
|
---|
83 | QIntDict<QLineEdit> fields; // long int keys, QLineEdit* values
|
---|
84 | for ( int i = 0; i < 3; i++ )
|
---|
85 | fields.<a href="#insert">insert</a>( i, new <a href="qlineedit.html">QLineEdit</a>( this ) );
|
---|
86 |
|
---|
87 | fields[0]->setText( "Homer" );
|
---|
88 | fields[1]->setText( "Simpson" );
|
---|
89 | fields[2]->setText( "45" );
|
---|
90 |
|
---|
91 | <a href="qintdictiterator.html">QIntDictIterator</a><QLineEdit> it( fields );
|
---|
92 | for ( ; it.<a href="qintdictiterator.html#current">current</a>(); ++it )
|
---|
93 | cout << it.<a href="qintdictiterator.html#currentKey">currentKey</a>() << ": " << it.<a href="qintdictiterator.html#current">current</a>()->text() << endl;
|
---|
94 |
|
---|
95 | for ( int i = 0; i < 3; i++ )
|
---|
96 | cout << fields[i]->text() << " "; // Prints "Homer Simpson 45"
|
---|
97 | cout << endl;
|
---|
98 |
|
---|
99 | fields.<a href="#remove">remove</a>( 1 ); // Does not delete the line edit
|
---|
100 | for ( int i = 0; i < 3; i++ )
|
---|
101 | if ( fields[i] )
|
---|
102 | cout << fields[i]->text() << " "; // Prints "Homer 45"
|
---|
103 | </pre>
|
---|
104 |
|
---|
105 | <p> See <a href="qdict.html">QDict</a> for full details, including the choice of dictionary
|
---|
106 | size, and how deletions are handled.
|
---|
107 | <p> <p>See also <a href="qintdictiterator.html">QIntDictIterator</a>, <a href="qdict.html">QDict</a>, <a href="qasciidict.html">QAsciiDict</a>, <a href="qptrdict.html">QPtrDict</a>, <a href="collection.html">Collection Classes</a>, <a href="collection.html">Collection Classes</a>, and <a href="tools.html">Non-GUI Classes</a>.
|
---|
108 |
|
---|
109 | <hr><h2>Member Function Documentation</h2>
|
---|
110 | <h3 class=fn><a name="QIntDict"></a>QIntDict::QIntDict ( int size = 17 )
|
---|
111 | </h3>
|
---|
112 |
|
---|
113 | <p> Constructs a dictionary using an internal hash array of size <em>size</em>.
|
---|
114 | <p> Setting <em>size</em> to a suitably large <a href="primes.html#prime">prime</a> number (equal to or
|
---|
115 | greater than the expected number of entries) makes the hash
|
---|
116 | distribution better which leads to faster lookup.
|
---|
117 |
|
---|
118 | <h3 class=fn><a name="QIntDict-2"></a>QIntDict::QIntDict ( const <a href="qintdict.html">QIntDict</a><type> & dict )
|
---|
119 | </h3>
|
---|
120 |
|
---|
121 | <p> Constructs a copy of <em>dict</em>.
|
---|
122 | <p> Each item in <em>dict</em> is inserted into this dictionary. Only the
|
---|
123 | pointers are copied (shallow copy).
|
---|
124 |
|
---|
125 | <h3 class=fn><a name="~QIntDict"></a>QIntDict::~QIntDict ()
|
---|
126 | </h3>
|
---|
127 |
|
---|
128 | <p> Removes all items from the dictionary and destroys it.
|
---|
129 | <p> All iterators that access this dictionary will be reset.
|
---|
130 | <p> <p>See also <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
|
---|
131 |
|
---|
132 | <h3 class=fn>bool <a name="autoDelete"></a>QPtrCollection::autoDelete () const
|
---|
133 | </h3>
|
---|
134 |
|
---|
135 | <p> Returns the setting of the auto-delete option. The default is FALSE.
|
---|
136 | <p> <p>See also <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
|
---|
137 |
|
---|
138 | <h3 class=fn>void <a name="clear"></a>QIntDict::clear ()<tt> [virtual]</tt>
|
---|
139 | </h3>
|
---|
140 |
|
---|
141 | <p> Removes all items from the dictionary.
|
---|
142 | <p> The removed items are deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
|
---|
143 | <p> All dictionary iterators that access this dictionary will be reset.
|
---|
144 | <p> <p>See also <a href="#remove">remove</a>(), <a href="#take">take</a>(), and <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
|
---|
145 |
|
---|
146 | <p>Reimplemented from <a href="qptrcollection.html#clear">QPtrCollection</a>.
|
---|
147 | <h3 class=fn>uint <a name="count"></a>QIntDict::count () const<tt> [virtual]</tt>
|
---|
148 | </h3>
|
---|
149 |
|
---|
150 | <p> Returns the number of items in the dictionary.
|
---|
151 | <p> <p>See also <a href="#isEmpty">isEmpty</a>().
|
---|
152 |
|
---|
153 | <p>Reimplemented from <a href="qptrcollection.html#count">QPtrCollection</a>.
|
---|
154 | <h3 class=fn>type * <a name="find"></a>QIntDict::find ( long key ) const
|
---|
155 | </h3>
|
---|
156 |
|
---|
157 | <p> Returns the item associated with <em>key</em>, or 0 if the key does not
|
---|
158 | exist in the dictionary.
|
---|
159 | <p> If there are two or more items with equal keys, then the most
|
---|
160 | recently inserted item will be found.
|
---|
161 | <p> Equivalent to operator[].
|
---|
162 | <p> <p>See also <a href="#operator[]">operator[]</a>().
|
---|
163 |
|
---|
164 | <p>Example: <a href="bigtable-example.html#x1286">table/bigtable/main.cpp</a>.
|
---|
165 | <h3 class=fn>void <a name="insert"></a>QIntDict::insert ( long key, const type * item )
|
---|
166 | </h3>
|
---|
167 |
|
---|
168 | <p> Insert item <em>item</em> into the dictionary using key <em>key</em>.
|
---|
169 | <p> Multiple items can have the same key, in which case only the last
|
---|
170 | item will be accessible using <a href="#operator[]">operator[]</a>().
|
---|
171 | <p> <em>item</em> may not be 0.
|
---|
172 | <p> <p>See also <a href="#replace">replace</a>().
|
---|
173 |
|
---|
174 | <p>Example: <a href="scribble-example.html#x912">scribble/scribble.cpp</a>.
|
---|
175 | <h3 class=fn>bool <a name="isEmpty"></a>QIntDict::isEmpty () const
|
---|
176 | </h3>
|
---|
177 |
|
---|
178 | <p> Returns TRUE if the dictionary is empty; otherwise returns FALSE.
|
---|
179 | <p> <p>See also <a href="#count">count</a>().
|
---|
180 |
|
---|
181 | <h3 class=fn><a href="qintdict.html">QIntDict</a><type> & <a name="operator-eq"></a>QIntDict::operator= ( const <a href="qintdict.html">QIntDict</a><type> & dict )
|
---|
182 | </h3>
|
---|
183 |
|
---|
184 | <p> Assigns <em>dict</em> to this dictionary and returns a reference to this
|
---|
185 | dictionary.
|
---|
186 | <p> This dictionary is first cleared and then each item in <em>dict</em> is
|
---|
187 | inserted into this dictionary. Only the pointers are copied
|
---|
188 | (shallow copy), unless <a href="qptrcollection.html#newItem">newItem</a>() has been reimplemented.
|
---|
189 |
|
---|
190 | <h3 class=fn>type * <a name="operator[]"></a>QIntDict::operator[] ( long key ) const
|
---|
191 | </h3>
|
---|
192 |
|
---|
193 | <p> Returns the item associated with <em>key</em>, or 0 if the key does not
|
---|
194 | exist in the dictionary.
|
---|
195 | <p> If there are two or more items with equal keys, then the most
|
---|
196 | recently inserted item will be found.
|
---|
197 | <p> Equivalent to the <a href="#find">find</a>() function.
|
---|
198 | <p> <p>See also <a href="#find">find</a>().
|
---|
199 |
|
---|
200 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="read"></a>QIntDict::read ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> & item )<tt> [virtual protected]</tt>
|
---|
201 | </h3>
|
---|
202 |
|
---|
203 | <p> Reads a dictionary item from the stream <em>s</em> and returns a
|
---|
204 | reference to the stream.
|
---|
205 | <p> The default implementation sets <em>item</em> to 0.
|
---|
206 | <p> <p>See also <a href="#write">write</a>().
|
---|
207 |
|
---|
208 | <h3 class=fn>bool <a name="remove"></a>QIntDict::remove ( long key )
|
---|
209 | </h3>
|
---|
210 |
|
---|
211 | <p> Removes the item associated with <em>key</em> from the dictionary.
|
---|
212 | Returns TRUE if successful, i.e. if the <em>key</em> is in the
|
---|
213 | dictionary; otherwise returns FALSE.
|
---|
214 | <p> If there are two or more items with equal keys, then the most
|
---|
215 | recently inserted item will be removed.
|
---|
216 | <p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
|
---|
217 | <p> All dictionary iterators that refer to the removed item will be
|
---|
218 | set to point to the next item in the dictionary's traversal
|
---|
219 | order.
|
---|
220 | <p> <p>See also <a href="#take">take</a>(), <a href="#clear">clear</a>(), and <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
|
---|
221 |
|
---|
222 | <p>Example: <a href="bigtable-example.html#x1287">table/bigtable/main.cpp</a>.
|
---|
223 | <h3 class=fn>void <a name="replace"></a>QIntDict::replace ( long key, const type * item )
|
---|
224 | </h3>
|
---|
225 |
|
---|
226 | <p> If the dictionary has key <em>key</em>, this key's item is replaced with
|
---|
227 | <em>item</em>. If the dictionary doesn't contain key <em>key</em>, <em>item</em> is
|
---|
228 | inserted into the dictionary using key <em>key</em>.
|
---|
229 | <p> <em>item</em> may not be 0.
|
---|
230 | <p> Equivalent to:
|
---|
231 | <pre>
|
---|
232 | QIntDict<char> dict;
|
---|
233 | // ...
|
---|
234 | if ( dict.<a href="#find">find</a>(key) )
|
---|
235 | dict.<a href="#remove">remove</a>( key );
|
---|
236 | dict.<a href="#insert">insert</a>( key, item );
|
---|
237 | </pre>
|
---|
238 |
|
---|
239 | <p> If there are two or more items with equal keys, then the most
|
---|
240 | recently inserted item will be replaced.
|
---|
241 | <p> <p>See also <a href="#insert">insert</a>().
|
---|
242 |
|
---|
243 | <p>Example: <a href="bigtable-example.html#x1288">table/bigtable/main.cpp</a>.
|
---|
244 | <h3 class=fn>void <a name="resize"></a>QIntDict::resize ( uint newsize )
|
---|
245 | </h3>
|
---|
246 |
|
---|
247 | <p> Changes the size of the hashtable to <em>newsize</em>. The contents of
|
---|
248 | the dictionary are preserved, but all iterators on the dictionary
|
---|
249 | become invalid.
|
---|
250 |
|
---|
251 | <h3 class=fn>void <a name="setAutoDelete"></a>QPtrCollection::setAutoDelete ( bool enable )
|
---|
252 | </h3>
|
---|
253 |
|
---|
254 | <p> Sets the collection to auto-delete its contents if <em>enable</em> is
|
---|
255 | TRUE and to never delete them if <em>enable</em> is FALSE.
|
---|
256 | <p> If auto-deleting is turned on, all the items in a collection are
|
---|
257 | deleted when the collection itself is deleted. This is convenient
|
---|
258 | if the collection has the only pointer to the items.
|
---|
259 | <p> The default setting is FALSE, for safety. If you turn it on, be
|
---|
260 | careful about copying the collection - you might find yourself
|
---|
261 | with two collections deleting the same items.
|
---|
262 | <p> Note that the auto-delete setting may also affect other functions
|
---|
263 | in subclasses. For example, a subclass that has a <a href="#remove">remove</a>()
|
---|
264 | function will remove the item from its data structure, and if
|
---|
265 | auto-delete is enabled, will also delete the item.
|
---|
266 | <p> <p>See also <a href="qptrcollection.html#autoDelete">autoDelete</a>().
|
---|
267 |
|
---|
268 | <p>Examples: <a href="grapher-nsplugin-example.html#x2769">grapher/grapher.cpp</a>, <a href="scribble-example.html#x924">scribble/scribble.cpp</a>, and <a href="bigtable-example.html#x1291">table/bigtable/main.cpp</a>.
|
---|
269 | <h3 class=fn>uint <a name="size"></a>QIntDict::size () const
|
---|
270 | </h3>
|
---|
271 |
|
---|
272 | <p> Returns the size of the internal hash array (as specified in the
|
---|
273 | constructor).
|
---|
274 | <p> <p>See also <a href="#count">count</a>().
|
---|
275 |
|
---|
276 | <h3 class=fn>void <a name="statistics"></a>QIntDict::statistics () const
|
---|
277 | </h3>
|
---|
278 |
|
---|
279 | <p> Debugging-only function that prints out the dictionary
|
---|
280 | distribution using <a href="qapplication.html#qDebug">qDebug</a>().
|
---|
281 |
|
---|
282 | <h3 class=fn>type * <a name="take"></a>QIntDict::take ( long key )
|
---|
283 | </h3>
|
---|
284 |
|
---|
285 | <p> Takes the item associated with <em>key</em> out of the dictionary
|
---|
286 | without deleting it (even if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled).
|
---|
287 | <p> If there are two or more items with equal keys, then the most
|
---|
288 | recently inserted item will be taken.
|
---|
289 | <p> Returns a pointer to the item taken out, or 0 if the key does not
|
---|
290 | exist in the dictionary.
|
---|
291 | <p> All dictionary iterators that refer to the taken item will be set
|
---|
292 | to point to the next item in the dictionary's traversing order.
|
---|
293 | <p> <p>See also <a href="#remove">remove</a>(), <a href="#clear">clear</a>(), and <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
|
---|
294 |
|
---|
295 | <p>Example: <a href="bigtable-example.html#x1289">table/bigtable/main.cpp</a>.
|
---|
296 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="write"></a>QIntDict::write ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> ) const<tt> [virtual protected]</tt>
|
---|
297 | </h3>
|
---|
298 |
|
---|
299 | <p> Writes a dictionary item to the stream <em>s</em> and returns a
|
---|
300 | reference to the stream.
|
---|
301 | <p> <p>See also <a href="#read">read</a>().
|
---|
302 |
|
---|
303 | <!-- eof -->
|
---|
304 | <hr><p>
|
---|
305 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
306 | Copyright © 1995-2007
|
---|
307 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
308 | <table width=100% cellspacing=0 border=0><tr>
|
---|
309 | <td>Copyright © 2007
|
---|
310 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
311 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
312 | </table></div></address></body>
|
---|
313 | </html>
|
---|