source: trunk/doc/html/qbitarray.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 17.2 KB
Line 
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/src/tools/qbitarray.cpp:83 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QBitArray Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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>QBitArray Class Reference</h1>
33
34<p>The QBitArray class provides an array of bits.
35<a href="#details">More...</a>
36<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
37<p><tt>#include &lt;<a href="qbitarray-h.html">qbitarray.h</a>&gt;</tt>
38<p>Inherits <a href="qbytearray.html">QByteArray</a>.
39<p><a href="qbitarray-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn><a href="#QBitArray"><b>QBitArray</b></a> ()</li>
43<li class=fn><a href="#QBitArray-2"><b>QBitArray</b></a> ( uint&nbsp;size )</li>
44<li class=fn><a href="#QBitArray-3"><b>QBitArray</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</li>
45<li class=fn>QBitArray &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</li>
46<li class=fn>uint <a href="#size"><b>size</b></a> () const</li>
47<li class=fn>bool <a href="#resize"><b>resize</b></a> ( uint&nbsp;size )</li>
48<li class=fn>bool <a href="#fill"><b>fill</b></a> ( bool&nbsp;v, int&nbsp;size = -1 )</li>
49<li class=fn>virtual void <a href="#detach"><b>detach</b></a> ()</li>
50<li class=fn>QBitArray <a href="#copy"><b>copy</b></a> () const</li>
51<li class=fn>bool <a href="#testBit"><b>testBit</b></a> ( uint&nbsp;index ) const</li>
52<li class=fn>void <a href="#setBit-2"><b>setBit</b></a> ( uint&nbsp;index )</li>
53<li class=fn>void <a href="#setBit"><b>setBit</b></a> ( uint&nbsp;index, bool&nbsp;value )</li>
54<li class=fn>void <a href="#clearBit"><b>clearBit</b></a> ( uint&nbsp;index )</li>
55<li class=fn>bool <a href="#toggleBit"><b>toggleBit</b></a> ( uint&nbsp;index )</li>
56<li class=fn>bool <a href="#at"><b>at</b></a> ( uint&nbsp;index ) const</li>
57<li class=fn>QBitVal <a href="#operator[]"><b>operator[]</b></a> ( int&nbsp;index )</li>
58<li class=fn>bool <a href="#operator[]-2"><b>operator[]</b></a> ( int&nbsp;index ) const</li>
59<li class=fn>QBitArray &amp; <a href="#operator-and-eq"><b>operator&amp;=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</li>
60<li class=fn>QBitArray &amp; <a href="#operator|-eq"><b>operator|=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</li>
61<li class=fn>QBitArray &amp; <a href="#operator^-eq"><b>operator^=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</li>
62<li class=fn>QBitArray <a href="#operator~"><b>operator~</b></a> () const</li>
63</ul>
64<h2>Related Functions</h2>
65<ul>
66<li class=fn>QBitArray <a href="#operator-and"><b>operator&amp;</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a1, const&nbsp;QBitArray&nbsp;&amp;&nbsp;a2 )</li>
67<li class=fn>QBitArray <a href="#operator|"><b>operator|</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a1, const&nbsp;QBitArray&nbsp;&amp;&nbsp;a2 )</li>
68<li class=fn>QBitArray <a href="#operator^"><b>operator^</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a1, const&nbsp;QBitArray&nbsp;&amp;&nbsp;a2 )</li>
69<li class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</li>
70<li class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QBitArray&nbsp;&amp;&nbsp;a )</li>
71</ul>
72<hr><a name="details"></a><h2>Detailed Description</h2>
73
74
75
76The QBitArray class provides an array of bits.
77<p>
78
79
80<p> Because QBitArray is a <a href="qmemarray.html">QMemArray</a>, it uses explicit <a href="shclass.html">sharing</a> with a reference count.
81<p> A QBitArray is a special byte array that can access individual
82bits and perform bit-operations (AND, OR, XOR and NOT) on entire
83arrays or bits.
84<p> Bits can be manipulated by the <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>() functions,
85but it is also possible to use the indexing [] operator to test
86and set individual bits. The [] operator is a little slower than
87setBit() and clearBit() because some tricks are required to
88implement single-bit assignments.
89<p> Example:
90<pre>
91 QBitArray a(3);
92 a.<a href="#setBit">setBit</a>( 0 );
93 a.<a href="#clearBit">clearBit</a>( 1 );
94 a.<a href="#setBit">setBit</a>( 2 ); // a = [1 0 1]
95
96 QBitArray b(3);
97 b[0] = 1;
98 b[1] = 1;
99 b[2] = 0; // b = [1 1 0]
100
101 QBitArray c;
102 c = ~a &amp; b; // c = [0 1 0]
103 </pre>
104
105<p> When a QBitArray is constructed the bits are uninitialized. Use
106<a href="#fill">fill</a>() to set all the bits to 0 or 1. The array can be resized
107with <a href="#resize">resize</a>() and copied with <a href="#copy">copy</a>(). Bits can be set with
108setBit() and cleared with clearBit(). Bits can be toggled with
109<a href="#toggleBit">toggleBit</a>(). A bit's value can be obtained with <a href="#testBit">testBit</a>() and with
110<a href="#at">at</a>().
111<p> QBitArray supports the &amp; (AND), | (OR), ^ (XOR) and ~ (NOT)
112operators.
113<p>See also <a href="collection.html">Collection Classes</a>, <a href="shared.html">Implicitly and Explicitly Shared Classes</a>, and <a href="tools.html">Non-GUI Classes</a>.
114
115<hr><h2>Member Function Documentation</h2>
116<h3 class=fn><a name="QBitArray"></a>QBitArray::QBitArray ()
117</h3>
118Constructs an empty bit array.
119
120<h3 class=fn><a name="QBitArray-2"></a>QBitArray::QBitArray ( uint&nbsp;size )
121</h3>
122Constructs a bit array of <em>size</em> bits. The bits are uninitialized.
123<p> <p>See also <a href="#fill">fill</a>().
124
125<h3 class=fn><a name="QBitArray-3"></a>QBitArray::QBitArray ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
126</h3>
127
128<p> Constructs a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em>.
129
130<h3 class=fn>bool <a name="at"></a>QBitArray::at ( uint&nbsp;index ) const
131</h3>
132
133<p> Returns the value (0 or 1) of the bit at position <em>index</em>.
134<p> <p>See also <a href="#operator[]">operator[]</a>().
135
136<h3 class=fn>void <a name="clearBit"></a>QBitArray::clearBit ( uint&nbsp;index )
137</h3>
138Clears the bit at position <em>index</em>, i.e. sets it to 0.
139<p> <p>See also <a href="#setBit">setBit</a>() and <a href="#toggleBit">toggleBit</a>().
140
141<h3 class=fn><a href="qbitarray.html">QBitArray</a> <a name="copy"></a>QBitArray::copy () const
142</h3>
143Returns a <a href="shclass.html#deep-copy">deep copy</a> of the bit array.
144<p> <p>See also <a href="#detach">detach</a>().
145
146<h3 class=fn>void <a name="detach"></a>QBitArray::detach ()<tt> [virtual]</tt>
147</h3>
148Detaches from shared bit array data and makes sure that this bit
149array is the only one referring to the data.
150<p> If multiple bit arrays share common data, this bit array
151dereferences the data and gets a copy of the data. Nothing happens
152if there is only a single reference.
153<p> <p>See also <a href="#copy">copy</a>().
154
155<p>Reimplemented from <a href="qmemarray.html#detach">QMemArray</a>.
156<h3 class=fn>bool <a name="fill"></a>QBitArray::fill ( bool&nbsp;v, int&nbsp;size = -1 )
157</h3>
158Fills the bit array with <em>v</em> (1's if <em>v</em> is TRUE, or 0's if <em>v</em>
159is FALSE).
160<p> <a href="#fill">fill</a>() resizes the bit array to <em>size</em> bits if <em>size</em> is
161nonnegative.
162<p> Returns FALSE if a nonnegative <em>size</em> was specified and the bit
163array could not be resized; otherwise returns TRUE.
164<p> <p>See also <a href="#resize">resize</a>().
165
166<h3 class=fn><a href="qbitarray.html">QBitArray</a>&nbsp;&amp; <a name="operator-and-eq"></a>QBitArray::operator&amp;= ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
167</h3>
168Performs the AND operation between all bits in this bit array and
169<em>a</em>. Returns a reference to this bit array.
170<p> The result has the length of the longest of the two bit arrays,
171with any missing bits (i.e. if one array is shorter than the
172other), taken to be 0.
173<pre>
174 QBitArray a( 3 ), b( 2 );
175 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
176 b[0] = 1; b[1] = 0; // b = [1 0]
177 a &amp;= b; // a = [1 0 0]
178 </pre>
179
180<p> <p>See also <a href="#operator|-eq">operator|=</a>(), <a href="#operator^-eq">operator^=</a>(), and <a href="#operator~">operator~</a>().
181
182<h3 class=fn><a href="qbitarray.html">QBitArray</a>&nbsp;&amp; <a name="operator-eq"></a>QBitArray::operator= ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
183</h3>
184
185<p> Assigns a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em> to this bit array and returns a
186reference to this array.
187
188<h3 class=fn><a href="qbitval.html">QBitVal</a> <a name="operator[]"></a>QBitArray::operator[] ( int&nbsp;index )
189</h3>
190
191<p> Implements the [] operator for bit arrays.
192<p> The returned <a href="qbitval.html">QBitVal</a> is a context object. It makes it possible to
193get and set a single bit value by its <em>index</em> position.
194<p> Example:
195<pre>
196 QBitArray a( 3 );
197 a[0] = 0;
198 a[1] = 1;
199 a[2] = a[0] ^ a[1];
200 </pre>
201
202<p> The functions <a href="#testBit">testBit</a>(), <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>() are faster.
203<p> <p>See also <a href="#at">at</a>().
204
205<h3 class=fn>bool <a name="operator[]-2"></a>QBitArray::operator[] ( int&nbsp;index ) const
206</h3>
207This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
208<p> Implements the [] operator for constant bit arrays.
209
210<h3 class=fn><a href="qbitarray.html">QBitArray</a>&nbsp;&amp; <a name="operator^-eq"></a>QBitArray::operator^= ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
211</h3>
212Performs the XOR operation between all bits in this bit array and
213<em>a</em>. Returns a reference to this bit array.
214<p> The result has the length of the longest of the two bit arrays,
215with any missing bits (i.e. if one array is shorter than the
216other), taken to be 0.
217<pre>
218 QBitArray a( 3 ), b( 2 );
219 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
220 b[0] = 1; b[1] = 0; // b = [1 0]
221 a ^= b; // a = [0 0 1]
222 </pre>
223
224<p> <p>See also <a href="#operator-and-eq">operator&amp;=</a>(), <a href="#operator|-eq">operator|=</a>(), and <a href="#operator~">operator~</a>().
225
226<h3 class=fn><a href="qbitarray.html">QBitArray</a>&nbsp;&amp; <a name="operator|-eq"></a>QBitArray::operator|= ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
227</h3>
228Performs the OR operation between all bits in this bit array and
229<em>a</em>. Returns a reference to this bit array.
230<p> The result has the length of the longest of the two bit arrays,
231with any missing bits (i.e. if one array is shorter than the
232other), taken to be 0.
233<pre>
234 QBitArray a( 3 ), b( 2 );
235 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
236 b[0] = 1; b[1] = 0; // b = [1 0]
237 a |= b; // a = [1 0 1]
238 </pre>
239
240<p> <p>See also <a href="#operator-and-eq">operator&amp;=</a>(), <a href="#operator^-eq">operator^=</a>(), and <a href="#operator~">operator~</a>().
241
242<h3 class=fn><a href="qbitarray.html">QBitArray</a> <a name="operator~"></a>QBitArray::operator~ () const
243</h3>
244Returns a bit array that contains the inverted bits of this bit array.
245<p> Example:
246<pre>
247 QBitArray a( 3 ), b;
248 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
249 b = ~a; // b = [0 1 0]
250 </pre>
251
252
253<h3 class=fn>bool <a name="resize"></a>QBitArray::resize ( uint&nbsp;size )
254</h3>
255Resizes the bit array to <em>size</em> bits and returns TRUE if the bit
256array could be resized; otherwise returns FALSE. The array becomes
257a null array if <em>size</em> == 0.
258<p> If the array is expanded, the new bits are set to 0.
259<p> <p>See also <a href="#size">size</a>().
260
261<h3 class=fn>void <a name="setBit"></a>QBitArray::setBit ( uint&nbsp;index, bool&nbsp;value )
262</h3>
263
264<p> Sets the bit at position <em>index</em> to <em>value</em>.
265<p> Equivalent to:
266<pre>
267 if ( value )
268 <a href="#setBit">setBit</a>( index );
269 else
270 <a href="#clearBit">clearBit</a>( index );
271 </pre>
272
273<p> <p>See also <a href="#clearBit">clearBit</a>() and <a href="#toggleBit">toggleBit</a>().
274
275<h3 class=fn>void <a name="setBit-2"></a>QBitArray::setBit ( uint&nbsp;index )
276</h3>
277This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
278<p> Sets the bit at position <em>index</em> to 1.
279<p> <p>See also <a href="#clearBit">clearBit</a>() and <a href="#toggleBit">toggleBit</a>().
280
281<h3 class=fn>uint <a name="size"></a>QBitArray::size () const
282</h3>
283
284<p> Returns the bit array's size (number of bits).
285<p> <p>See also <a href="#resize">resize</a>().
286
287<h3 class=fn>bool <a name="testBit"></a>QBitArray::testBit ( uint&nbsp;index ) const
288</h3>
289Returns TRUE if the bit at position <em>index</em> is set, i.e. is 1;
290otherwise returns FALSE.
291<p> <p>See also <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>().
292
293<h3 class=fn>bool <a name="toggleBit"></a>QBitArray::toggleBit ( uint&nbsp;index )
294</h3>
295Toggles the bit at position <em>index</em>.
296<p> If the previous value was 0, the new value will be 1. If the
297previous value was 1, the new value will be 0.
298<p> <p>See also <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>().
299
300<hr><h2>Related Functions</h2>
301<h3 class=fn><a href="qbitarray.html">QBitArray</a> <a name="operator-and"></a>operator&amp; ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a1, const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a2 )
302</h3>
303
304<p> Returns the AND result between the bit arrays <em>a1</em> and <em>a2</em>.
305<p> The result has the length of the longest of the two bit arrays,
306with any missing bits (i.e. if one array is shorter than the
307other), taken to be 0.
308<p> <p>See also <a href="#operator-and-eq">QBitArray::operator&=</a>().
309
310<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
311</h3>
312
313<p> Writes bit array <em>a</em> to stream <em>s</em>.
314<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
315
316<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
317</h3>
318
319<p> Reads a bit array into <em>a</em> from stream <em>s</em>.
320<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
321
322<h3 class=fn><a href="qbitarray.html">QBitArray</a> <a name="operator^"></a>operator^ ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a1, const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a2 )
323</h3>
324
325<p> Returns the XOR result between the bit arrays <em>a1</em> and <em>a2</em>.
326<p> The result has the length of the longest of the two bit arrays,
327with any missing bits (i.e. if one array is shorter than the
328other), taken to be 0.
329<p> <p>See also <a href="#operator^">QBitArray::operator^</a>().
330
331<h3 class=fn><a href="qbitarray.html">QBitArray</a> <a name="operator|"></a>operator| ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a1, const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a2 )
332</h3>
333
334<p> Returns the OR result between the bit arrays <em>a1</em> and <em>a2</em>.
335<p> The result has the length of the longest of the two bit arrays,
336with any missing bits (i.e. if one array is shorter than the
337other), taken to be 0.
338<p> <p>See also <a href="#operator|-eq">QBitArray::operator|=</a>().
339
340<!-- eof -->
341<hr><p>
342This file is part of the <a href="index.html">Qt toolkit</a>.
343Copyright &copy; 1995-2007
344<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
345<table width=100% cellspacing=0 border=0><tr>
346<td>Copyright &copy; 2007
347<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
348<td align=right><div align=right>Qt 3.3.8</div>
349</table></div></address></body>
350</html>
Note: See TracBrowser for help on using the repository browser.