Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 881

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/tools/qbitarray.cpp:81 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QBitArray Class</title>
<style type="text/css"><!--
h3.fn,span.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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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>QBitArray Class Reference</h1>

<p>The QBitArray class provides an array of bits.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qbitarray-h.html">qbitarray.h</a>&gt;</tt>
<p>Inherits <a href="qbytearray.html">QByteArray</a>.
<p><a href="qbitarray-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class=fn><a href="#QBitArray"><b>QBitArray</b></a> ()</div></li>
<li><div class=fn><a href="#QBitArray-2"><b>QBitArray</b></a> ( uint&nbsp;size )</div></li>
<li><div class=fn><a href="#QBitArray-3"><b>QBitArray</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</div></li>
<li><div class=fn>QBitArray &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</div></li>
<li><div class=fn>uint <a href="#size"><b>size</b></a> () const</div></li>
<li><div class=fn>bool <a href="#resize"><b>resize</b></a> ( uint&nbsp;size )</div></li>
<li><div class=fn>bool <a href="#fill"><b>fill</b></a> ( bool&nbsp;v, int&nbsp;size = -1 )</div></li>
<li><div class=fn>virtual void <a href="#detach"><b>detach</b></a> ()</div></li>
<li><div class=fn>QBitArray <a href="#copy"><b>copy</b></a> () const</div></li>
<li><div class=fn>bool <a href="#testBit"><b>testBit</b></a> ( uint&nbsp;index ) const</div></li>
<li><div class=fn>void <a href="#setBit-2"><b>setBit</b></a> ( uint&nbsp;index )</div></li>
<li><div class=fn>void <a href="#setBit"><b>setBit</b></a> ( uint&nbsp;index, bool&nbsp;value )</div></li>
<li><div class=fn>void <a href="#clearBit"><b>clearBit</b></a> ( uint&nbsp;index )</div></li>
<li><div class=fn>bool <a href="#toggleBit"><b>toggleBit</b></a> ( uint&nbsp;index )</div></li>
<li><div class=fn>bool <a href="#at"><b>at</b></a> ( uint&nbsp;index ) const</div></li>
<li><div class=fn>QBitVal <a href="#operator[]"><b>operator[]</b></a> ( int&nbsp;index )</div></li>
<li><div class=fn>bool <a href="#operator[]-2"><b>operator[]</b></a> ( int&nbsp;index ) const</div></li>
<li><div class=fn>QBitArray &amp; <a href="#operator-and-eq"><b>operator&amp;=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</div></li>
<li><div class=fn>QBitArray &amp; <a href="#operator|-eq"><b>operator|=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</div></li>
<li><div class=fn>QBitArray &amp; <a href="#operator^-eq"><b>operator^=</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a )</div></li>
<li><div class=fn>QBitArray <a href="#operator~"><b>operator~</b></a> () const</div></li>
</ul>
<h2>Related Functions</h2>
<ul>
<li><div 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 )</div></li>
<li><div class=fn>QBitArray <a href="#operator|"><b>operator|</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a1, const&nbsp;QBitArray&nbsp;&amp;&nbsp;a2 )</div></li>
<li><div class=fn>QBitArray <a href="#operator^"><b>operator^</b></a> ( const&nbsp;QBitArray&nbsp;&amp;&nbsp;a1, const&nbsp;QBitArray&nbsp;&amp;&nbsp;a2 )</div></li>
<li><div 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 )</div></li>
<li><div 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 )</div></li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>



The QBitArray class provides an array of bits.
<p> 

<p> Because QBitArray is a <a href="qmemarray.html">QMemArray</a>, it uses explicit
<a href="shclass.html">sharing</a> with a reference count.
<p> A QBitArray 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>
    QBitArray 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]

    QBitArray b(3);
    b[0] = 1;
    b[1] = 1;
    b[2] = 0;                           // b = [1 1 0]

    QBitArray c;
    c = ~a &amp; b;                         // c = [0 1 0]
  </pre>
 
