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
|
<!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/src/tools/qbitarray.cpp:83 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQBitArray 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>TQBitArray Class Reference</h1>
<p>The TQBitArray class provides an array of bits.
<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="qbitarray-h.html">qbitarray.h</a>></tt>
<p>Inherits <a href="qbytearray.html">TQByteArray</a>.
<p><a href="qbitarray-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#TQBitArray"><b>TQBitArray</b></a> ()</li>
<li class=fn><a href="#TQBitArray-2"><b>TQBitArray</b></a> ( uint size )</li>
<li class=fn><a href="#TQBitArray-3"><b>TQBitArray</b></a> ( const TQBitArray & a )</li>
<li class=fn>TQBitArray & <a href="#operator-eq"><b>operator=</b></a> ( const TQBitArray & a )</li>
<li class=fn>uint <a href="#size"><b>size</b></a> () const</li>
<li class=fn>bool <a href="#resize"><b>resize</b></a> ( uint size )</li>
<li class=fn>bool <a href="#fill"><b>fill</b></a> ( bool v, int size = -1 )</li>
<li class=fn>virtual void <a href="#detach"><b>detach</b></a> ()</li>
<li class=fn>TQBitArray <a href="#copy"><b>copy</b></a> () const</li>
<li class=fn>bool <a href="#testBit"><b>testBit</b></a> ( uint index ) const</li>
<li class=fn>void <a href="#setBit-2"><b>setBit</b></a> ( uint index )</li>
<li class=fn>void <a href="#setBit"><b>setBit</b></a> ( uint index, bool value )</li>
<li class=fn>void <a href="#clearBit"><b>clearBit</b></a> ( uint index )</li>
<li class=fn>bool <a href="#toggleBit"><b>toggleBit</b></a> ( uint index )</li>
<li class=fn>bool <a href="#at"><b>at</b></a> ( uint index ) const</li>
<li class=fn>TQBitVal <a href="#operator[]"><b>operator[]</b></a> ( int index )</li>
<li class=fn>bool <a href="#operator[]-2"><b>operator[]</b></a> ( int index ) const</li>
<li class=fn>TQBitArray & <a href="#operator-and-eq"><b>operator&=</b></a> ( const TQBitArray & a )</li>
<li class=fn>TQBitArray & <a href="#operator|-eq"><b>operator|=</b></a> ( const TQBitArray & a )</li>
<li class=fn>TQBitArray & <a href="#operator^-eq"><b>operator^=</b></a> ( const TQBitArray & a )</li>
<li class=fn>TQBitArray <a href="#operator~"><b>operator~</b></a> () const</li>
</ul>
<h2>Related Functions</h2>
<ul>
<li class=fn>TQBitArray <a href="#operator-and"><b>operator&</b></a> ( const TQBitArray & a1, const TQBitArray & a2 )</li>
<li class=fn>TQBitArray <a href="#operator|"><b>operator|</b></a> ( const TQBitArray & a1, const TQBitArray & a2 )</li>
<li class=fn>TQBitArray <a href="#operator^"><b>operator^</b></a> ( const TQBitArray & a1, const TQBitArray & a2 )</li>
<li class=fn>TQDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( TQDataStream & s, const TQBitArray & a )</li>
<li class=fn>TQDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( TQDataStream & s, TQBitArray & a )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The TQBitArray class provides an array of bits.
<p>
<p> Because TQBitArray is a <a href="qmemarray.html">TQMemArray</a>, it uses explicit <a href="shclass.html">sharing</a> with a reference count.
<p> A TQBitArray is a special byte array that can access individual
bits and perform bit-operations (AND, OR, XOR and NOT) on entire
arrays or bits.
<p> Bits can be manipulated by the <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>() functions,
but it is also possible to use the indexing [] operator to test
and set individual bits. The [] operator is a little slower than
setBit() and clearBit() because some tricks are required to
implement single-bit assignments.
<p> Example:
<pre>
TQBitArray a(3);
a.<a href="#setBit">setBit</a>( 0 );
a.<a href="#clearBit">clearBit</a>( 1 );
a.<a href="#setBit">setBit</a>( 2 ); // a = [1 0 1]
TQBitArray b(3);
b[0] = 1;
b[1] = 1;
b[2] = 0; // b = [1 1 0]
TQBitArray c;
c = ~a & b; // c = [0 1 0]
</pre>
<p> When a TQBitArray is constructed the bits are uninitialized. Use
<a href="#fill">fill</a>() to set all the bits to 0 or 1. The array can be resized
with <a href="#resize">resize</a>() and copied with <a href="#copy">copy</a>(). Bits can be set with
setBit() and cleared with clearBit(). Bits can be toggled with
<a href="#toggleBit">toggleBit</a>(). A bit's value can be obtained with <a href="#testBit">testBit</a>() and with
<a href="#at">at</a>().
<p> TQBitArray supports the & (AND), | (OR), ^ (XOR) and ~ (NOT)
operators.
<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>.
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQBitArray"></a>TQBitArray::TQBitArray ()
</h3>
Constructs an empty bit array.
<h3 class=fn><a name="TQBitArray-2"></a>TQBitArray::TQBitArray ( uint size )
</h3>
Constructs a bit array of <em>size</em> bits. The bits are uninitialized.
<p> <p>See also <a href="#fill">fill</a>().
<h3 class=fn><a name="TQBitArray-3"></a>TQBitArray::TQBitArray ( const <a href="qbitarray.html">TQBitArray</a> & a )
</h3>
<p> Constructs a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em>.
<h3 class=fn>bool <a name="at"></a>TQBitArray::at ( uint index ) const
</h3>
<p> Returns the value (0 or 1) of the bit at position <em>index</em>.
<p> <p>See also <a href="#operator[]">operator[]</a>().
<h3 class=fn>void <a name="clearBit"></a>TQBitArray::clearBit ( uint index )
</h3>
Clears the bit at position <em>index</em>, i.e. sets it to 0.
<p> <p>See also <a href="#setBit">setBit</a>() and <a href="#toggleBit">toggleBit</a>().
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> <a name="copy"></a>TQBitArray::copy () const
</h3>
Returns a <a href="shclass.html#deep-copy">deep copy</a> of the bit array.
<p> <p>See also <a href="#detach">detach</a>().
<h3 class=fn>void <a name="detach"></a>TQBitArray::detach ()<tt> [virtual]</tt>
</h3>
Detaches from shared bit array data and makes sure that this bit
array is the only one referring to the data.
<p> If multiple bit arrays share common data, this bit array
dereferences the data and gets a copy of the data. Nothing happens
if there is only a single reference.
<p> <p>See also <a href="#copy">copy</a>().
<p>Reimplemented from <a href="qmemarray.html#detach">TQMemArray</a>.
<h3 class=fn>bool <a name="fill"></a>TQBitArray::fill ( bool v, int size = -1 )
</h3>
Fills the bit array with <em>v</em> (1's if <em>v</em> is TRUE, or 0's if <em>v</em>
is FALSE).
<p> <a href="#fill">fill</a>() resizes the bit array to <em>size</em> bits if <em>size</em> is
nonnegative.
<p> Returns FALSE if a nonnegative <em>size</em> was specified and the bit
array could not be resized; otherwise returns TRUE.
<p> <p>See also <a href="#resize">resize</a>().
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> & <a name="operator-and-eq"></a>TQBitArray::operator&= ( const <a href="qbitarray.html">TQBitArray</a> & a )
</h3>
Performs the AND operation between all bits in this bit array and
<em>a</em>. Returns a reference to this bit array.
<p> The result has the length of the longest of the two bit arrays,
with any missing bits (i.e. if one array is shorter than the
other), taken to be 0.
<pre>
TQBitArray a( 3 ), b( 2 );
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
b[0] = 1; b[1] = 0; // b = [1 0]
a &= b; // a = [1 0 0]
</pre>
<p> <p>See also <a href="#operator|-eq">operator|=</a>(), <a href="#operator^-eq">operator^=</a>(), and <a href="#operator~">operator~</a>().
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> & <a name="operator-eq"></a>TQBitArray::operator= ( const <a href="qbitarray.html">TQBitArray</a> & a )
</h3>
<p> Assigns a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em> to this bit array and returns a
reference to this array.
<h3 class=fn><a href="qbitval.html">TQBitVal</a> <a name="operator[]"></a>TQBitArray::operator[] ( int index )
</h3>
<p> Implements the [] operator for bit arrays.
<p> The returned <a href="qbitval.html">TQBitVal</a> is a context object. It makes it possible to
get and set a single bit value by its <em>index</em> position.
<p> Example:
<pre>
TQBitArray a( 3 );
a[0] = 0;
a[1] = 1;
a[2] = a[0] ^ a[1];
</pre>
<p> The functions <a href="#testBit">testBit</a>(), <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>() are faster.
<p> <p>See also <a href="#at">at</a>().
<h3 class=fn>bool <a name="operator[]-2"></a>TQBitArray::operator[] ( int index ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Implements the [] operator for constant bit arrays.
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> & <a name="operator^-eq"></a>TQBitArray::operator^= ( const <a href="qbitarray.html">TQBitArray</a> & a )
</h3>
Performs the XOR operation between all bits in this bit array and
<em>a</em>. Returns a reference to this bit array.
<p> The result has the length of the longest of the two bit arrays,
with any missing bits (i.e. if one array is shorter than the
other), taken to be 0.
<pre>
TQBitArray a( 3 ), b( 2 );
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
b[0] = 1; b[1] = 0; // b = [1 0]
a ^= b; // a = [0 0 1]
</pre>
<p> <p>See also <a href="#operator-and-eq">operator&=</a>(), <a href="#operator|-eq">operator|=</a>(), and <a href="#operator~">operator~</a>().
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> & <a name="operator|-eq"></a>TQBitArray::operator|= ( const <a href="qbitarray.html">TQBitArray</a> & a )
</h3>
Performs the OR operation between all bits in this bit array and
<em>a</em>. Returns a reference to this bit array.
<p> The result has the length of the longest of the two bit arrays,
with any missing bits (i.e. if one array is shorter than the
other), taken to be 0.
<pre>
TQBitArray a( 3 ), b( 2 );
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
b[0] = 1; b[1] = 0; // b = [1 0]
a |= b; // a = [1 0 1]
</pre>
<p> <p>See also <a href="#operator-and-eq">operator&=</a>(), <a href="#operator^-eq">operator^=</a>(), and <a href="#operator~">operator~</a>().
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> <a name="operator~"></a>TQBitArray::operator~ () const
</h3>
Returns a bit array that contains the inverted bits of this bit array.
<p> Example:
<pre>
TQBitArray a( 3 ), b;
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
b = ~a; // b = [0 1 0]
</pre>
<h3 class=fn>bool <a name="resize"></a>TQBitArray::resize ( uint size )
</h3>
Resizes the bit array to <em>size</em> bits and returns TRUE if the bit
array could be resized; otherwise returns FALSE. The array becomes
a null array if <em>size</em> == 0.
<p> If the array is expanded, the new bits are set to 0.
<p> <p>See also <a href="#size">size</a>().
<h3 class=fn>void <a name="setBit"></a>TQBitArray::setBit ( uint index, bool value )
</h3>
<p> Sets the bit at position <em>index</em> to <em>value</em>.
<p> Equivalent to:
<pre>
if ( value )
<a href="#setBit">setBit</a>( index );
else
<a href="#clearBit">clearBit</a>( index );
</pre>
<p> <p>See also <a href="#clearBit">clearBit</a>() and <a href="#toggleBit">toggleBit</a>().
<h3 class=fn>void <a name="setBit-2"></a>TQBitArray::setBit ( uint index )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Sets the bit at position <em>index</em> to 1.
<p> <p>See also <a href="#clearBit">clearBit</a>() and <a href="#toggleBit">toggleBit</a>().
<h3 class=fn>uint <a name="size"></a>TQBitArray::size () const
</h3>
<p> Returns the bit array's size (number of bits).
<p> <p>See also <a href="#resize">resize</a>().
<h3 class=fn>bool <a name="testBit"></a>TQBitArray::testBit ( uint index ) const
</h3>
Returns TRUE if the bit at position <em>index</em> is set, i.e. is 1;
otherwise returns FALSE.
<p> <p>See also <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>().
<h3 class=fn>bool <a name="toggleBit"></a>TQBitArray::toggleBit ( uint index )
</h3>
Toggles the bit at position <em>index</em>.
<p> If the previous value was 0, the new value will be 1. If the
previous value was 1, the new value will be 0.
<p> <p>See also <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>().
<hr><h2>Related Functions</h2>
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> <a name="operator-and"></a>operator& ( const <a href="qbitarray.html">TQBitArray</a> & a1, const <a href="qbitarray.html">TQBitArray</a> & a2 )
</h3>
<p> Returns the AND result between the bit arrays <em>a1</em> and <em>a2</em>.
<p> The result has the length of the longest of the two bit arrays,
with any missing bits (i.e. if one array is shorter than the
other), taken to be 0.
<p> <p>See also <a href="#operator-and-eq">TQBitArray::operator&=</a>().
<h3 class=fn><a href="qdatastream.html">TQDataStream</a> & <a name="operator-lt-lt"></a>operator<< ( <a href="qdatastream.html">TQDataStream</a> & s, const <a href="qbitarray.html">TQBitArray</a> & a )
</h3>
<p> Writes bit array <em>a</em> to stream <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the TQDataStream operators</a>.
<h3 class=fn><a href="qdatastream.html">TQDataStream</a> & <a name="operator-gt-gt"></a>operator>> ( <a href="qdatastream.html">TQDataStream</a> & s, <a href="qbitarray.html">TQBitArray</a> & a )
</h3>
<p> Reads a bit array into <em>a</em> from stream <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the TQDataStream operators</a>.
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> <a name="operator^"></a>operator^ ( const <a href="qbitarray.html">TQBitArray</a> & a1, const <a href="qbitarray.html">TQBitArray</a> & a2 )
</h3>
<p> Returns the XOR result between the bit arrays <em>a1</em> and <em>a2</em>.
<p> The result has the length of the longest of the two bit arrays,
with any missing bits (i.e. if one array is shorter than the
other), taken to be 0.
<p> <p>See also <a href="#operator^">TQBitArray::operator^</a>().
<h3 class=fn><a href="qbitarray.html">TQBitArray</a> <a name="operator|"></a>operator| ( const <a href="qbitarray.html">TQBitArray</a> & a1, const <a href="qbitarray.html">TQBitArray</a> & a2 )
</h3>
<p> Returns the OR result between the bit arrays <em>a1</em> and <em>a2</em>.
<p> The result has the length of the longest of the two bit arrays,
with any missing bits (i.e. if one array is shorter than the
other), taken to be 0.
<p> <p>See also <a href="#operator|-eq">TQBitArray::operator|=</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>
|