Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QBitArray Class Reference

The QBitArray class provides an array of bits. More...

#include </home/clem/local/src/opie/qmake/include/qbitarray.h>

Inheritance diagram for QBitArray:

Inheritance graph
[legend]
Collaboration diagram for QBitArray:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 QBitArray ()
 QBitArray (uint size)
 QBitArray (const QBitArray &a)
QBitArrayoperator= (const QBitArray &)
uint size () const
bool resize (uint size)
bool fill (bool v, int size=-1)
void detach ()
QBitArray copy () const
bool testBit (uint index) const
void setBit (uint index)
void setBit (uint index, bool value)
void clearBit (uint index)
bool toggleBit (uint index)
bool at (uint index) const
QBitVal operator[] (int index)
bool operator[] (int index) const
QBitArrayoperator &= (const QBitArray &)
QBitArrayoperator|= (const QBitArray &)
QBitArrayoperator^= (const QBitArray &)
QBitArray operator~ () const

Protected Member Functions

array_data * newData ()
void deleteData (array_data *d)

Private Member Functions

void pad0 ()

Related Functions

(Note that these are not member functions.)

QBitArray operator & (const QBitArray &a1, const QBitArray &a2)
QBitArray operator| (const QBitArray &a1, const QBitArray &a2)
QBitArray operator^ (const QBitArray &a1, const QBitArray &a2)
QDataStreamoperator<< (QDataStream &s, const QBitArray &a)
QDataStreamoperator>> (QDataStream &s, QBitArray &a)

Classes

struct  bitarr_data
 The QBitArray::bitarr_data class is internal. More...

Detailed Description

The QBitArray class provides an array of bits.

Because QBitArray is a QMemArray, it uses explicit sharing with a reference count.

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.

Bits can be manipulated by the setBit() and clearBit() 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.

Example:

    QBitArray a(3);
    a.setBit( 0 );
    a.clearBit( 1 );
    a.setBit( 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 & b;        // c = [0 1 0]

When a QBitArray is constructed the bits are uninitialized. Use fill() to set all the bits to 0 or 1. The array can be resized with resize() and copied with copy(). Bits can be set with setBit() and cleared with clearBit(). Bits can be toggled with toggleBit(). A bit's value can be obtained with testBit() and with at().

QBitArray supports the & (AND), | (OR), ^ (XOR) and ~ (NOT) operators.

Definition at line 69 of file qbitarray.h.


Constructor & Destructor Documentation

QBitArray::QBitArray  ) 
 

Constructs an empty bit array.

Definition at line 142 of file qbitarray.cpp.

References QBitArray::bitarr_data::nbits, and Opie::MM::x.

QBitArray::QBitArray uint  size  ) 
 

Constructs a bit array of size bits. The bits are uninitialized.

See also:
fill()

Definition at line 156 of file qbitarray.cpp.

References QBitArray::bitarr_data::nbits, resize(), and Opie::MM::x.

QBitArray::QBitArray const QBitArray a  )  [inline]
 

Constructs a shallow copy of a.

Definition at line 74 of file qbitarray.h.


Member Function Documentation

bool QBitArray::at uint  index  )  const [inline]
 

Returns the value (0 or 1) of the bit at position index.

See also:
operator[]()

Definition at line 121 of file qbitarray.h.

References testBit().

void QBitArray::clearBit uint  index  ) 
 

Clears the bit at position index, i.e. sets it to 0.

See also:
setBit(), toggleBit()

Definition at line 344 of file qbitarray.cpp.

References data, qWarning(), and size().

Referenced by Referee::demo(), Referee::introPlay(), Referee::killedPlay(), Referee::levelUpPlay(), Referee::pause(), Referee::ready(), setBit(), and Referee::start().

QBitArray QBitArray::copy  )  const
 

Returns a deep copy of the bit array.

See also:
detach()

Definition at line 276 of file qbitarray.cpp.

References SHBLOCK.

Referenced by operator &(), operator^(), and operator|().

void QBitArray::deleteData array_data *  d  )  [inline, protected]
 

For internal use only.

Deletes data specific to QBitArray that extended what QGArray provided.

QPtrCollection mechanism for allowing extra/different data.

Definition at line 106 of file qbitarray.h.

void QBitArray::detach  ) 
 

