<class name="QBitArray" doc="/** <p>The <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> class provides an array of bits.</p> <p>A <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> is an array that gives access to individual bits and provides operators (AND</tt>, OR</tt>, XOR</tt>, and NOT</tt>) that work on entire arrays of bits. It uses implicit sharing</tt> (copy-on-write) to reduce memory usage and to avoid the needless copying of data.</p> <p>The following code constructs a <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> containing 200 bits initialized to false (0):</p> <pre> QBitArray ba(200);</pre> <p>To initialize the bits to true, either pass <tt>true</tt> as second argument to the constructor, or call <a href="QBitArray.html#fill(boolean, int)"><tt>fill</tt></a> later on.</p> <p><a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> uses 0-based indexes, just like C++ arrays. To access the bit at a particular index position, you can use operator[](). On non-const bit arrays, operator[]() returns a reference to a bit that can be used on the left side of an assignment. For example:</p> <pre> QBitArray ba; ba.resize(3); ba[0] = true; ba[1] = false; ba[2] = true;</pre> <p>For technical reasons, it is more efficient to use <a href="QBitArray.html#testBit(int)"><tt>testBit</tt></a> and <a href="QBitArray.html#setBit(int, boolean)"><tt>setBit</tt></a> to access bits in the array than operator[](). For example:</p> <pre> QBitArray ba(3); ba.setBit(0, true); ba.setBit(1, false); ba.setBit(2, true);</pre> <p><a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> supports <tt>&amp;</tt> (AND</tt>), <tt>|</tt> (OR</tt>), <tt>^</tt> (XOR</tt>), <tt>~</tt> (NOT</tt>), as well as <tt>&amp;=</tt>, <tt>|=</tt>, and <tt>^=</tt>. These operators work in the same way as the built-in C++ bitwise operators of the same name. For example:</p> <pre> QBitArray x(5); x.setBit(3, true); <span class="comment"> // x: [ 0, 0, 0, 1, 0 ]</span> QBitArray y(5); y.setBit(4, true); <span class="comment"> // y: [ 0, 0, 0, 0, 1 ]</span> x |= y; <span class="comment"> // x: [ 0, 0, 0, 1, 1 ]</span></pre> <p>For historical reasons, <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> distinguishes between a null bit array and an empty bit array. A <i>null</i> bit array is a bit array that is initialized using <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a>'s default constructor. An <i>empty</i> bit array is any bit array with size 0. A null bit array is always empty, but an empty bit array isn't necessarily null:</p> <pre> QBitArray().isNull(); <span class="comment">// returns true</span> QBitArray().isEmpty(); <span class="comment">// returns true</span> QBitArray(0).isNull(); <span class="comment">// returns false</span> QBitArray(0).isEmpty(); <span class="comment">// returns true</span> QBitArray(3).isNull(); <span class="comment">// returns false</span> QBitArray(3).isEmpty(); <span class="comment">// returns false</span></pre> <p>All functions except <a href="QBitArray.html#isNull()"><tt>isNull</tt></a> treat null bit arrays the same as empty bit arrays; for example, <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> compares equal to <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a>(0). We recommend that you always use <a href="QBitArray.html#isEmpty()"><tt>isEmpty</tt></a> and avoid <a href="QBitArray.html#isNull()"><tt>isNull</tt></a>.</p> @see <a href="QByteArray.html"><tt>QByteArray</tt></a> @see <tt>QVector</tt> */"> <method name="public QBitArray(int size, boolean val)" doc="/** <p>Constructs a bit array containing <tt>size</tt> bits. The bits are initialized with <tt>val</tt>, which defaults to false (0).</p> */"/> <method name="public QBitArray(int size)" doc="/** <p>Equivalent to <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a>(<tt>size</tt>, false). */"/> <method name="public QBitArray(com.trolltech.qt.core.QBitArray other)" doc="/** <p>Constructs a copy of <tt>other</tt>.</p> <p>This operation takes constant time</tt>, because <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> is implicitly shared</tt>. This makes returning a <a href="QBitArray.html#QBitArray()"><tt>QBitArray</tt></a> from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time</tt>.</p> @see <tt>operator=</tt> */"/> <method name="public QBitArray()" doc="/** <p>Constructs an empty bit array.</p> @see <a href="QBitArray.html#isEmpty()"><tt>isEmpty</tt></a> */"/> <method name="public final boolean at(int i)" doc="/** <p>Returns the value of the bit at index position <tt>i</tt>.</p> <p><tt>i</tt> must be a valid index position in the bit array (i.e&#x2e;, 0 &lt;= <tt>i</tt> &lt; <a href="QBitArray.html#size()"><tt>size</tt></a>).</p> @see <tt>operator[]</tt> */"/> <method name="public final void clear()" doc="/** <p>Clears the contents of the bit array and makes it empty.</p> @see <a href="QBitArray.html#resize(int)"><tt>resize</tt></a> @see <a href="QBitArray.html#isEmpty()"><tt>isEmpty</tt></a> */"/> <method name="public final void clearBit(int i)" doc="/** <p>Sets the bit at index position <tt>i</tt> to 0.</p> <p><tt>i</tt> must be a valid index position in the bit array (i.e&#x2e;, 0 &lt;= <tt>i</tt> &lt; <a href="QBitArray.html#size()"><tt>size</tt></a>).</p> @see <a href="QBitArray.html#setBit(int, boolean)"><tt>setBit</tt></a> @see <a href="QBitArray.html#toggleBit(int)"><tt>toggleBit</tt></a> */"/> <method name="public final int count(boolean on)" doc="/** <p>If <tt>on</tt> is true, this function returns the number of 1-bits stored in the bit array; otherwise the number of 0-bits is returned.</p> */"/> <method name="public final int count()" doc="/** <p>Same as <a href="QBitArray.html#size()"><tt>size</tt></a>.</p> */"/> <method name="public final void fill(boolean val, int first, int last)" doc="/** <p>Sets bits at index positions <tt>first</tt> up to and excluding <tt>last</tt> to <tt>val</tt>.</p> <p><tt>first</tt> and <tt>last</tt> must be a valid index position in the bit array (i.e&#x2e;, 0 &lt;= <tt>first</tt> &lt;= <a href="QBitArray.html#size()"><tt>size</tt></a> and 0 &lt;= <tt>last</tt> &lt;= <a href="QBitArray.html#size()"><tt>size</tt></a>).</p> */"/> <method name="public final boolean fill(boolean val, int size)" doc="/** <p>Sets every bit in the bit array to <tt>val</tt>, returning true if successful; otherwise returns false. If <tt>size</tt> is different from -1 (the default), the bit array is resized to <tt>size</tt> beforehand.</p> <p>Example:</p> <pre> QBitArray ba(8); ba.fill(true); <span class="comment"> // ba: [ 1, 1, 1, 1, 1, 1, 1, 1 ]</span> ba.fill(false, 2); <span class="comment"> // ba: [ 0, 0 ]</span></pre> @see <a href="QBitArray.html#resize(int)"><tt>resize</tt></a> */"/> <method name="public final boolean fill(boolean val)" doc="/** <p>Equivalent to <a href="QBitArray.html#fill(boolean, int)">fill</tt></a>(<tt>val</tt>, -1). */"/> <method name="public final boolean isEmpty()" doc="/** <p>Returns true if this bit array has size 0; otherwise returns false.</p> @see <a href="QBitArray.html#size()"><tt>size</tt></a> */"/> <method name="public final boolean isNull()" doc="/** <p>Returns true if this bit array is null; otherwise returns false.</p> <p>Example:</p> <pre> QBitArray().isNull(); <span class="comment">// returns true</span> QBitArray(0).isNull(); <span class="comment">// returns false</span> QBitArray(3).isNull(); <span class="comment">// returns false</span></pre> <p>Qt makes a distinction between null bit arrays and empty bit arrays for historical reasons. For most applications, what matters is whether or not a bit array contains any data, and this can be determined using <a href="QBitArray.html#isEmpty()"><tt>isEmpty</tt></a>.</p> @see <a href="QBitArray.html#isEmpty()"><tt>isEmpty</tt></a> */"/> <method name="public final void writeTo(com.trolltech.qt.core.QDataStream arg__1)"/> <method name="public final void readFrom(com.trolltech.qt.core.QDataStream arg__1)"/> <method name="public final void resize(int size)" doc="/** <p>Resizes the bit array to <tt>size</tt> bits.</p> <p>If <tt>size</tt> is greater than the current size, the bit array is extended to make it <tt>size</tt> bits with the extra bits added to the end. The new bits are initialized to false (0).</p> <p>If <tt>size</tt> is less than the current size, bits are removed from the end.</p> @see <a href="QBitArray.html#size()"><tt>size</tt></a> */"/> <method name="public final void setBit(int i)" doc="/** <p>Sets the bit at index position <tt>i</tt> to 1.</p> <p><tt>i</tt> must be a valid index position in the bit array (i.e&#x2e;, 0 &lt;= <tt>i</tt> &lt; <a href="QBitArray.html#size()"><tt>size</tt></a>).</p> @see <a href="QBitArray.html#clearBit(int)"><tt>clearBit</tt></a> @see <a href="QBitArray.html#toggleBit(int)"><tt>toggleBit</tt></a> */"/> <method name="public final void setBit(int i, boolean val)" doc="/** <p>Sets the bit at index position <tt>i</tt> to <tt>val</tt>.</p> */"/> <method name="public final int size()" doc="/** <p>Returns the number of bits stored in the bit array.</p> @see <a href="QBitArray.html#resize(int)"><tt>resize</tt></a> */"/> <method name="public final boolean testBit(int i)" doc="/** <p>Returns true if the bit at index position <tt>i</tt> is 1; otherwise returns false.</p> <p><tt>i</tt> must be a valid index position in the bit array (i.e&#x2e;, 0 &lt;= <tt>i</tt> &lt; <a href="QBitArray.html#size()"><tt>size</tt></a>).</p> @see <a href="QBitArray.html#setBit(int, boolean)"><tt>setBit</tt></a> @see <a href="QBitArray.html#clearBit(int)"><tt>clearBit</tt></a> */"/> <method name="public final boolean toggleBit(int i)" doc="/** <p>Inverts the value of the bit at index position <tt>i</tt>, returning the previous value of that bit as either true (if it was set) or false (if it was unset).</p> <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><tt>i</tt> must be a valid index position in the bit array (i.e&#x2e;, 0 &lt;= <tt>i</tt> &lt; <a href="QBitArray.html#size()"><tt>size</tt></a>).</p> @see <a href="QBitArray.html#setBit(int, boolean)"><tt>setBit</tt></a> @see <a href="QBitArray.html#clearBit(int)"><tt>clearBit</tt></a> */"/> <method name="public final void truncate(int pos)" doc="/** <p>Truncates the bit array at index position <tt>pos</tt>.</p> <p>If <tt>pos</tt> is beyond the end of the array, nothing happens.</p> @see <a href="QBitArray.html#resize(int)"><tt>resize</tt></a> */"/> </class>