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 QMEMARRAY_H
00039 #define QMEMARRAY_H
00040
00041 #ifndef QT_H
00042 #include "qgarray.h"
00043 #endif // QT_H
00044
00045
00046 template<class type>
00047 class QMemArray : public QGArray
00048 {
00049 public:
00050 typedef type* Iterator;
00051 typedef const type* ConstIterator;
00052 typedef type ValueType;
00053
00054 protected:
00055 QMemArray( int, int ) : QGArray( 0, 0 ) {}
00056
00057 public:
00058 QMemArray() {}
00059 QMemArray( int size ) : QGArray(size*sizeof(type)) {}
00060 QMemArray( const QMemArray<type> &a ) : QGArray(a) {}
00061 ~QMemArray() {}
00062 QMemArray<type> &operator=(const QMemArray<type> &a)
00063 { return (QMemArray<type>&)QGArray::assign(a); }
00064 type *data() const { return (type *)QGArray::data(); }
00065 uint nrefs() const { return QGArray::nrefs(); }
00066 uint size() const { return QGArray::size()/sizeof(type); }
00067 uint count() const { return size(); }
00068 bool isEmpty() const { return QGArray::size() == 0; }
00069 bool isNull() const { return QGArray::data() == 0; }
00070 bool resize( uint size ) { return QGArray::resize(size*sizeof(type)); }
00071 bool resize( uint size, Optimization optim ) { return QGArray::resize(size*sizeof(type), optim); }
00072 bool truncate( uint pos ) { return QGArray::resize(pos*sizeof(type)); }
00073 bool fill( const type &d, int size = -1 )
00074 { return QGArray::fill((char*)&d,size,sizeof(type) ); }
00075 void detach() { QGArray::detach(); }
00076 QMemArray<type> copy() const
00077 { QMemArray<type> tmp; return tmp.duplicate(*this); }
00078 QMemArray<type>& assign( const QMemArray<type>& a )
00079 { return (QMemArray<type>&)QGArray::assign(a); }
00080 QMemArray<type>& assign( const type *a, uint n )
00081 { return (QMemArray<type>&)QGArray::assign((char*)a,n*sizeof(type)); }
00082 QMemArray<type>& duplicate( const QMemArray<type>& a )
00083 { return (QMemArray<type>&)QGArray::duplicate(a); }
00084 QMemArray<type>& duplicate( const type *a, uint n )
00085 { return (QMemArray<type>&)QGArray::duplicate((char*)a,n*sizeof(type)); }
00086 QMemArray<type>& setRawData( const type *a, uint n )
00087 { return (QMemArray<type>&)QGArray::setRawData((char*)a,
00088 n*sizeof(type)); }
00089 void resetRawData( const type *a, uint n )
00090 { QGArray::resetRawData((char*)a,n*sizeof(type)); }
00091 int find( const type &d, uint i=0 ) const
00092 { return QGArray::find((char*)&d,i,sizeof(type)); }
00093 int contains( const type &d ) const
00094 { return QGArray::contains((char*)&d,sizeof(type)); }
00095 void sort() { QGArray::sort(sizeof(type)); }
00096 int bsearch( const type &d ) const
00097 { return QGArray::bsearch((const char*)&d,sizeof(type)); }
00098
00099 type& operator[]( int i ) const
00100 { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }
00101 type& at( uint i ) const
00102 { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }
00103 operator const type*() const { return (const type *)QGArray::data(); }
00104 bool operator==( const QMemArray<type> &a ) const { return isEqual(a); }
00105 bool operator!=( const QMemArray<type> &a ) const { return !isEqual(a); }
00106 Iterator begin() { return data(); }
00107 Iterator end() { return data() + size(); }
00108 ConstIterator begin() const { return data(); }
00109 ConstIterator end() const { return data() + size(); }
00110 };
00111
00112 #ifndef QT_QWINEXPORT
00113 #if defined(Q_TEMPLATEDLL)
00114
00115 Q_TEMPLATE_EXTERN template class Q_EXPORT QMemArray<int>;
00116 Q_TEMPLATE_EXTERN template class Q_EXPORT QMemArray<bool>;
00117
00118 #endif
00119 #endif
00120
00121 #ifndef QT_NO_COMPAT
00122 #define QArray QMemArray
00123 #endif
00124
00125 #ifdef QT_QWINEXPORT
00126 #define Q_DEFINED_QMEMARRAY
00127 #include <qwinexport.h>
00128 #endif
00129 #endif // QARRAY_H