Detaches from shared bit array data and makes sure that this bit array is the only one referring to the data.

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.

See also:
copy()

Definition at line 263 of file qbitarray.cpp.

References SHBLOCK.

bool QBitArray::fill bool  v,
int  size = -1
 

Fills the bit array with v (1's if v is TRUE, or 0's if v is FALSE).

fill() resizes the bit array to size bits if size is nonnegative.

Returns FALSE if a nonnegative size was specified and the bit array could not be resized; otherwise returns TRUE.

See also:
resize()

Definition at line 236 of file qbitarray.cpp.

References data, FALSE, pad0(), resize(), size(), and TRUE.

Referenced by Referee::demo(), Referee::intro(), QRegExpEngine::matchHere(), Referee::play(), OTodoAccessXML::sup(), OTodoAccessVCal::sup(), and OTodoAccessBackendSQL::sup().

QBitArray::array_data * QBitArray::newData  )  [inline, protected]
 

For internal use only.

Returns data specific to QBitArray that extends what QGArray provides. QPtrCollection mechanism for allowing extra/different data.

Definition at line 105 of file qbitarray.h.

QBitArray & QBitArray::operator &= const QBitArray a  ) 
 

Performs the AND operation between all bits in this bit array and a. Returns a reference to this bit array.

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.

    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 0]

See also:
operator|=(), operator^=(), operator~()

Definition at line 433 of file qbitarray.cpp.

References data, p, resize(), size, and size().

QBitArray & QBitArray::operator= const QBitArray a  )  [inline]
 

Assigns a shallow copy of a to this bit array and returns a reference to this array.

Definition at line 112 of file qbitarray.h.

bool QBitArray::operator[] int  index  )  const [inline]
 

Definition at line 127 of file qbitarray.h.

References testBit().

QBitVal QBitArray::operator[] int  index  )  [inline]
 

Implements the [] operator for bit arrays.

The returned QBitVal is a context object. It makes it possible to get and set a single bit value by its index position.

Example:

    QBitArray a( 3 );
    a[0] = 0;
    a[1] = 1;
    a[2] = a[0] ^ a[1];

The functions testBit(), setBit() and clearBit() are faster.

See also:
at()

Definition at line 124 of file qbitarray.h.

QBitArray & QBitArray::operator^= const QBitArray a  ) 
 

Performs the XOR operation between all bits in this bit array and a. Returns a reference to this bit array.

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.

    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]

See also:
operator&=(), operator|=(), operator~()

Definition at line 492 of file qbitarray.cpp.

References data, resize(), size, and size().

QBitArray & QBitArray::operator|= const QBitArray a  ) 
 

Performs the OR operation between all bits in this bit array and a. Returns a reference to this bit array.

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.

    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]

See also:
operator&=(), operator^=(), operator~()

Definition at line 464 of file qbitarray.cpp.

References data, resize(), size, and size().

QBitArray QBitArray::operator~  )  const
 

Returns a bit array that contains the inverted bits of this bit array.

Example:

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

Definition at line 514 of file qbitarray.cpp.

References data, pad0(), size, and size().

void QBitArray::pad0  )  [private]
 

Pad last byte with 0-bits.

Definition at line 182 of file qbitarray.cpp.

References data, and size().

Referenced by fill(), and operator~().

bool QBitArray::resize uint  size  ) 
 

Resizes the bit array to size bits and returns TRUE if the bit array could be resized; otherwise returns FALSE. The array becomes a null array if size == 0.

If the array is expanded, the new bits are set to 0.

See also:
size()

Definition at line 208 of file qbitarray.cpp.

References data, FALSE, s, SHBLOCK, size(), and TRUE.

Referenced by fill(), Opie::MM::OImageScrollView::OImageScrollView(), operator &=(), operator>>(), operator^=(), operator|=(), QBitArray(), and Referee::Referee().

void QBitArray::setBit uint  index,
bool  value
[inline]
 

Sets the bit at position index to value.

Equivalent to:

    if ( value )
        setBit( index );
    else
        clearBit( index );

See also:
clearBit() toggleBit()

Definition at line 118 of file qbitarray.h.

References clearBit(), and setBit().

void QBitArray::setBit uint  index  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the bit at position index to 1.

See also:
clearBit() toggleBit()

Definition at line 311 of file qbitarray.cpp.

References data, qWarning(), and size().

