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