~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/q3memarray.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/doc/src/q3memarray.qdoc -->
 
6
<head>
 
7
    <title>Qt 4.0: Q3MemArray Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">Q3MemArray Class Reference</h1>
 
21
<p>The Q3MemArray class is a template class that provides arrays of simple types. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;Q3MemArray&gt;</pre><p><b>This class is part of the Qt 3 support library.</b> It is provided to keep old source code working. We strongly advise against using it in new code. See the <a href="porting4.html">Porting Guide</a> for more information.</p>
 
23
<p>Part of the <a href="qt3support.html">Qt3Support</a> module.</p>
 
24
<ul>
 
25
<li><a href="q3memarray-members.html">List of all members, including inherited members</a></li>
 
26
</ul>
 
27
<a name="public-types"></a>
 
28
<h3>Public Types</h3>
 
29
<ul>
 
30
<li><div class="fn"/>typedef <b><a href="q3memarray.html#ConstIterator-typedef">ConstIterator</a></b></li>
 
31
<li><div class="fn"/>typedef <b><a href="q3memarray.html#Iterator-typedef">Iterator</a></b></li>
 
32
</ul>
 
33
<a name="public-functions"></a>
 
34
<h3>Public Functions</h3>
 
35
<ul>
 
36
<li><div class="fn"/><b><a href="q3memarray.html#Q3MemArray-2">Q3MemArray</a></b> ()</li>
 
37
<li><div class="fn"/><b><a href="q3memarray.html#Q3MemArray-3">Q3MemArray</a></b> ( int <i>size</i> )</li>
 
38
<li><div class="fn"/><b><a href="q3memarray.html#Q3MemArray-4">Q3MemArray</a></b> ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</li>
 
39
<li><div class="fn"/><b><a href="q3memarray.html#Q3MemArray-5">Q3MemArray</a></b> ( const QVector&lt;type&gt; &amp; <i>vector</i> )</li>
 
40
<li><div class="fn"/><b><a href="q3memarray.html#dtor.Q3MemArray">~Q3MemArray</a></b> ()</li>
 
41
<li><div class="fn"/>Q3MemArray&lt;type&gt; &amp; <b><a href="q3memarray.html#assign">assign</a></b> ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</li>
 
42
<li><div class="fn"/>Q3MemArray&lt;type&gt; &amp; <b><a href="q3memarray.html#assign-2">assign</a></b> ( const type * <i>data</i>, uint <i>size</i> )</li>
 
43
<li><div class="fn"/>type &amp; <b><a href="q3memarray.html#at">at</a></b> ( uint <i>index</i> ) const</li>
 
44
<li><div class="fn"/>Iterator <b><a href="q3memarray.html#begin">begin</a></b> ()</li>
 
45
<li><div class="fn"/>ConstIterator <b><a href="q3memarray.html#begin-2">begin</a></b> () const</li>
 
46
<li><div class="fn"/>int <b><a href="q3memarray.html#bsearch">bsearch</a></b> ( const type &amp; <i>v</i> ) const</li>
 
47
<li><div class="fn"/>int <b><a href="q3memarray.html#contains">contains</a></b> ( const type &amp; <i>v</i> ) const</li>
 
48
<li><div class="fn"/>Q3MemArray&lt;type&gt; <b><a href="q3memarray.html#copy">copy</a></b> () const</li>
 
49
<li><div class="fn"/>uint <b><a href="q3memarray.html#count">count</a></b> () const</li>
 
50
<li><div class="fn"/>type * <b><a href="q3memarray.html#data">data</a></b> () const</li>
 
51
<li><div class="fn"/>virtual void <b><a href="q3memarray.html#detach">detach</a></b> ()</li>
 
52
<li><div class="fn"/>Q3MemArray&lt;type&gt; &amp; <b><a href="q3memarray.html#duplicate">duplicate</a></b> ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</li>
 
53
<li><div class="fn"/>Q3MemArray&lt;type&gt; &amp; <b><a href="q3memarray.html#duplicate-2">duplicate</a></b> ( const type * <i>data</i>, uint <i>size</i> )</li>
 
54
<li><div class="fn"/>Iterator <b><a href="q3memarray.html#end">end</a></b> ()</li>
 
55
<li><div class="fn"/>ConstIterator <b><a href="q3memarray.html#end-2">end</a></b> () const</li>
 