Referenced by Referee::demo(), Referee::eaten(), Referee::intro(), Referee::killed(), Referee::killedPlay(), Referee::levelUp(), Referee::levelUpPlay(), QRegExpEngine::matchHere(), QBitVal::operator=(), IMAPwrapper::parse_list_result(), Genericwrapper::parseList(), Referee::pause(), Referee::play(), Referee::ready(), Opie::MM::OImageScrollView::setAutoRotate(), Opie::MM::OImageScrollView::setAutoScale(), Opie::MM::OImageScrollView::setAutoScaleRotate(), setBit(), Opie::MM::OImageScrollView::setFirstResizeDone(), Opie::MM::OImageScrollView::setImageIsJpeg(), Opie::MM::OImageScrollView::setImageScaledLoaded(), and Opie::MM::OImageScrollView::setShowZoomer().

uint QBitArray::size  )  const [inline]
 

Returns the bit array's size (number of bits).

See also:
resize()

Definition at line 115 of file qbitarray.h.

Referenced by clearBit(), fill(), operator &=(), operator<<(), operator^=(), operator|=(), operator~(), pad0(), resize(), setBit(), testBit(), and toggleBit().

bool QBitArray::testBit uint  index  )  const
 

Returns TRUE if the bit at position index is set, i.e. is 1; otherwise returns FALSE.

See also:
setBit(), clearBit()

Definition at line 292 of file qbitarray.cpp.

References data, FALSE, qWarning(), and size().

Referenced by at(), Opie::MM::OImageScrollView::AutoRotate(), Opie::MM::OImageScrollView::AutoScale(), Referee::demo(), Referee::eaten(), Opie::MM::OImageScrollView::FirstResizeDone(), Referee::focusInEvent(), Referee::focusOutEvent(), Referee::hallOfFame(), Opie::MM::OImageScrollView::ImageIsJpeg(), Opie::MM::OImageScrollView::ImageScaledLoaded(), Referee::initEnergizers(), Referee::initMonsters(), Referee::initPacman(), Referee::intro(), Referee::introPlay(), Referee::keyPressEvent(), Referee::killed(), Referee::killedPlay(), Referee::levelUpPlay(), QRegExpEngine::matchHere(), QBitVal::operator int(), operator[](), Referee::paintEvent(), IMAPwrapper::parse_list_result(), Referee::pause(), Referee::ready(), Referee::score(), Referee::setScheme(), Opie::MM::OImageScrollView::ShowZoomer(), Referee::start(), and Referee::timerEvent().

bool QBitArray::toggleBit uint  index  ) 
 

Toggles the bit at position index.

If the previous value was 0, the new value will be 1. If the previous value was 1, the new value will be 0.

See also:
setBit(), clearBit()

Definition at line 364 of file qbitarray.cpp.

References data, FALSE, p, qWarning(), and size().

Referenced by Referee::toggleHallOfFame().


Friends And Related Function Documentation

QBitArray operator & const QBitArray a1,
const QBitArray a2
[related]
 

Returns the AND result between the bit arrays a1 and a2.

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.

See also:
QBitArray::operator&=()

Definition at line 539 of file qbitarray.cpp.

References copy().

QDataStream & operator<< QDataStream s,
const QBitArray a
[related]
 

Writes bit array a to stream s.

See also:
Format of the QDataStream operators

Definition at line 630 of file qbitarray.cpp.

References len, size(), and QDataStream::writeRawBytes().

QDataStream & operator>> QDataStream s,
QBitArray a
[related]
 

Reads a bit array into a from stream s.

See also:
Format of the QDataStream operators

Definition at line 647 of file qbitarray.cpp.

References len, qWarning(), QDataStream::readRawBytes(), and resize().

QBitArray operator^ const QBitArray a1,
const QBitArray a2
[related]
 

Returns the XOR result between the bit arrays a1 and a2.

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.

See also:
QBitArray::operator^()

Definition at line 577 of file qbitarray.cpp.

References copy().

QBitArray operator| const QBitArray a1,
const QBitArray a2
[related]
 

Returns the OR result between the bit arrays a1 and a2.

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.

See also:
QBitArray::operator|=()

Definition at line 558 of file qbitarray.cpp.

References copy().


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 17:46:02 2005 for OPIE by  doxygen 1.4.2