00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef QGARRAY_H
00039 #define QGARRAY_H
00040
00041 #ifndef QT_H
00042 #include "qshared.h"
00043 #endif // QT_H
00044
00045
00046 class Q_EXPORT QGArray
00047 {
00048 friend class QBuffer;
00049 public:
00050
00051 struct array_data : public QShared {
00052 array_data():data(0),len(0)
00053 #ifdef QT_QGARRAY_SPEED_OPTIM
00054 ,maxl(0)
00055 #endif
00056 {}
00057 char *data;
00058 uint len;
00059 #ifdef QT_QGARRAY_SPEED_OPTIM
00060 uint maxl;
00061 #endif
00062 };
00063 QGArray();
00064 enum Optimization { MemOptim, SpeedOptim };
00065 protected:
00066 QGArray( int, int );
00067 QGArray( int size );
00068 QGArray( const QGArray &a );
00069 virtual ~QGArray();
00070
00071 QGArray &operator=( const QGArray &a ) { return assign( a ); }
00072
00073 virtual void detach() { duplicate(*this); }
00074
00075
00076 char *data() const { return shd->data; }
00077 uint nrefs() const { return shd->count; }
00078 uint size() const { return shd->len; }
00079 bool isEqual( const QGArray &a ) const;
00080
00081 bool resize( uint newsize, Optimization optim );
00082 bool resize( uint newsize );
00083
00084 bool fill( const char *d, int len, uint sz );
00085
00086 QGArray &assign( const QGArray &a );
00087 QGArray &assign( const char *d, uint len );
00088 QGArray &duplicate( const QGArray &a );
00089 QGArray &duplicate( const char *d, uint len );
00090 void store( const char *d, uint len );
00091
00092 array_data *sharedBlock() const { return shd; }
00093 void setSharedBlock( array_data *p ) { shd=(array_data*)p; }
00094
00095 QGArray &setRawData( const char *d, uint len );
00096 void resetRawData( const char *d, uint len );
00097
00098 int find( const char *d, uint index, uint sz ) const;
00099 int contains( const char *d, uint sz ) const;
00100
00101 void sort( uint sz );
00102 int bsearch( const char *d, uint sz ) const;
00103
00104 char *at( uint index ) const;
00105
00106 bool setExpand( uint index, const char *d, uint sz );
00107
00108 protected:
00109 virtual array_data *newData();
00110 virtual void deleteData( array_data *p );
00111
00112 private:
00113 static void msg_index( uint );
00114 array_data *shd;
00115 };
00116
00117
00118 inline char *QGArray::at( uint index ) const
00119 {
00120 #if defined(QT_CHECK_RANGE)
00121 if ( index >= size() ) {
00122 msg_index( index );
00123 index = 0;
00124 }
00125 #endif
00126 return &shd->data[index];
00127 }
00128
00129
00130 #endif // QGARRAY_H