⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qbitarray.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    Example:    \code        QBitArray a(3);        a[0] = false;        a[1] = true;        a[2] = a[0] ^ a[1];    \endcode    The return value is of type QBitRef, a helper class for QBitArray.    When you get an object of type QBitRef, you can assign to    it, and the assignment will apply to the bit in the QBitArray    from which you got the reference.    The functions testBit(), setBit(), and clearBit() are slightly    faster.    \sa at(), testBit(), setBit(), clearBit()*//*! \fn bool QBitArray::operator[](int i) const    \overload*//*! \fn bool QBitArray::operator[](uint i)    \overload*//*! \fn bool QBitArray::operator[](uint i) const    \overload*//*! \fn QBitArray::QBitArray(const QBitArray &other)    Constructs a copy of \a other.    This operation takes \l{constant time}, because QBitArray is    \l{implicitly shared}. This makes returning a QBitArray from a    function very fast. If a shared instance is modified, it will be    copied (copy-on-write), and that takes \l{linear time}.    \sa operator=()*//*! \fn QBitArray &QBitArray::operator=(const QBitArray &other)    Assigns \a other to this bit array and returns a reference to    this bit array.*//*! \fn bool QBitArray::operator==(const QBitArray &other) const    Returns true if \a other is equal to this bit array; otherwise    returns false.    \sa operator!=()*//*! \fn bool QBitArray::operator!=(const QBitArray &other) const    Returns true if \a other is not equal to this bit array;    otherwise returns false.    \sa operator==()*//*!    Performs the AND operation between all bits in this bit array and    \a other. Assigns the result to this bit array, and returns a    reference to it.    The result has the length of the longest of the two bit arrays,    with any missing bits (if one array is shorter than the other)    taken to be 0.    Example:    \code        QBitArray a(3);        QBitArray b(2);        a[0] = 1; a[1] = 0; a[2] = 1;   // a: [ 1, 0, 1 ]        b[0] = 1; b[1] = 0;             // b: [ 1, 1 ]        a &= b;                         // a: [ 1, 0, 0 ]    \endcode    \sa operator&(), operator|=(), operator^=(), operator~()*/QBitArray &QBitArray::operator&=(const QBitArray &other){    resize(qMax(size(), other.size()));    uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1;    const uchar *a2 = reinterpret_cast<const uchar*>(other.d.constData()) + 1;    int n = other.d.size() -1 ;     int p = d.size() - 1 - n;    while (n-- > 0)        *a1++ &= *a2++;    while (p-- > 0)        *a1++ = 0;    return *this;}/*!    Performs the OR operation between all bits in this bit array and    \a other. Assigns the result to this bit array, and returns a    reference to it.    The result has the length of the longest of the two bit arrays,    with any missing bits (if one array is shorter than the other)    taken to be 0.    Example:    \code        QBitArray a(3);        QBitArray b(2);        a[0] = 1; a[1] = 0; a[2] = 1;   // a: [ 1, 0, 1 ]        b[0] = 1; b[1] = 0;             // b: [ 1, 1 ]        a |= b;                         // a: [ 1, 1, 1 ]    \endcode    \sa operator|(), operator&=(), operator^=(), operator~()*/QBitArray &QBitArray::operator|=(const QBitArray &other){    resize(qMax(size(), other.size()));    uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1;    const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1;    int n = other.d.size() - 1;       while (n-- > 0)        *a1++ |= *a2++;    return *this;}/*!    Performs the XOR operation between all bits in this bit array and    \a other. Assigns the result to this bit array, and returns a    reference to it.    The result has the length of the longest of the two bit arrays,    with any missing bits (if one array is shorter than the other)    taken to be 0.    Example:    \code        QBitArray a(3);        QBitArray b(2);        a[0] = 1; a[1] = 0; a[2] = 1;   // a: [ 1, 0, 1 ]        b[0] = 1; b[1] = 0;             // b: [ 1, 1 ]        a ^= b;                         // a: [ 0, 1, 1 ]    \endcode    \sa operator^(), operator&=(), operator|=(), operator~()*/QBitArray &QBitArray::operator^=(const QBitArray &other){    resize(qMax(size(), other.size()));    uchar *a1 = reinterpret_cast<uchar*>(d.data()) + 1;    const uchar *a2 = reinterpret_cast<const uchar *>(other.d.constData()) + 1;    int n = other.d.size() - 1;    while (n-- > 0)        *a1++ ^= *a2++;    return *this;}/*!    Returns a bit array that contains the inverted bits of this bit    array.    Example:    \code        QBitArray a(3);        QBitArray b;        a[0] = 1; a[1] = 0; a[2] = 1;   // a: [ 1, 0, 1 ]        b = ~a;                         // b: [ 0, 1, 0 ]    \endcode    \sa operator&(), operator|(), operator^()*/QBitArray QBitArray::operator~() const{    int sz = size();    QBitArray a(sz);    const uchar *a1 = reinterpret_cast<const uchar *>(d.constData()) + 1;    uchar *a2 = reinterpret_cast<uchar*>(a.d.data()) + 1;    int n = d.size() - 1;    while (n-- > 0)        *a2++ = ~*a1++;    if (sz && sz%8)        *(a2-1) &= (1 << (sz%8)) - 1;    return a;}/*!    \relates QBitArray    Returns a bit array that is the AND of the bit arrays \a a1 and \a    a2.    The result has the length of the longest of the two bit arrays,    with any missing bits (if one array is shorter than the other)    taken to be 0.    Example:    \code        QBitArray a(3);        QBitArray b(2);        QBitArray c;        a[0] = 1; a[1] = 0; a[2] = 1;   // a: [ 1, 0, 1 ]        b[0] = 1; b[1] = 0;             // b: [ 1, 1 ]        c = a & b;                      // c: [ 1, 0, 0 ]    \endcode    \sa QBitArray::operator&=(), operator|(), operator^()*/QBitArray operator&(const QBitArray &a1, const QBitArray &a2){    QBitArray tmp = a1;    tmp &= a2;    return tmp;}/*!    \relates QBitArray    Returns a bit array that is the OR of the bit arrays \a a1 and \a    a2.    The result has the length of the longest of the two bit arrays,    with any missing bits (if one array is shorter than the other)    taken to be 0.    Example:    \code        QBitArray a(3);        QBitArray b(2);        QBitArray c;        a[0] = 1; a[1] = 0; a[2] = 1;   // a: [ 1, 0, 1 ]        b[0] = 1; b[1] = 0;             // b: [ 1, 1 ]        c = a | b;                      // c: [ 1, 1, 1 ]    \endcode    \sa QBitArray::operator|=(), operator&(), operator^()*/QBitArray operator|(const QBitArray &a1, const QBitArray &a2){    QBitArray tmp = a1;    tmp |= a2;    return tmp;}/*!    \relates QBitArray    Returns a bit array that is the XOR of the bit arrays \a a1 and \a    a2.    The result has the length of the longest of the two bit arrays,    with any missing bits (if one array is shorter than the other)    taken to be 0.    Example:    \code        QBitArray a(3);        QBitArray b(2);        QBitArray c;        a[0] = 1; a[1] = 0; a[2] = 1;   // a: [ 1, 0, 1 ]        b[0] = 1; b[1] = 0;             // b: [ 1, 1 ]        c = a ^ b;                      // c: [ 0, 1, 1 ]    \endcode    \sa QBitArray::operator^=(), operator&(), operator|()*/QBitArray operator^(const QBitArray &a1, const QBitArray &a2){    QBitArray tmp = a1;    tmp ^= a2;    return tmp;}/*!    \class QBitRef    \reentrant    \brief The QBitRef class is an internal class, used with QBitArray.    \internal    The QBitRef is required by the indexing [] operator on bit arrays.    It is not for use in any other context.*//*! \fn QBitRef::QBitRef (QBitArray& a, int i)    Constructs a reference to element \a i in the QBitArray \a a.    This is what QBitArray::operator[] constructs its return value    with.*//*! \fn QBitRef::operator bool() const    Returns the value referenced by the QBitRef.*//*! \fn bool QBitRef::operator!() const    \internal*//*! \fn QBitRef& QBitRef::operator= (const QBitRef& v)    Sets the value referenced by the QBitRef to that referenced by    QBitRef \a v.*//*! \fn QBitRef& QBitRef::operator= (bool v)    \overload    Sets the value referenced by the QBitRef to \a v.*//*****************************************************************************  QBitArray stream functions *****************************************************************************//*!    \relates QBitArray    Writes bit array \a ba to stream \a out.    \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/#ifndef QT_NO_DATASTREAMQDataStream &operator<<(QDataStream &out, const QBitArray &ba){    quint32 len = ba.size();    out << len;    if (len > 0)        out.writeRawData(ba.d.constData() + 1, ba.d.size() - 1);    return out;}/*!    \relates QBitArray    Reads a bit array into \a ba from stream \a in.    \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream &operator>>(QDataStream &in, QBitArray &ba){    ba.clear();    quint32 len;    in >> len;    if (len == 0) {	ba.clear();	return in;    }    const quint32 Step = 8 * 1024 * 1024;    quint32 totalBytes = (len + 7) / 8;    quint32 allocated = 0;    while (allocated < totalBytes) {        int blockSize = qMin(Step, totalBytes - allocated);        ba.d.resize(allocated + blockSize + 1);        if (in.readRawData(ba.d.data() + 1 + allocated, blockSize) != blockSize) {            ba.clear();            in.setStatus(QDataStream::ReadPastEnd);            return in;        }        allocated += blockSize;    }    int paddingMask = ~((0x1 << (len & 0x7)) - 1);    if (paddingMask != ~0x0 && (ba.d.constData()[ba.d.size() - 1] & paddingMask)) {        ba.clear();        in.setStatus(QDataStream::ReadCorruptData);        return in;    }    *ba.d.data() = ba.d.size() * 8 - len;    return in;}#endif/*!    \fn DataPtr &QBitArray::data_ptr()    \internal*//*!    \typedef QBitArray::DataPtr    \internal*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -