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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
<!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/qmemarray.doc:41 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQMemArray 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>TQMemArray Class Reference</h1>
<p>The TQMemArray class is a template class that provides arrays of simple types.
<a href="#details">More...</a>
<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when TQt is built with thread support.</p>
<p><tt>#include <<a href="qmemarray-h.html">ntqmemarray.h</a>></tt>
<p>Inherited by <a href="qbytearray.html">TQByteArray</a> and <a href="ntqpointarray.html">TQPointArray</a>.
<p><a href="qmemarray-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn>typedef type * <a href="#Iterator"><b>Iterator</b></a></li>
<li class=fn>typedef const type * <a href="#ConstIterator"><b>ConstIterator</b></a></li>
<li class=fn><a href="#TQMemArray-2"><b>TQMemArray</b></a> ()</li>
<li class=fn><a href="#TQMemArray-3"><b>TQMemArray</b></a> ( int size )</li>
<li class=fn><a href="#TQMemArray-4"><b>TQMemArray</b></a> ( const TQMemArray<type> & a )</li>
<li class=fn><a href="#~TQMemArray"><b>~TQMemArray</b></a> ()</li>
<li class=fn>TQMemArray<type> & <a href="#operator-eq"><b>operator=</b></a> ( const TQMemArray<type> & a )</li>
<li class=fn>type * <a href="#data"><b>data</b></a> () const</li>
<li class=fn>uint <a href="#nrefs"><b>nrefs</b></a> () const</li>
<li class=fn>uint <a href="#size"><b>size</b></a> () const</li>
<li class=fn>uint <a href="#count"><b>count</b></a> () const</li>
<li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
<li class=fn>bool <a href="#resize-2"><b>resize</b></a> ( uint size )</li>
<li class=fn>bool <a href="#resize"><b>resize</b></a> ( uint size, Optimization optim )</li>
<li class=fn>bool <a href="#truncate"><b>truncate</b></a> ( uint pos )</li>
<li class=fn>bool <a href="#fill"><b>fill</b></a> ( const type & v, int size = -1 )</li>
<li class=fn>virtual void <a href="#detach"><b>detach</b></a> ()</li>
<li class=fn>TQMemArray<type> <a href="#copy"><b>copy</b></a> () const</li>
<li class=fn>TQMemArray<type> & <a href="#assign"><b>assign</b></a> ( const TQMemArray<type> & a )</li>
<li class=fn>TQMemArray<type> & <a href="#assign-2"><b>assign</b></a> ( const type * data, uint size )</li>
<li class=fn>TQMemArray<type> & <a href="#duplicate"><b>duplicate</b></a> ( const TQMemArray<type> & a )</li>
<li class=fn>TQMemArray<type> & <a href="#duplicate-2"><b>duplicate</b></a> ( const type * data, uint size )</li>
<li class=fn>TQMemArray<type> & <a href="#setRawData"><b>setRawData</b></a> ( const type * data, uint size )</li>
<li class=fn>void <a href="#resetRawData"><b>resetRawData</b></a> ( const type * data, uint size )</li>
<li class=fn>int <a href="#find"><b>find</b></a> ( const type & v, uint index = 0 ) const</li>
<li class=fn>int <a href="#contains"><b>contains</b></a> ( const type & v ) const</li>
<li class=fn>void <a href="#sort"><b>sort</b></a> ()</li>
<li class=fn>int <a href="#bsearch"><b>bsearch</b></a> ( const type & v ) const</li>
<li class=fn>type & <a href="#operator[]"><b>operator[]</b></a> ( int index ) const</li>
<li class=fn>type & <a href="#at"><b>at</b></a> ( uint index ) const</li>
<li class=fn><a href="#operator-const-type-*"><b>operator const type *</b></a> () const</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const TQMemArray<type> & a ) const</li>
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const TQMemArray<type> & a ) const</li>
<li class=fn>Iterator <a href="#begin"><b>begin</b></a> ()</li>
<li class=fn>Iterator <a href="#end"><b>end</b></a> ()</li>
<li class=fn>ConstIterator <a href="#begin-2"><b>begin</b></a> () const</li>
<li class=fn>ConstIterator <a href="#end-2"><b>end</b></a> () const</li>
</ul>
<h2>Protected Members</h2>
<ul>
<li class=fn><a href="#TQMemArray"><b>TQMemArray</b></a> ( int, int )</li>
</ul>
<h2>Related Functions</h2>
<ul>
<li class=fn>Q_UINT16 <a href="#qChecksum"><b>qChecksum</b></a> ( const char * data, uint len )</li>
<li class=fn>TQDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( TQDataStream & s, const TQByteArray & a )</li>
<li class=fn>TQDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( TQDataStream & s, TQByteArray & a )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The TQMemArray class is a template class that provides arrays of simple types.
<p>
<p> TQMemArray is implemented as a template class. Define a template
instance TQMemArray<X> to create an array that contains X items.
<p> TQMemArray stores the array elements directly in the array. It can
only deal with simple types (i.e. C++ types, structs, and classes
that have no constructors, destructors, or virtual functions).
TQMemArray uses bitwise operations to copy and compare array
elements.
<p> The <a href="ntqptrvector.html">TQPtrVector</a> collection class is also a kind of array. Like most
<a href="collection.html">collection classes</a>, it uses pointers
to the contained items.
<p> TQMemArray uses <a href="shclass.html">explicit sharing</a> with a
reference count. If more than one array shares common data and one
of the arrays is modified, all the arrays are modified.
<p> The benefit of sharing is that a program does not need to duplicate
data when it is not required, which results in lower memory use
and less copying of data.
<p> An alternative to TQMemArray is <a href="ntqvaluevector.html">TQValueVector</a>. The TQValueVector class
also provides an array of objects, but can deal with objects that
have constructors (specifically a copy constructor and a default
constructor). TQValueVector provides an STL-compatible syntax and is
<a href="shclass.html">implicitly shared</a>.
<p> Example:
<pre>
#include <<a href="qmemarray-h.html">ntqmemarray.h</a>>
#include <stdio.h>
TQMemArray<int> fib( int num ) // returns fibonacci array
{
<a href="ntqapplication.html#Q_ASSERT">Q_ASSERT</a>( num > 2 );
TQMemArray<int> f( num ); // array of ints
f[0] = f[1] = 1;
for ( int i = 2; i < num; i++ )
f[i] = f[i-1] + f[i-2];
return f;
}
int main()
{
TQMemArray<int> a = fib( 6 ); // get first 6 fibonaccis
for ( int i = 0; i < a.<a href="#size">size</a>(); i++ )
<a href="ntqapplication.html#qDebug">qDebug</a>( "%d: %d", i, a[i] );
<a href="ntqapplication.html#qDebug">qDebug</a>( "1 is found %d times", a.<a href="#contains">contains</a>(1) );
<a href="ntqapplication.html#qDebug">qDebug</a>( "5 is found at index %d", a.<a href="#find">find</a>(5) );
return 0;
}
</pre>
<p> Program output:
<pre>
0: 1
1: 1
2: 2
3: 3
4: 5
5: 8
1 is found 2 times
5 is found at index 4
</pre>
<p> Note concerning the use of TQMemArray for manipulating structs or
classes: Compilers will often pad the size of structs of odd sizes
up to the nearest word boundary. This will then be the size
TQMemArray will use for its bitwise element comparisons. Because
the remaining bytes will typically be uninitialized, this can
cause <a href="#find">find</a>() etc. to fail to find the element. Example:
<p> <pre>
// MyStruct may be padded to 4 or 8 bytes
struct MyStruct
{
short i; // 2 bytes
char c; // 1 byte
};
TQMemArray<MyStruct> a(1);
a[0].i = 5;
a[0].c = 't';
MyStruct x;
x.i = '5';
x.c = 't';
int i = a.<a href="#find">find</a>( x ); // may return -1 if the pad bytes differ
</pre>
<p> To work around this, make sure that you use a struct where
sizeof() returns the same as the sum of the sizes of the members
either by changing the types of the struct members or by adding
dummy members.
<p> TQMemArray data can be traversed by iterators (see <a href="#begin">begin</a>() and
<a href="#end">end</a>()). The number of items is returned by <a href="#count">count</a>(). The array can
be resized with <a href="#resize">resize</a>() and filled using <a href="#fill">fill</a>().
<p> You can make a <a href="shclass.html#shallow-copy">shallow copy</a> of the array with <a href="#assign">assign</a>() (or
<a href="#operator-eq">operator=</a>()) and a <a href="shclass.html#deep-copy">deep copy</a> with <a href="#duplicate">duplicate</a>().
<p> Search for values in the array with <a href="#find">find</a>() and <a href="#contains">contains</a>(). For
sorted arrays (see <a href="#sort">sort</a>()) you can search using <a href="#bsearch">bsearch</a>().
<p> You can set the data directly using <a href="#setRawData">setRawData</a>() and
<a href="#resetRawData">resetRawData</a>(), although this requires care.
<p> <p>See also <a href="shclass.html">Shared Classes</a> and <a href="tools.html">Non-GUI Classes</a>.
<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="ConstIterator"></a>TQMemArray::ConstIterator</h3>
A const TQMemArray iterator.
<p>See also <a href="#begin">begin</a>() and <a href="#end">end</a>().
<h3 class=fn><a name="Iterator"></a>TQMemArray::Iterator</h3>
A TQMemArray iterator.
<p>See also <a href="#begin">begin</a>() and <a href="#end">end</a>().
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQMemArray"></a>TQMemArray::TQMemArray ( int, int )<tt> [protected]</tt>
</h3>
<p> Constructs an array <em>without allocating</em> array space. The
arguments should be (0, 0). Use at your own risk.
<h3 class=fn><a name="TQMemArray-2"></a>TQMemArray::TQMemArray ()
</h3>
<p> Constructs a null array.
<p> <p>See also <a href="#isNull">isNull</a>().
<h3 class=fn><a name="TQMemArray-3"></a>TQMemArray::TQMemArray ( int size )
</h3>
<p> Constructs an array with room for <em>size</em> elements. Makes a null
array if <em>size</em> == 0.
<p> The elements are left uninitialized.
<p> <p>See also <a href="#resize">resize</a>() and <a href="#isNull">isNull</a>().
<h3 class=fn><a name="TQMemArray-4"></a>TQMemArray::TQMemArray ( const <a href="ntqmemarray.html">TQMemArray</a><type> & a )
</h3>
<p> Constructs a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em>.
<p> <p>See also <a href="#assign">assign</a>().
<h3 class=fn><a name="~TQMemArray"></a>TQMemArray::~TQMemArray ()
</h3>
<p> Dereferences the array data and deletes it if this was the last
reference.
<h3 class=fn><a href="ntqmemarray.html">TQMemArray</a><type> & <a name="assign"></a>TQMemArray::assign ( const <a href="ntqmemarray.html">TQMemArray</a><type> & a )
</h3>
<p> <a href="shclass.html#shallow-copy">Shallow copy</a>. Dereferences the current array and references the
data contained in <em>a</em> instead. Returns a reference to this array.
<p> <p>See also <a href="#operator-eq">operator=</a>().
<h3 class=fn><a href="ntqmemarray.html">TQMemArray</a><type> & <a name="assign-2"></a>TQMemArray::assign ( const type * data, uint size )
</h3>
<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <a href="shclass.html#shallow-copy">Shallow copy</a>. Dereferences the current array and references the
array data <em>data</em>, which contains <em>size</em> elements. Returns a
reference to this array.
<p> Do not delete <em>data</em> later; TQMemArray will call free() on it
at the right time.
<h3 class=fn>type & <a name="at"></a>TQMemArray::at ( uint index ) const
</h3>
<p> Returns a reference to the element at position <em>index</em> in the array.
<p> This can be used to both read and set an element.
<p> <p>See also <a href="#operator[]">operator[]</a>().
<h3 class=fn><a href="ntqmemarray.html#Iterator">Iterator</a> <a name="begin"></a>TQMemArray::begin ()
</h3>
<p> Returns an iterator pointing at the beginning of this array. This
iterator can be used in the same way as the iterators of
<a href="ntqvaluelist.html">TQValueList</a> and <a href="ntqmap.html">TQMap</a>, for example.
<h3 class=fn><a href="ntqmemarray.html#ConstIterator">ConstIterator</a> <a name="begin-2"></a>TQMemArray::begin () const
</h3>
<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns a const iterator pointing at the beginning of this array.
This iterator can be used in the same way as the iterators of
<a href="ntqvaluelist.html">TQValueList</a> and <a href="ntqmap.html">TQMap</a>, for example.
<h3 class=fn>int <a name="bsearch"></a>TQMemArray::bsearch ( const type & v ) const
</h3>
<p> In a sorted array (as sorted by <a href="#sort">sort</a>()), finds the first
occurrence of <em>v</em> by using a binary search. For a sorted
array this is generally much faster than <a href="#find">find</a>(), which does
a linear search.
<p> Returns the position of <em>v</em>, or -1 if <em>v</em> could not be found.
<p> <p>See also <a href="#sort">sort</a>() and <a href="#find">find</a>().
<h3 class=fn>int <a name="contains"></a>TQMemArray::contains ( const type & v ) const
</h3>
<p> Returns the number of times <em>v</em> occurs in the array.
<p> <p>See also <a href="#find">find</a>().
<h3 class=fn><a href="ntqmemarray.html">TQMemArray</a><type> <a name="copy"></a>TQMemArray::copy () const
</h3>
<p> Returns a <a href="shclass.html#deep-copy">deep copy</a> of this array.
<p> <p>See also <a href="#detach">detach</a>() and <a href="#duplicate">duplicate</a>().
<h3 class=fn>uint <a name="count"></a>TQMemArray::count () const
</h3>
<p> Returns the same as <a href="#size">size</a>().
<p> <p>See also <a href="#size">size</a>().
<p>Example: <a href="scribble-example.html#x913">scribble/scribble.cpp</a>.
<h3 class=fn>type * <a name="data"></a>TQMemArray::data () const
</h3>
<p> Returns a pointer to the actual array data.
<p> The array is a null array if <a href="#data">data</a>() == 0 (null pointer).
<p> <p>See also <a href="#isNull">isNull</a>().
<p>Examples: <a href="fileiconview-example.html#x855">fileiconview/qfileiconview.cpp</a> and <a href="networkprotocol-example.html#x671">network/networkprotocol/nntp.cpp</a>.
<h3 class=fn>void <a name="detach"></a>TQMemArray::detach ()<tt> [virtual]</tt>
</h3>
<p> Detaches this array from shared array data; i.e. it makes a
private, <a href="shclass.html#deep-copy">deep copy</a> of the data.
<p> Copying will be performed only if the <a href="#nrefs">reference
count</a> is greater than one.
<p> <p>See also <a href="#copy">copy</a>().
<p>Reimplemented in <a href="ntqbitarray.html#detach">TQBitArray</a>.
<h3 class=fn><a href="ntqmemarray.html">TQMemArray</a><type> & <a name="duplicate"></a>TQMemArray::duplicate ( const <a href="ntqmemarray.html">TQMemArray</a><type> & a )
</h3>
<p> <a href="shclass.html#deep-copy">Deep copy</a>. Dereferences the current array and obtains a copy of
the data contained in <em>a</em> instead. Returns a reference to this
array.
<p> <p>See also <a href="#copy">copy</a>().
<h3 class=fn><a href="ntqmemarray.html">TQMemArray</a><type> & <a name="duplicate-2"></a>TQMemArray::duplicate ( const type * data, uint size )
</h3>
<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <a href="shclass.html#deep-copy">Deep copy</a>. Dereferences the current array and obtains a copy of
the array data <em>data</em> instead. Returns a reference to this array.
The size of the array is given by <em>size</em>.
<p> <p>See also <a href="#copy">copy</a>().
<h3 class=fn><a href="ntqmemarray.html#Iterator">Iterator</a> <a name="end"></a>TQMemArray::end ()
</h3>
<p> Returns an iterator pointing behind the last element of this
array. This iterator can be used in the same way as the iterators
of <a href="ntqvaluelist.html">TQValueList</a> and <a href="ntqmap.html">TQMap</a>, for example.
<h3 class=fn><a href="ntqmemarray.html#ConstIterator">ConstIterator</a> <a name="end-2"></a>TQMemArray::end () const
</h3>
<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns a const iterator pointing behind the last element of this
array. This iterator can be used in the same way as the iterators
of <a href="ntqvaluelist.html">TQValueList</a> and <a href="ntqmap.html">TQMap</a>, for example.
<h3 class=fn>bool <a name="fill"></a>TQMemArray::fill ( const type & v, int size = -1 )
</h3>
<p> Fills the array with the value <em>v</em>. If <em>size</em> is specified as
different from -1, then the array will be resized before being
filled.
<p> Returns TRUE if successful, i.e. if <em>size</em> is -1, or <em>size</em> is
!= -1 and the memory can be allocated; otherwise returns FALSE.
<p> <p>See also <a href="#resize">resize</a>().
<h3 class=fn>int <a name="find"></a>TQMemArray::find ( const type & v, uint index = 0 ) const
</h3>
<p> Finds the first occurrence of <em>v</em>, starting at position <em>index</em>.
<p> Returns the position of <em>v</em>, or -1 if <em>v</em> could not be found.
<p> <p>See also <a href="#contains">contains</a>().
<h3 class=fn>bool <a name="isEmpty"></a>TQMemArray::isEmpty () const
</h3>
<p> Returns TRUE if the array is empty; otherwise returns FALSE.
<p> <a href="#isEmpty">isEmpty</a>() is equivalent to <a href="#isNull">isNull</a>() for TQMemArray (unlike
<a href="ntqstring.html">TQString</a>).
<h3 class=fn>bool <a name="isNull"></a>TQMemArray::isNull () const
</h3>
<p> Returns TRUE if the array is null; otherwise returns FALSE.
<p> A null array has <a href="#size">size</a>() == 0 and <a href="#data">data</a>() == 0.
<h3 class=fn>uint <a name="nrefs"></a>TQMemArray::nrefs () const
</h3>
<p> Returns the reference count for the shared array data. This
reference count is always greater than zero.
<h3 class=fn><a name="operator-const-type-*"></a>TQMemArray::operator const type * () const
</h3>
<p> Cast operator. Returns a pointer to the array.
<p> <p>See also <a href="#data">data</a>().
<h3 class=fn>bool <a name="operator!-eq"></a>TQMemArray::operator!= ( const <a href="ntqmemarray.html">TQMemArray</a><type> & a ) const
</h3>
<p> Returns TRUE if this array is different from <em>a</em>; otherwise
returns FALSE.
<p> The two arrays are compared bitwise.
<p> <p>See also <a href="#operator-eq-eq">operator==</a>().
<h3 class=fn><a href="ntqmemarray.html">TQMemArray</a><type> & <a name="operator-eq"></a>TQMemArray::operator= ( const <a href="ntqmemarray.html">TQMemArray</a><type> & a )
</h3>
<p> Assigns a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em> to this array and returns a
reference to this array.
<p> Equivalent to <a href="#assign">assign</a>( a ).
<h3 class=fn>bool <a name="operator-eq-eq"></a>TQMemArray::operator== ( const <a href="ntqmemarray.html">TQMemArray</a><type> & a ) const
</h3>
<p> Returns TRUE if this array is equal to <em>a</em>; otherwise returns
FALSE.
<p> The two arrays are compared bitwise.
<p> <p>See also <a href="#operator!-eq">operator!=</a>().
<h3 class=fn>type & <a name="operator[]"></a>TQMemArray::operator[] ( int index ) const
</h3>
<p> Returns a reference to the element at position <em>index</em> in the
array.
<p> This can be used to both read and set an element. Equivalent to
<a href="#at">at</a>().
<p> <p>See also <a href="#at">at</a>().
<h3 class=fn>void <a name="resetRawData"></a>TQMemArray::resetRawData ( const type * data, uint size )
</h3>
<p> Removes internal references to the raw data that was set using
<a href="#setRawData">setRawData</a>(). This means that TQMemArray no longer has access to
the <em>data</em>, so you are free to manipulate <em>data</em> as you wish.
You can now use the TQMemArray without affecting the original <em>data</em>, for example by calling setRawData() with a pointer to some
other data.
<p> The arguments must be the <em>data</em> and length, <em>size</em>, that were
passed to setRawData(). This is for consistency checking.
<p> <p>See also <a href="#setRawData">setRawData</a>().
<h3 class=fn>bool <a name="resize"></a>TQMemArray::resize ( uint size, Optimization optim )
</h3>
<p> Resizes (expands or shrinks) the array to <em>size</em> elements. The
array becomes a null array if <em>size</em> == 0.
<p> Returns TRUE if successful, or FALSE if the memory cannot be
allocated.
<p> New elements are not initialized.
<p> <em>optim</em> is either <tt>TQGArray::MemOptim</tt> (the default) or
<tt>TQGArray::SpeedOptim</tt>.
<p> <b>Note:</b> By default, <tt>SpeedOptim</tt> is not available for general
use since it is only available if TQt is built in a particular
configuration.
<p> <p>See also <a href="#size">size</a>().
<p>Example: <a href="fileiconview-example.html#x856">fileiconview/qfileiconview.cpp</a>.
<h3 class=fn>bool <a name="resize-2"></a>TQMemArray::resize ( uint size )
</h3>
<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Resizes (expands or shrinks) the array to <em>size</em> elements. The
array becomes a null array if <em>size</em> == 0.
<p> Returns TRUE if successful, i.e. if the memory can be allocated;
otherwise returns FALSE.
<p> New elements are not initialized.
<p> <p>See also <a href="#size">size</a>().
<h3 class=fn><a href="ntqmemarray.html">TQMemArray</a><type> & <a name="setRawData"></a>TQMemArray::setRawData ( const type * data, uint size )
</h3>
<p> Sets raw data and returns a reference to the array.
<p> Dereferences the current array and sets the new array data to <em>data</em> and the new array size to <em>size</em>. Do not attempt to resize
or re-assign the array data when raw data has been set. Call
<a href="#resetRawData">resetRawData</a>(<em>data</em>, <em>size</em>) to reset the array.
<p> Setting raw data is useful because it sets TQMemArray data without
allocating memory or copying data.
<p> Example I (intended use):
<pre>
static char bindata[] = { 231, 1, 44, ... };
<a href="qbytearray.html">TQByteArray</a> a;
a.<a href="#setRawData">setRawData</a>( bindata, sizeof(bindata) ); // a points to bindata
<a href="ntqdatastream.html">TQDataStream</a> s( a, <a href="ntqfile.html#open">IO_ReadOnly</a> ); // open on a's data
s >> <something>; // read raw bindata
a.<a href="#resetRawData">resetRawData</a>( bindata, sizeof(bindata) ); // finished
</pre>
<p> Example II (you don't want to do this):
<pre>
static char bindata[] = { 231, 1, 44, ... };
<a href="qbytearray.html">TQByteArray</a> a, b;
a.<a href="#setRawData">setRawData</a>( bindata, sizeof(bindata) ); // a points to bindata
a.<a href="#resize">resize</a>( 8 ); // will crash
b = a; // will crash
a[2] = 123; // might crash
// forget to resetRawData: will crash
</pre>
<p> <b>Warning:</b> If you do not call <a href="#resetRawData">resetRawData</a>(), TQMemArray will attempt
to deallocate or reallocate the raw data, which might not be too
good. Be careful.
<p> <p>See also <a href="#resetRawData">resetRawData</a>().
<h3 class=fn>uint <a name="size"></a>TQMemArray::size () const
</h3>
<p> Returns the size of the array (maximum number of elements).
<p> The array is a null array if <a href="#size">size</a>() == 0.
<p> <p>See also <a href="#isNull">isNull</a>() and <a href="#resize">resize</a>().
<h3 class=fn>void <a name="sort"></a>TQMemArray::sort ()
</h3>
<p> Sorts the array elements in ascending order, using bitwise
comparison (memcmp()).
<p> <p>See also <a href="#bsearch">bsearch</a>().
<h3 class=fn>bool <a name="truncate"></a>TQMemArray::truncate ( uint pos )
</h3>
<p> Truncates the array at position <em>pos</em>.
<p> Returns TRUE if successful, i.e. if the memory can be allocated;
otherwise returns FALSE.
<p> Equivalent to <a href="#resize">resize</a>(<em>pos</em>).
<p> <p>See also <a href="#resize">resize</a>().
<hr><h2>Related Functions</h2>
<h3 class=fn><a href="ntqdatastream.html">TQDataStream</a> & <a name="operator-lt-lt"></a>operator<< ( <a href="ntqdatastream.html">TQDataStream</a> & s, const <a href="qbytearray.html">TQByteArray</a> & a )
</h3>
<p> Writes byte array <em>a</em> to the stream <em>s</em> and returns a reference
to the stream.
<p> <p>See also <a href="datastreamformat.html">Format of the TQDataStream operators</a>.
<h3 class=fn><a href="ntqdatastream.html">TQDataStream</a> & <a name="operator-gt-gt"></a>operator>> ( <a href="ntqdatastream.html">TQDataStream</a> & s, <a href="qbytearray.html">TQByteArray</a> & a )
</h3>
<p> Reads a byte array into <em>a</em> from the stream <em>s</em> and returns a
reference to the stream.
<p> <p>See also <a href="datastreamformat.html">Format of the TQDataStream operators</a>.
<h3 class=fn>Q_UINT16 <a name="qChecksum"></a>qChecksum ( const char * data, uint len )
</h3>
<p> Returns the CRC-16 checksum of <em>len</em> bytes starting at <em>data</em>.
<p> The checksum is independent of the byte order (endianness).
<!-- 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>
|