56
<li><div class="fn"/>bool <b><a href="q3memarray.html#fill">fill</a></b> ( const type &amp; <i>v</i>, int <i>size</i> = -1 )</li>
 
57
<li><div class="fn"/>int <b><a href="q3memarray.html#find">find</a></b> ( const type &amp; <i>v</i>, uint <i>index</i> = 0 ) const</li>
 
58
<li><div class="fn"/>bool <b><a href="q3memarray.html#isEmpty">isEmpty</a></b> () const</li>
 
59
<li><div class="fn"/>bool <b><a href="q3memarray.html#isNull">isNull</a></b> () const</li>
 
60
<li><div class="fn"/>uint <b><a href="q3memarray.html#nrefs">nrefs</a></b> () const</li>
 
61
<li><div class="fn"/>void <b><a href="q3memarray.html#resetRawData">resetRawData</a></b> ( const type * <i>data</i>, uint <i>size</i> )</li>
 
62
<li><div class="fn"/>bool <b><a href="q3memarray.html#resize">resize</a></b> ( uint <i>size</i>, Optimization <i>optim</i> )</li>
 
63
<li><div class="fn"/>bool <b><a href="q3memarray.html#resize-2">resize</a></b> ( uint <i>size</i> )</li>
 
64
<li><div class="fn"/>Q3MemArray&lt;type&gt; &amp; <b><a href="q3memarray.html#setRawData">setRawData</a></b> ( const type * <i>data</i>, uint <i>size</i> )</li>
 
65
<li><div class="fn"/>uint <b><a href="q3memarray.html#size">size</a></b> () const</li>
 
66
<li><div class="fn"/>void <b><a href="q3memarray.html#sort">sort</a></b> ()</li>
 
67
<li><div class="fn"/>bool <b><a href="q3memarray.html#truncate">truncate</a></b> ( uint <i>pos</i> )</li>
 
68
<li><div class="fn"/><b><a href="q3memarray.html#operator-QVector-lttype-gt">operator QVector&lt;type&gt;</a></b> () const</li>
 
69
<li><div class="fn"/><b><a href="q3memarray.html#operator-const-type--2a">operator const type *</a></b> () const</li>
 
70
<li><div class="fn"/>bool <b><a href="q3memarray.html#operator-not-eq">operator!=</a></b> ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> ) const</li>
 
71
<li><div class="fn"/>Q3MemArray&lt;type&gt; &amp; <b><a href="q3memarray.html#operator-eq">operator=</a></b> ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</li>
 
72
<li><div class="fn"/>bool <b><a href="q3memarray.html#operator-eq-eq">operator==</a></b> ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> ) const</li>
 
73
<li><div class="fn"/>type &amp; <b><a href="q3memarray.html#operator-5b-5d">operator[]</a></b> ( int <i>index</i> ) const</li>
 
74
</ul>
 
75
<a name="protected-functions"></a>
 
76
<h3>Protected Functions</h3>
 
77
<ul>
 
78
<li><div class="fn"/><b><a href="q3memarray.html#Q3MemArray">Q3MemArray</a></b> ( int <i>arg1</i>, int <i>arg2</i> )</li>
 
79
</ul>
 
80
<a name="details"></a>
 
81
<hr />
 
82
<h2>Detailed Description</h2>
 
83
<p>The Q3MemArray class is a template class that provides arrays of simple types.</p>
 
84
<p>Q3MemArray is implemented as a template class. Define a template instance Q3MemArray&lt;X&gt; to create an array that contains X items.</p>
 
85
<p>Q3MemArray 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). Q3MemArray uses bitwise operations to copy and compare array elements.</p>
 
86
<p>The <a href="q3ptrvector.html">Q3PtrVector</a> collection class is also a kind of array. Like most old Qt collection classes, it uses pointers to the contained items.</p>
 
87
<p>Q3MemArray uses explicit sharing 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>
 
88
<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>
 
89
<p>Example:</p>
 
90
<pre>&nbsp;   #include &lt;qmemarray.h&gt;
 
91
    #include &lt;stdio.h&gt;
 
92
 
 
93
    Q3MemArray&lt;int&gt; fib( int num ) // returns fibonacci array
 
94
    {
 
95
        Q_ASSERT( num &gt; 2 );
 
96
        Q3MemArray&lt;int&gt; f( num ); // array of ints
 
97
 
 
98
        f[0] = f[1] = 1;
 
99
        for ( int i = 2; i &lt; num; i++ )
 
100
            f[i] = f[i-1] + f[i-2];
 
101
 
 
102
        return f;
 
103
    }
 
