| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qbitarray.h 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Definition of QBitArray class
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 940118
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the tools module of the Qt GUI Toolkit.
|
|---|
| 11 | **
|
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 15 | **
|
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 19 | ** packaging of this file.
|
|---|
| 20 | **
|
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
|
|---|
| 23 | ** Agreement provided with the Software.
|
|---|
| 24 | **
|
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 27 | **
|
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 29 | ** information about Qt Commercial License Agreements.
|
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 32 | **
|
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 34 | ** not clear to you.
|
|---|
| 35 | **
|
|---|
| 36 | **********************************************************************/
|
|---|
| 37 |
|
|---|
| 38 | #ifndef QBITARRAY_H
|
|---|
| 39 | #define QBITARRAY_H
|
|---|
| 40 |
|
|---|
| 41 | #ifndef QT_H
|
|---|
| 42 | #include "qstring.h"
|
|---|
| 43 | #endif // QT_H
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | /*****************************************************************************
|
|---|
| 47 | QBitVal class; a context class for QBitArray::operator[]
|
|---|
| 48 | *****************************************************************************/
|
|---|
| 49 |
|
|---|
| 50 | class QBitArray;
|
|---|
| 51 |
|
|---|
| 52 | class Q_EXPORT QBitVal
|
|---|
| 53 | {
|
|---|
| 54 | private:
|
|---|
| 55 | QBitArray *array;
|
|---|
| 56 | uint index;
|
|---|
| 57 | public:
|
|---|
| 58 | QBitVal( QBitArray *a, uint i ) : array(a), index(i) {}
|
|---|
| 59 | operator int();
|
|---|
| 60 | QBitVal &operator=( const QBitVal &v );
|
|---|
| 61 | QBitVal &operator=( bool v );
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | /*****************************************************************************
|
|---|
| 66 | QBitArray class
|
|---|
| 67 | *****************************************************************************/
|
|---|
| 68 |
|
|---|
| 69 | class Q_EXPORT QBitArray : public QByteArray
|
|---|
| 70 | {
|
|---|
| 71 | public:
|
|---|
| 72 | QBitArray();
|
|---|
| 73 | QBitArray( uint size );
|
|---|
| 74 | QBitArray( const QBitArray &a ) : QByteArray( a ) {}
|
|---|
| 75 |
|
|---|
| 76 | QBitArray &operator=( const QBitArray & );
|
|---|
| 77 |
|
|---|
| 78 | uint size() const;
|
|---|
| 79 | bool resize( uint size );
|
|---|
| 80 |
|
|---|
| 81 | bool fill( bool v, int size = -1 );
|
|---|
| 82 |
|
|---|
| 83 | void detach();
|
|---|
| 84 | QBitArray copy() const;
|
|---|
| 85 |
|
|---|
| 86 | bool testBit( uint index ) const;
|
|---|
| 87 | void setBit( uint index );
|
|---|
| 88 | void setBit( uint index, bool value );
|
|---|
| 89 | void clearBit( uint index );
|
|---|
| 90 | bool toggleBit( uint index );
|
|---|
| 91 |
|
|---|
| 92 | bool at( uint index ) const;
|
|---|
| 93 | QBitVal operator[]( int index );
|
|---|
| 94 | bool operator[]( int index ) const;
|
|---|
| 95 |
|
|---|
| 96 | QBitArray &operator&=( const QBitArray & );
|
|---|
| 97 | QBitArray &operator|=( const QBitArray & );
|
|---|
| 98 | QBitArray &operator^=( const QBitArray & );
|
|---|
| 99 | QBitArray operator~() const;
|
|---|
| 100 |
|
|---|
| 101 | protected:
|
|---|
| 102 | struct bitarr_data : public QGArray::array_data {
|
|---|
| 103 | uint nbits;
|
|---|
| 104 | };
|
|---|
| 105 | array_data *newData() { return new bitarr_data; }
|
|---|
| 106 | void deleteData( array_data *d ) { delete (bitarr_data*)d; }
|
|---|
| 107 | private:
|
|---|
| 108 | void pad0();
|
|---|
| 109 | };
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | inline QBitArray &QBitArray::operator=( const QBitArray &a )
|
|---|
| 113 | { return (QBitArray&)assign( a ); }
|
|---|
| 114 |
|
|---|
| 115 | inline uint QBitArray::size() const
|
|---|
| 116 | { return ((bitarr_data*)sharedBlock())->nbits; }
|
|---|
| 117 |
|
|---|
| 118 | inline void QBitArray::setBit( uint index, bool value )
|
|---|
| 119 | { if ( value ) setBit(index); else clearBit(index); }
|
|---|
| 120 |
|
|---|
| 121 | inline bool QBitArray::at( uint index ) const
|
|---|
| 122 | { return testBit(index); }
|
|---|
| 123 |
|
|---|
| 124 | inline QBitVal QBitArray::operator[]( int index )
|
|---|
| 125 | { return QBitVal( (QBitArray*)this, index ); }
|
|---|
| 126 |
|
|---|
| 127 | inline bool QBitArray::operator[]( int index ) const
|
|---|
| 128 | { return testBit( index ); }
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | /*****************************************************************************
|
|---|
| 132 | Misc. QBitArray operator functions
|
|---|
| 133 | *****************************************************************************/
|
|---|
| 134 |
|
|---|
| 135 | Q_EXPORT QBitArray operator&( const QBitArray &, const QBitArray & );
|
|---|
| 136 | Q_EXPORT QBitArray operator|( const QBitArray &, const QBitArray & );
|
|---|
| 137 | Q_EXPORT QBitArray operator^( const QBitArray &, const QBitArray & );
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | inline QBitVal::operator int()
|
|---|
| 141 | {
|
|---|
| 142 | return array->testBit( index );
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | inline QBitVal &QBitVal::operator=( const QBitVal &v )
|
|---|
| 146 | {
|
|---|
| 147 | array->setBit( index, v.array->testBit(v.index) );
|
|---|
| 148 | return *this;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | inline QBitVal &QBitVal::operator=( bool v )
|
|---|
| 152 | {
|
|---|
| 153 | array->setBit( index, v );
|
|---|
| 154 | return *this;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | /*****************************************************************************
|
|---|
| 159 | QBitArray stream functions
|
|---|
| 160 | *****************************************************************************/
|
|---|
| 161 | #ifndef QT_NO_DATASTREAM
|
|---|
| 162 | Q_EXPORT QDataStream &operator<<( QDataStream &, const QBitArray & );
|
|---|
| 163 | Q_EXPORT QDataStream &operator>>( QDataStream &, QBitArray & );
|
|---|
| 164 | #endif
|
|---|
| 165 |
|
|---|
| 166 | #endif // QBITARRAY_H
|
|---|