<p> When a QBitArray 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> QBitArray supports the &amp; (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="QBitArray"></a>QBitArray::QBitArray ()
</h3>
Constructs an empty bit array.

<h3 class=fn><a name="QBitArray-2"></a>QBitArray::QBitArray ( uint&nbsp;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="QBitArray-3"></a>QBitArray::QBitArray ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
</h3>

Constructs a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em>.

<h3 class=fn>bool <a name="at"></a>QBitArray::at ( uint&nbsp;index ) const
</h3>

Returns the value (0 or 1) of the bit at position <em>index</em>.
<p>See also <a href="#operator[]">operator[]</a>().

<h3 class=fn>void <a name="clearBit"></a>QBitArray::clearBit ( uint&nbsp;index )
</h3>
Clears the bit at position <em>index</em> (sets it to 0).
<p>See also <a href="#setBit">setBit</a>() and <a href="#toggleBit">toggleBit</a>().

<h3 class=fn><a href="qbitarray.html">QBitArray</a> <a name="copy"></a>QBitArray::copy () const
</h3>
Returns a <a href="shclass.html#deep-copy">deep copy</a> of the bit array.
<p>See also <a href="#detach">detach</a>().

<h3 class=fn>void <a name="detach"></a>QBitArray::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 will be done if there is just
a single reference.
<p> <p>See also <a href="#copy">copy</a>().

<p>Reimplemented from <a href="qmemarray.html#detach">QMemArray</a>.
<h3 class=fn>bool <a name="fill"></a>QBitArray::fill ( bool&nbsp;v, int&nbsp;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">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 )
</h3>
Performs the AND operation between all bits in this bit array and <em>a</em>.
Returns a reference to this bit array.
<p> If the arrays have different sizes, the AND operation uses 0 for the
missing bits, as the following example demonstrates:
<pre>
    QBitArray 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 &amp;= 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">QBitArray</a>&nbsp;&amp; <a name="operator-eq"></a>QBitArray::operator= ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;a )
</h3>

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">QBitVal</a> <a name="operator[]"></a>QBitArray::operator[] ( int&nbsp;index )
</h3>

Implements the [] operator for bit arrays.
<p> The returned <a href="qbitval.html">QBitVal</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>
    QBitArray 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>QBitArray::operator[] ( int&nbsp;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">QBitArray</a>&nbsp;&amp; <a name="operator^-eq"></a>QBitArray::operator^= ( const&nbsp;<a href="qbitarray.html">QBitArray</a>&nbsp;&amp;&nbsp;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 bit array of the two, with
the bits missing from the shortest array taken as 0.
<p> Example:
<pre>
    QBitArray 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&amp;=</a>(), <a href="#operator|-eq">operator|=</a>() and <a href="#operator~">operator~</a>().

<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 )
</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 bit array of the two, with
the bits missing from the shortest array taken as 0.
<p> Example:
<pre>
    QBitArray 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&amp;=</a>(), <a href="#operator^-eq">operator^=</a>() and <a href="#operator~">operator~</a>().

<h3 class=fn><a href="qbitarray.html">QBitArray</a> <a name="operator~"></a>QBitArray::operator~ () const
</h3>
Returns a bit array that contains the inverted bits of this bit array.
<p> Example:
<pre>
    QBitArray 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>QBitArray::resize ( uint&nbsp;size )
</h3>  Resizes the bit array to <em>size</em> bits and returns TRUE if the bit
array could be resized, and FALSE otherwise.
<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>QBitArray::setBit ( uint&nbsp;index, bool&nbsp;value )
</h3>

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>QBitArray::setBit ( uint&nbsp;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> (sets it to 1).
<p>See also <a href="#clearBit">clearBit</a>() and <a href="#toggleBit">toggleBit</a>().

<h3 class=fn>uint <a name="size"></a>QBitArray::size () const
</h3>

Returns the size (number of bits) of the bit array.
<p>See also <a href="#resize">resize</a>().

<h3 class=fn>bool <a name="testBit"></a>QBitArray::testBit ( uint&nbsp;index ) const
</h3>
Returns TRUE if the bit at position <em>index</em> is set, i.e. is 1.
<p>See also <a href="#setBit">setBit</a>() and <a href="#clearBit">clearBit</a>().

<h3 class=fn>bool <a name="toggleBit"></a>QBitArray::toggleBit ( uint&nbsp;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">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 )
</h3>

Returns the AND result between the bit arrays <em>a1</em> and <em>a2</em>.
<p>See also <a href="#operator-and-eq">QBitArray::operator&=</a>().

<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 )
</h3>

Writes bit array <em>a</em> to stream <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<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 )
</h3>

Reads a bit array into <em>a</em> from stream <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<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 )
</h3>

Returns the XOR result between the bit arrays <em>a1</em> and <em>a2</em>.
<p>See also <a href="#operator^">QBitArray::operator^</a>().

<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 )
</h3>

Returns the OR result between the bit arrays <em>a1</em> and <em>a2</em>.
<p>See also <a href="#operator|-eq">QBitArray::operator|=</a>().

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2001
<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 &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>