104
 
 
105
    int main()
 
106
    {
 
107
        Q3MemArray&lt;int&gt; a = fib( 6 ); // get first 6 fibonaccis
 
108
        for ( int i = 0; i &lt; a.size(); i++ )
 
109
            qDebug( &quot;%d: %d&quot;, i, a[i] );
 
110
 
 
111
        qDebug( &quot;1 is found %d times&quot;, a.contains(1) );
 
112
        qDebug( &quot;5 is found at index %d&quot;, a.find(5) );
 
113
 
 
114
        return 0;
 
115
    }</pre>
 
116
<p>Program output:</p>
 
117
<pre>&nbsp;   0: 1
 
118
    1: 1
 
119
    2: 2
 
120
    3: 3
 
121
    4: 5
 
122
    5: 8
 
123
    1 is found 2 times
 
124
    5 is found at index 4</pre>
 
125
<p>Note concerning the use of Q3MemArray 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 Q3MemArray will use for its bitwise element comparisons. Because the remaining bytes will typically be uninitialized, this can cause <a href="q3memarray.html#find">find</a>() etc. to fail to find the element. Example:</p>
 
126
<pre>&nbsp;   // MyStruct may be padded to 4 or 8 bytes
 
127
    struct MyStruct
 
128
    {
 
129
        short i; // 2 bytes
 
130
        char c;  // 1 byte
 
131
    };
 
132
 
 
133
    Q3MemArray&lt;MyStruct&gt; a(1);
 
134
    a[0].i = 5;
 
135
    a[0].c = 't';
 
136
 
 
137
    MyStruct x;
 
138
    x.i = '5';
 
139
    x.c = 't';
 
140
    int i = a.find( x ); // may return -1 if the pad bytes differ</pre>
 
141
<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>
 
142
<p>Q3MemArray data can be traversed by iterators (see <a href="q3memarray.html#begin">begin</a>() and <a href="q3memarray.html#end">end</a>()). The number of items is returned by <a href="q3memarray.html#count">count</a>(). The array can be resized with <a href="q3memarray.html#resize">resize</a>() and filled using <a href="q3memarray.html#fill">fill</a>().</p>
 
143
<p>You can make a shallow copy of the array with <a href="q3memarray.html#assign">assign</a>() (or operator=()) and a deep copy with <a href="q3memarray.html#duplicate">duplicate</a>().</p>
 
144
<p>Search for values in the array with <a href="q3memarray.html#find">find</a>() and <a href="q3memarray.html#contains">contains</a>(). For sorted arrays (see <a href="q3memarray.html#sort">sort</a>()) you can search using <a href="q3memarray.html#bsearch">bsearch</a>().</p>
 
145
<p>You can set the data directly using <a href="q3memarray.html#setRawData">setRawData</a>() and <a href="q3memarray.html#resetRawData">resetRawData</a>(), although this requires care.</p>
 
146
<hr />
 
147
<h2>Member Type Documentation</h2>
 
148
<h3 class="fn"><a name="ConstIterator-typedef"></a>typedef Q3MemArray::ConstIterator</h3>
 
149
<p>A const <a href="q3memarray.html">Q3MemArray</a> iterator.</p>
 
150
<p>See also <a href="q3memarray.html#begin">begin</a>() and <a href="q3memarray.html#end">end</a>().</p>
 
151
<h3 class="fn"><a name="Iterator-typedef"></a>typedef Q3MemArray::Iterator</h3>
 
152
<p>A <a href="q3memarray.html">Q3MemArray</a> iterator.</p>
 
153
<p>See also <a href="q3memarray.html#begin">begin</a>() and <a href="q3memarray.html#end">end</a>().</p>
 
154
<hr />
 
155
<h2>Member Function Documentation</h2>
 
