You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
350 lines
17 KiB
350 lines
17 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<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="tqbitarray-h.html">tqbitarray.h</a>></tt>
|
|
<p>Inherits <a href="tqbytearray.html">TQByteArray</a>.
|
|
<p><a href="tqbitarray-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="tqmemarray.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="tqbitarray.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="tqbitarray.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="tqmemarray.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="tqbitarray.html">TQBitArray</a> & <a name="operator-and-eq"></a>TQBitArray::operator&= ( const <a href="tqbitarray.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="tqbitarray.html">TQBitArray</a> & <a name="operator-eq"></a>TQBitArray::operator= ( const <a href="tqbitarray.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="tqbitval.html">TQBitVal</a> <a name="operator[]"></a>TQBitArray::operator[] ( int index )
|
|
</h3>
|
|
|
|
<p> Implements the [] operator for bit arrays.
|
|
<p> The returned <a href="tqbitval.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="tqbitarray.html">TQBitArray</a> & <a name="operator^-eq"></a>TQBitArray::operator^= ( const <a href="tqbitarray.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="tqbitarray.html">TQBitArray</a> & <a name="operator|-eq"></a>TQBitArray::operator|= ( const <a href="tqbitarray.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="tqbitarray.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="tqbitarray.html">TQBitArray</a> <a name="operator-and"></a>operator& ( const <a href="tqbitarray.html">TQBitArray</a> & a1, const <a href="tqbitarray.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="tqdatastream.html">TQDataStream</a> & <a name="operator-lt-lt"></a>operator<< ( <a href="tqdatastream.html">TQDataStream</a> & s, const <a href="tqbitarray.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="tqdatastream.html">TQDataStream</a> & <a name="operator-gt-gt"></a>operator>> ( <a href="tqdatastream.html">TQDataStream</a> & s, <a href="tqbitarray.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="tqbitarray.html">TQBitArray</a> <a name="operator^"></a>operator^ ( const <a href="tqbitarray.html">TQBitArray</a> & a1, const <a href="tqbitarray.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="tqbitarray.html">TQBitArray</a> <a name="operator|"></a>operator| ( const <a href="tqbitarray.html">TQBitArray</a> & a1, const <a href="tqbitarray.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>
|