1QBitArray(3qt) QBitArray(3qt)
2
3
4
6 QBitArray - Array of bits
7
9 All the functions in this class are reentrant when Qt is built with
10 thread support.</p>
11
12 #include <qbitarray.h>
13
14 Inherits QByteArray.
15
16 Public Members
17 QBitArray ()
18 QBitArray ( uint size )
19 QBitArray ( const QBitArray & a )
20 QBitArray & operator= ( const QBitArray & a )
21 uint size () const
22 bool resize ( uint size )
23 bool fill ( bool v, int size = -1 )
24 virtual void detach ()
25 QBitArray copy () const
26 bool testBit ( uint index ) const
27 void setBit ( uint index )
28 void setBit ( uint index, bool value )
29 void clearBit ( uint index )
30 bool toggleBit ( uint index )
31 bool at ( uint index ) const
32 QBitVal operator[] ( int index )
33 bool operator[] ( int index ) const
34 QBitArray & operator&= ( const QBitArray & a )
35 QBitArray & operator|= ( const QBitArray & a )
36 QBitArray & operator^= ( const QBitArray & a )
37 QBitArray operator~ () const
38
40 QBitArray operator& ( const QBitArray & a1, const QBitArray & a2 )
41 QBitArray operator| ( const QBitArray & a1, const QBitArray & a2 )
42 QBitArray operator^ ( const QBitArray & a1, const QBitArray & a2 )
43 QDataStream & operator<< ( QDataStream & s, const QBitArray & a )
44 QDataStream & operator>> ( QDataStream & s, QBitArray & a )
45
47 The QBitArray class provides an array of bits.
48
49 Because QBitArray is a QMemArray, it uses explicit sharing with a
50 reference count.
51
52 A QBitArray is a special byte array that can access individual bits and
53 perform bit-operations (AND, OR, XOR and NOT) on entire arrays or bits.
54
55 Bits can be manipulated by the setBit() and clearBit() functions, but
56 it is also possible to use the indexing [] operator to test and set
57 individual bits. The [] operator is a little slower than setBit() and
58 clearBit() because some tricks are required to implement single-bit
59 assignments.
60
61 Example:
62
63 QBitArray a(3);
64 a.setBit( 0 );
65 a.clearBit( 1 );
66 a.setBit( 2 ); // a = [1 0 1]
67 QBitArray b(3);
68 b[0] = 1;
69 b[1] = 1;
70 b[2] = 0; // b = [1 1 0]
71 QBitArray c;
72 c = ~a & b; // c = [0 1 0]
73
74 When a QBitArray is constructed the bits are uninitialized. Use fill()
75 to set all the bits to 0 or 1. The array can be resized with resize()
76 and copied with copy(). Bits can be set with setBit() and cleared with
77 clearBit(). Bits can be toggled with toggleBit(). A bit's value can be
78 obtained with testBit() and with at().
79
80 QBitArray supports the & (AND), | (OR), ^ (XOR) and ~ (NOT) operators.
81
82 See also Collection Classes, Implicitly and Explicitly Shared Classes,
83 and Non-GUI Classes.
84
87 Constructs an empty bit array.
88
90 Constructs a bit array of size bits. The bits are uninitialized.
91
92 See also fill().
93
95 Constructs a shallow copy of a.
96
98 Returns the value (0 or 1) of the bit at position index.
99
100 See also operator[]().
101
103 Clears the bit at position index, i.e. sets it to 0.
104
105 See also setBit() and toggleBit().
106
108 Returns a deep copy of the bit array.
109
110 See also detach().
111
113 Detaches from shared bit array data and makes sure that this bit array
114 is the only one referring to the data.
115
116 If multiple bit arrays share common data, this bit array dereferences
117 the data and gets a copy of the data. Nothing happens if there is only
118 a single reference.
119
120 See also copy().
121
122 Reimplemented from QMemArray.
123
125 Fills the bit array with v (1's if v is TRUE, or 0's if v is FALSE).
126
127 fill() resizes the bit array to size bits if size is nonnegative.
128
129 Returns FALSE if a nonnegative size was specified and the bit array
130 could not be resized; otherwise returns TRUE.
131
132 See also resize().
133
135 Performs the AND operation between all bits in this bit array and a.
136 Returns a reference to this bit array.
137
138 The result has the length of the longest of the two bit arrays, with
139 any missing bits (i.e. if one array is shorter than the other), taken
140 to be 0.
141
142 QBitArray a( 3 ), b( 2 );
143 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
144 b[0] = 1; b[1] = 0; // b = [1 0]
145 a &= b; // a = [1 0 0]
146
147 See also operator|=(), operator^=(), and operator~().
148
150 Assigns a shallow copy of a to this bit array and returns a reference
151 to this array.
152
154 Implements the [] operator for bit arrays.
155
156 The returned QBitVal is a context object. It makes it possible to get
157 and set a single bit value by its index position.
158
159 Example:
160
161 QBitArray a( 3 );
162 a[0] = 0;
163 a[1] = 1;
164 a[2] = a[0] ^ a[1];
165
166 The functions testBit(), setBit() and clearBit() are faster.
167
168 See also at().
169
171 This is an overloaded member function, provided for convenience. It
172 behaves essentially like the above function.
173
174 Implements the [] operator for constant bit arrays.
175
177 Performs the XOR operation between all bits in this bit array and a.
178 Returns a reference to this bit array.
179
180 The result has the length of the longest of the two bit arrays, with
181 any missing bits (i.e. if one array is shorter than the other), taken
182 to be 0.
183
184 QBitArray a( 3 ), b( 2 );
185 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
186 b[0] = 1; b[1] = 0; // b = [1 0]
187 a ^= b; // a = [0 0 1]
188
189 See also operator&=(), operator|=(), and operator~().
190
192 Performs the OR operation between all bits in this bit array and a.
193 Returns a reference to this bit array.
194
195 The result has the length of the longest of the two bit arrays, with
196 any missing bits (i.e. if one array is shorter than the other), taken
197 to be 0.
198
199 QBitArray a( 3 ), b( 2 );
200 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
201 b[0] = 1; b[1] = 0; // b = [1 0]
202 a |= b; // a = [1 0 1]
203
204 See also operator&=(), operator^=(), and operator~().
205
207 Returns a bit array that contains the inverted bits of this bit array.
208
209 Example:
210
211 QBitArray a( 3 ), b;
212 a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
213 b = ~a; // b = [0 1 0]
214
216 Resizes the bit array to size bits and returns TRUE if the bit array
217 could be resized; otherwise returns FALSE. The array becomes a null
218 array if size == 0.
219
220 If the array is expanded, the new bits are set to 0.
221
222 See also size().
223
225 Sets the bit at position index to value.
226
227 Equivalent to:
228
229 if ( value )
230 setBit( index );
231 else
232 clearBit( index );
233
234 See also clearBit() and toggleBit().
235
237 This is an overloaded member function, provided for convenience. It
238 behaves essentially like the above function.
239
240 Sets the bit at position index to 1.
241
242 See also clearBit() and toggleBit().
243
245 Returns the bit array's size (number of bits).
246
247 See also resize().
248
250 Returns TRUE if the bit at position index is set, i.e. is 1; otherwise
251 returns FALSE.
252
253 See also setBit() and clearBit().
254
256 Toggles the bit at position index.
257
258 If the previous value was 0, the new value will be 1. If the previous
259 value was 1, the new value will be 0.
260
261 See also setBit() and clearBit().
262
265 Returns the AND result between the bit arrays a1 and a2.
266
267 The result has the length of the longest of the two bit arrays, with
268 any missing bits (i.e. if one array is shorter than the other), taken
269 to be 0.
270
271 See also QBitArray::operator&=().
272
274 Writes bit array a to stream s.
275
276 See also Format of the QDataStream operators.
277
279 Reads a bit array into a from stream s.
280
281 See also Format of the QDataStream operators.
282
284 Returns the XOR result between the bit arrays a1 and a2.
285
286 The result has the length of the longest of the two bit arrays, with
287 any missing bits (i.e. if one array is shorter than the other), taken
288 to be 0.
289
290 See also QBitArray::operator^().
291
293 Returns the OR result between the bit arrays a1 and a2.
294
295 The result has the length of the longest of the two bit arrays, with
296 any missing bits (i.e. if one array is shorter than the other), taken
297 to be 0.
298
299 See also QBitArray::operator|=().
300
301
303 http://doc.trolltech.com/qbitarray.html
304 http://www.trolltech.com/faq/tech.html
305
307 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
308 license file included in the distribution for a complete license
309 statement.
310
312 Generated automatically from the source code.
313
315 If you find a bug in Qt, please report it as described in
316 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
317 help you. Thank you.
318
319 The definitive Qt documentation is provided in HTML format; it is
320 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
321 web browser. This man page is provided as a convenience for those users
322 who prefer man pages, although this format is not officially supported
323 by Trolltech.
324
325 If you find errors in this manual page, please report them to qt-
326 bugs@trolltech.com. Please include the name of the manual page
327 (qbitarray.3qt) and the Qt version (3.3.8).
328
329
330
331Trolltech AS 2 February 2007 QBitArray(3qt)