Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qbitarray.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QBitArray class 00005 ** 00006 ** Created : 940118 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the tools module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QBITARRAY_H 00039 #define QBITARRAY_H 00040 00041 #ifndef QT_H 00042 #include "qstring.h" 00043 #endif // QT_H 00044 00045 00046 /***************************************************************************** 00047 QBitVal class; a context class for QBitArray::operator[] 00048 *****************************************************************************/ 00049 00050 class QBitArray; 00051 00052 class Q_EXPORT QBitVal 00053 { 00054 private: 00055 QBitArray *array; 00056 uint index; 00057 public: 00058 QBitVal( QBitArray *a, uint i ) : array(a), index(i) {} 00059 operator int(); 00060 QBitVal &operator=( const QBitVal &v ); 00061 QBitVal &operator=( bool v ); 00062 }; 00063 00064 00065 /***************************************************************************** 00066 QBitArray class 00067 *****************************************************************************/ 00068 00069 class Q_EXPORT QBitArray : public QByteArray 00070 { 00071 public: 00072 QBitArray(); 00073 QBitArray( uint size ); 00074 QBitArray( const QBitArray &a ) : QByteArray( a ) {} 00075 00076 QBitArray &operator=( const QBitArray & ); 00077 00078 uint size() const; 00079 bool resize( uint size ); 00080 00081 bool fill( bool v, int size = -1 ); 00082 00083 void detach(); 00084 QBitArray copy() const; 00085 00086 bool testBit( uint index ) const; 00087 void setBit( uint index ); 00088 void setBit( uint index, bool value ); 00089 void clearBit( uint index ); 00090 bool toggleBit( uint index ); 00091 00092 bool at( uint index ) const; 00093 QBitVal operator[]( int index ); 00094 bool operator[]( int index ) const; 00095 00096 QBitArray &operator&=( const QBitArray & ); 00097 QBitArray &operator|=( const QBitArray & ); 00098 QBitArray &operator^=( const QBitArray & ); 00099 QBitArray operator~() const; 00100 00101 protected: 00102 struct bitarr_data : public QGArray::array_data { 00103 uint nbits; 00104 }; 00105 array_data *newData() { return new bitarr_data; } 00106 void deleteData( array_data *d ) { delete (bitarr_data*)d; } 00107 private: 00108 void pad0(); 00109 }; 00110 00111 00112 inline QBitArray &QBitArray::operator=( const QBitArray &a ) 00113 { return (QBitArray&)assign( a ); } 00114 00115 inline uint QBitArray::size() const 00116 { return ((bitarr_data*)sharedBlock())->nbits; } 00117 00118 inline void QBitArray::setBit( uint index, bool value ) 00119 { if ( value ) setBit(index); else clearBit(index); } 00120 00121 inline bool QBitArray::at( uint index ) const 00122 { return testBit(index); } 00123 00124 inline QBitVal QBitArray::operator[]( int index ) 00125 { return QBitVal( (QBitArray*)this, index ); } 00126 00127 inline bool QBitArray::operator[]( int index ) const 00128 { return testBit( index ); } 00129 00130 00131 /***************************************************************************** 00132 Misc. QBitArray operator functions 00133 *****************************************************************************/ 00134 00135 Q_EXPORT QBitArray operator&( const QBitArray &, const QBitArray & ); 00136 Q_EXPORT QBitArray operator|( const QBitArray &, const QBitArray & ); 00137 Q_EXPORT QBitArray operator^( const QBitArray &, const QBitArray & ); 00138 00139 00140 inline QBitVal::operator int() 00141 { 00142 return array->testBit( index ); 00143 } 00144 00145 inline QBitVal &QBitVal::operator=( const QBitVal &v ) 00146 { 00147 array->setBit( index, v.array->testBit(v.index) ); 00148 return *this; 00149 } 00150 00151 inline QBitVal &QBitVal::operator=( bool v ) 00152 { 00153 array->setBit( index, v ); 00154 return *this; 00155 } 00156 00157 00158 /***************************************************************************** 00159 QBitArray stream functions 00160 *****************************************************************************/ 00161 #ifndef QT_NO_DATASTREAM 00162 Q_EXPORT QDataStream &operator<<( QDataStream &, const QBitArray & ); 00163 Q_EXPORT QDataStream &operator>>( QDataStream &, QBitArray & ); 00164 #endif 00165 00166 #endif // QBITARRAY_H