156
<h3 class="fn"><a name="Q3MemArray"></a>Q3MemArray::Q3MemArray ( int <i>arg1</i>, int <i>arg2</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
 
157
<p>Constructs an array <i>without allocating</i> array space. The arguments <i>arg1</i> and <i>arg2</i> should be zero. Use at your own risk.</p>
 
158
<h3 class="fn"><a name="Q3MemArray-2"></a>Q3MemArray::Q3MemArray ()</h3>
 
159
<p>Constructs a null array.</p>
 
160
<p>See also <a href="q3memarray.html#isNull">isNull</a>().</p>
 
161
<h3 class="fn"><a name="Q3MemArray-3"></a>Q3MemArray::Q3MemArray ( int <i>size</i> )</h3>
 
162
<p>Constructs an array with room for <i>size</i> elements. Makes a null array if <i>size</i> == 0.</p>
 
163
<p>The elements are left uninitialized.</p>
 
164
<p>See also <a href="q3memarray.html#resize">resize</a>() and <a href="q3memarray.html#isNull">isNull</a>().</p>
 
165
<h3 class="fn"><a name="Q3MemArray-4"></a>Q3MemArray::Q3MemArray ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</h3>
 
166
<p>Constructs a shallow copy of <i>a</i>.</p>
 
167
<p>See also <a href="q3memarray.html#assign">assign</a>().</p>
 
168
<h3 class="fn"><a name="Q3MemArray-5"></a>Q3MemArray::Q3MemArray ( const <a href="qvector.html">QVector</a>&lt;type&gt; &amp; <i>vector</i> )</h3>
 
169
<p>Constructs a copy of <i>vector</i>.</p>
 
170
<h3 class="fn"><a name="dtor.Q3MemArray"></a>Q3MemArray::~Q3MemArray ()</h3>
 
171
<p>Dereferences the array data and deletes it if this was the last reference.</p>
 
172
<h3 class="fn"><a name="assign"></a>Q3MemArray&lt;type&gt; &amp; Q3MemArray::assign ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</h3>
 
173
<p>Shallow copy. Dereferences the current array and references the data contained in <i>a</i> instead. Returns a reference to this array.</p>
 
174
<p>See also <a href="q3memarray.html#operator-eq">operator=</a>().</p>
 
175
<h3 class="fn"><a name="assign-2"></a>Q3MemArray&lt;type&gt; &amp; Q3MemArray::assign ( const type * <i>data</i>, <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )</h3>
 
176
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
177
<p>Shallow copy. Dereferences the current array and references the array data <i>data</i>, which contains <i>size</i> elements. Returns a reference to this array.</p>
 
178
<p>Do not delete <i>data</i> later; <a href="q3memarray.html">Q3MemArray</a> will call free() on it at the right time.</p>
 
179
<h3 class="fn"><a name="at"></a>type &amp; Q3MemArray::at ( <a href="qtglobal.html#uint-typedef">uint</a> <i>index</i> ) const</h3>
 
180
<p>Returns a reference to the element at position <i>index</i> in the array.</p>
 
181
<p>This can be used to both read and set an element.</p>
 
182
<p>See also <a href="q3memarray.html#operator-5b-5d">operator[]</a>().</p>
 
183
<h3 class="fn"><a name="begin"></a><a href="q3memarray.html#Iterator-typedef">Iterator</a> Q3MemArray::begin ()</h3>
 
184
<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="q3valuelist.html">Q3ValueList</a> and <a href="qmap.html">QMap</a>, for example.</p>
 
185
<h3 class="fn"><a name="begin-2"></a><a href="q3memarray.html#ConstIterator-typedef">ConstIterator</a> Q3MemArray::begin () const</h3>
 
186
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
187
<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="q3valuelist.html">Q3ValueList</a> and <a href="qmap.html">QMap</a>, for example.</p>
 
188
<h3 class="fn"><a name="bsearch"></a>int Q3MemArray::bsearch ( const type &amp; <i>v</i> ) const</h3>
 
189
<p>In a sorted array (as sorted by <a href="q3memarray.html#sort">sort</a>()), finds the first occurrence of <i>v</i> by using a binary search. For a sorted array this is generally much faster than <a href="q3memarray.html#find">find</a>(), which does a linear search.</p>
 
190
<p>Returns the position of <i>v</i>, or -1 if <i>v</i> could not be found.</p>
 
191
<p>See also <a href="q3memarray.html#sort">sort</a>() and <a href="q3memarray.html#find">find</a>().</p>
 
192
<h3 class="fn"><a name="contains"></a>int Q3MemArray::contains ( const type &amp; <i>v</i> ) const</h3>
 
193
<p>Returns the number of times <i>v</i> occurs in the array.</p>
 
194
<p>See also <a href="q3memarray.html#find">find</a>().</p>
 
195
<h3 class="fn"><a name="copy"></a>Q3MemArray&lt;type&gt; Q3MemArray::copy () const</h3>
 
196
<p>Returns a deep copy of this array.</p>
 
197
<p>See also <a href="q3memarray.html#detach">detach</a>() and <a href="q3memarray.html#duplicate">duplicate</a>().</p>
 
198
<h3 class="fn"><a name="count"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3MemArray::count () const</h3>
 
199
<p>Returns the same as <a href="q3memarray.html#size">size</a>().</p>
 
200
<p>See also <a href="q3memarray.html#size">size</a>().</p>
 
201
<h3 class="fn"><a name="data"></a>type * Q3MemArray::data () const</h3>
 
202
<p>Returns a pointer to the actual array data.</p>
 
203
<p>The array is a null array if data() == 0 (null pointer).</p>
 
204
<p>See also <a href="q3memarray.html#isNull">isNull</a>().</p>
 
205
<h3 class="fn"><a name="detach"></a>void Q3MemArray::detach ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
206
<p>Detaches this array from shared array data; i.e. it makes a private, deep copy of the data.</p>
 
207
<p>Copying will be performed only if the <a href="q3memarray.html#nrefs">reference count</a> is greater than one.</p>
 
208
<p>Reimplemented from <a href="q3garray.html#detach">Q3GArray</a>.</p>
 
209
<p>See also <a href="q3memarray.html#copy">copy</a>().</p>
 
210
<h3 class="fn"><a name="duplicate"></a>Q3MemArray&lt;type&gt; &amp; Q3MemArray::duplicate ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</h3>
 
211
<p>Deep copy. Dereferences the current array and obtains a copy of the data contained in <i>a</i> instead. Returns a reference to this array.</p>
 
212
<p>See also <a href="q3memarray.html#copy">copy</a>().</p>
 
213
<h3 class="fn"><a name="duplicate-2"></a>Q3MemArray&lt;type&gt; &amp; Q3MemArray::duplicate ( const type * <i>data</i>, <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )</h3>
 
214
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
215
<p>Deep copy. Dereferences the current array and obtains a copy of the array data <i>data</i> instead. Returns a reference to this array. The size of the array is given by <i>size</i>.</p>
 
216
<p>See also <a href="q3memarray.html#copy">copy</a>().</p>
 
217
<h3 class="fn"><a name="end"></a><a href="q3memarray.html#Iterator-typedef">Iterator</a> Q3MemArray::end ()</h3>
 
218
<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="q3valuelist.html">Q3ValueList</a> and <a href="qmap.html">QMap</a>, for example.</p>
 
219
<h3 class="fn"><a name="end-2"></a><a href="q3memarray.html#ConstIterator-typedef">ConstIterator</a> Q3MemArray::end () const</h3>
 
220
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
221
<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="q3valuelist.html">Q3ValueList</a> and <a href="qmap.html">QMap</a>, for example.</p>
 
222
<h3 class="fn"><a name="fill"></a>bool Q3MemArray::fill ( const type &amp; <i>v</i>, int <i>size</i> = -1 )</h3>
 
223
<p>Fills the array with the value <i>v</i>. If <i>size</i> is specified as different from -1, then the array will be resized before being filled.</p>
 
224
<p>Returns TRUE if successful, i.e. if <i>size</i> is -1, or <i>size</i> is != -1 and the memory can be allocated; otherwise returns FALSE.</p>
 
225
<p>See also <a href="q3memarray.html#resize">resize</a>().</p>
 
226
<h3 class="fn"><a name="find"></a>int Q3MemArray::find ( const type &amp; <i>v</i>, <a href="qtglobal.html#uint-typedef">uint</a> <i>index</i> = 0 ) const</h3>
 
227
<p>Finds the first occurrence of <i>v</i>, starting at position <i>index</i>.</p>
 
228
<p>Returns the position of <i>v</i>, or -1 if <i>v</i> could not be found.</p>
 
229
<p>See also <a href="q3memarray.html#contains">contains</a>().</p>
 
230
<h3 class="fn"><a name="isEmpty"></a>bool Q3MemArray::isEmpty () const</h3>
 
231
<p>Returns TRUE if the array is empty; otherwise returns FALSE.</p>
 
232
<p>isEmpty() is equivalent to <a href="q3memarray.html#isNull">isNull</a>() for <a href="q3memarray.html">Q3MemArray</a> (unlike <a href="qstring.html">QString</a>).</p>
 
233
<h3 class="fn"><a name="isNull"></a>bool Q3MemArray::isNull () const</h3>
 
234
<p>Returns TRUE if the array is null; otherwise returns FALSE.</p>
 
235
<p>A null array has <a href="q3memarray.html#size">size</a>() == 0 and <a href="q3memarray.html#data">data</a>() == 0.</p>
 
236
<h3 class="fn"><a name="nrefs"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3MemArray::nrefs () const</h3>
 
237
<p>Returns the reference count for the shared array data. This reference count is always greater than zero.</p>
 
238
<h3 class="fn"><a name="resetRawData"></a>void Q3MemArray::resetRawData ( const type * <i>data</i>, <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )</h3>
 
239
<p>Removes internal references to the raw data that was set using <a href="q3memarray.html#setRawData">setRawData</a>(). This means that <a href="q3memarray.html">Q3MemArray</a> no longer has access to the <i>data</i>, so you are free to manipulate <i>data</i> as you wish. You can now use the <a href="q3memarray.html">Q3MemArray</a> without affecting the original <i>data</i>, for example by calling <a href="q3memarray.html#setRawData">setRawData</a>() with a pointer to some other data.</p>
 
240
<p>The arguments must be the <i>data</i> and length, <i>size</i>, that were passed to <a href="q3memarray.html#setRawData">setRawData</a>(). This is for consistency checking.</p>
 
241
<p>See also <a href="q3memarray.html#setRawData">setRawData</a>().</p>
 
242
<h3 class="fn"><a name="resize"></a>bool Q3MemArray::resize ( <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i>, Optimization <i>optim</i> )</h3>
 
243
<p>Resizes (expands or shrinks) the array to <i>size</i> elements. The array becomes a null array if <i>size</i> == 0.</p>
 
244
<p>Returns TRUE if successful, or FALSE if the memory cannot be allocated.</p>
 
245
<p>New elements are not initialized.</p>
 
246
<p><i>optim</i> is either <a href="q3garray.html#Optimization-enum">Q3GArray::MemOptim</a> (the default) or <a href="q3garray.html#Optimization-enum">Q3GArray::SpeedOptim</a>. When optimizing for speed rather than memory consumption, the array uses a smart grow and shrink algorithm that might allocate more memory than is actually needed for <i>size</i> elements. This speeds up subsequent resize operations, for example when appending many elements to an array, since the space has already been allocated.</p>
 
247
<p>See also <a href="q3memarray.html#size">size</a>().</p>
 
248
<h3 class="fn"><a name="resize-2"></a>bool Q3MemArray::resize ( <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )</h3>
 
249
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
250
<p>Resizes (expands or shrinks) the array to <i>size</i> elements. The array becomes a null array if <i>size</i> == 0.</p>
 
251
<p>Returns TRUE if successful, i.e. if the memory can be allocated; otherwise returns FALSE.</p>
 
252
<p>New elements are not initialized.</p>
 
253
<p>See also <a href="q3memarray.html#size">size</a>().</p>
 
254
<h3 class="fn"><a name="setRawData"></a>Q3MemArray&lt;type&gt; &amp; Q3MemArray::setRawData ( const type * <i>data</i>, <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )</h3>
 
255
<p>Sets raw data and returns a reference to the array.</p>
 
256
<p>Dereferences the current array and sets the new array data to <i>data</i> and the new array size to <i>size</i>. Do not attempt to resize or re-assign the array data when raw data has been set. Call resetRawData(<i>data</i>, <i>size</i>) to reset the array.</p>
 
257
<p>Setting raw data is useful because it sets <a href="q3memarray.html">Q3MemArray</a> data without allocating memory or copying data.</p>
 
258
<p>Example I (intended use):</p>
 
259
<pre>&nbsp;   static char bindata[] = { 231, 1, 44, ... };
 
260
    QByteArray  a;
 
261
    a.setRawData( bindata, sizeof(bindata) );   // a points to bindata
 
262
    QDataStream s( a, IO_ReadOnly );            // open on a's data
 
263
    s &gt;&gt; &lt;something&gt;;                           // read raw bindata
 
264
    a.resetRawData( bindata, sizeof(bindata) ); // finished</pre>
 
265
<p>Example II (you don't want to do this):</p>
 
266
<pre>&nbsp;   static char bindata[] = { 231, 1, 44, ... };
 
267
    QByteArray  a, b;
 
268
    a.setRawData( bindata, sizeof(bindata) );   // a points to bindata
 
269
    a.resize( 8 );                              // will crash
 
270
    b = a;                                      // will crash
 
271
    a[2] = 123;                                 // might crash
 
272
    // forget to resetRawData: will crash</pre>
 
273
<p><b>Warning:</b> If you do not call <a href="q3memarray.html#resetRawData">resetRawData</a>(), <a href="q3memarray.html">Q3MemArray</a> will attempt to deallocate or reallocate the raw data, which might not be too good. Be careful.</p>
 
274
<p>See also <a href="q3memarray.html#resetRawData">resetRawData</a>().</p>
 
275
<h3 class="fn"><a name="size"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3MemArray::size () const</h3>
 
276
<p>Returns the size of the array (maximum number of elements).</p>
 
277
<p>The array is a null array if size() == 0.</p>
 
278
<p>See also <a href="q3memarray.html#isNull">isNull</a>() and <a href="q3memarray.html#resize">resize</a>().</p>
 
279
<h3 class="fn"><a name="sort"></a>void Q3MemArray::sort ()</h3>
 
280
<p>Sorts the array elements in ascending order, using bitwise comparison (memcmp()).</p>
 
281
<p>See also <a href="q3memarray.html#bsearch">bsearch</a>().</p>
 
282
<h3 class="fn"><a name="truncate"></a>bool Q3MemArray::truncate ( <a href="qtglobal.html#uint-typedef">uint</a> <i>pos</i> )</h3>
 
283
<p>Truncates the array at position <i>pos</i>.</p>
 
284
<p>Returns TRUE if successful, i.e. if the memory can be allocated; otherwise returns FALSE.</p>
 
285
<p>Equivalent to resize(<i>pos</i>).</p>
 
286
<p>See also <a href="q3memarray.html#resize">resize</a>().</p>
 
287
<h3 class="fn"><a name="operator-QVector-lttype-gt"></a>Q3MemArray::operator QVector&lt;type&gt; () const</h3>
 
288
<p>Automatically converts the <a href="q3memarray.html">Q3MemArray</a>&lt;type&gt; into a <a href="qvector.html">QVector</a>&lt;type&gt;.</p>
 
289
<h3 class="fn"><a name="operator-const-type--2a"></a>Q3MemArray::operator const type * () const</h3>
 
290
<p>Cast operator. Returns a pointer to the array.</p>
 
291
<p>See also <a href="q3memarray.html#data">data</a>().</p>
 
292
<h3 class="fn"><a name="operator-not-eq"></a>bool Q3MemArray::operator!= ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> ) const</h3>
 
293
<p>Returns TRUE if this array is different from <i>a</i>; otherwise returns FALSE.</p>
 
294
<p>The two arrays are compared bitwise.</p>
 
295
<p>See also <a href="q3memarray.html#operator-eq-eq">operator==</a>().</p>
 
296
<h3 class="fn"><a name="operator-eq"></a>Q3MemArray&lt;type&gt; &amp; Q3MemArray::operator= ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> )</h3>
 
297
<p>Assigns a shallow copy of <i>a</i> to this array and returns a reference to this array.</p>
 
298
<p>Equivalent to assign( a ).</p>
 
299
<h3 class="fn"><a name="operator-eq-eq"></a>bool Q3MemArray::operator== ( const Q3MemArray&lt;type&gt; &amp; <i>a</i> ) const</h3>
 
300
<p>Returns TRUE if this array is equal to <i>a</i>; otherwise returns FALSE.</p>
 
301
<p>The two arrays are compared bitwise.</p>
 
302
<p>See also <a href="q3memarray.html#operator-not-eq">operator!=</a>().</p>
 
303
<h3 class="fn"><a name="operator-5b-5d"></a>type &amp; Q3MemArray::operator[] ( int <i>index</i> ) const</h3>
 
304
<p>Returns a reference to the element at position <i>index</i> in the array.</p>
 
305
<p>This can be used to both read and set an element. Equivalent to <a href="q3memarray.html#at">at</a>().</p>
 
306
<p>See also <a href="q3memarray.html#at">at</a>().</p>
 
307
<p /><address><hr /><div align="center">
 
308
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
309
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
310
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
311
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
312
</tr></table></div></address></body>
 
313
</html>