61 #ifndef GAIA_QVARLENGTHARRAY_H 62 #define GAIA_QVARLENGTHARRAY_H 64 #include <QtCore/qcontainerfwd.h> 65 #include <QtCore/qglobal.h> 76 template<class T,
int Prealloc>
80 inline explicit GVarLengthArray(
int size = 0);
83 : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array))
85 append(other.constData(), other.size());
88 inline ~GVarLengthArray() {
89 if (QTypeInfo<T>::isComplex) {
94 if (ptr != reinterpret_cast<T *>(array))
101 append(other.constData(), other.size());
106 inline void removeLast() {
110 inline int size()
const {
return s; }
111 inline int count()
const {
return s; }
112 inline bool isEmpty()
const {
return (s == 0); }
113 inline void resize(
int size);
114 inline void clear() { resize(0); }
116 inline int capacity()
const {
return a; }
117 inline void reserve(
int size);
119 inline T &operator[](
int idx) {
120 Q_ASSERT(idx >= 0 && idx < s);
123 inline const T &operator[](
int idx)
const {
124 Q_ASSERT(idx >= 0 && idx < s);
128 inline void append(
const T &t) {
132 if (QTypeInfo<T>::isComplex) {
133 new (ptr + idx) T(t);
138 void append(
const T *buf,
int size);
140 inline T *data() {
return ptr; }
141 inline const T *data()
const {
return ptr; }
142 inline const T * constData()
const {
return ptr; }
145 void realloc(
int size,
int alloc);
152 char array[
sizeof(qint64) * (((Prealloc *
sizeof(T)) /
sizeof(qint64)) + 1)];
153 qint64 q_for_alignment_1;
154 double q_for_alignment_2;
158 template <
class T,
int Prealloc>
162 ptr =
reinterpret_cast<T *
>(std::malloc(s *
sizeof(T)));
165 ptr =
reinterpret_cast<T *
>(array);
168 if (QTypeInfo<T>::isComplex) {
175 template <
class T,
int Prealloc>
177 { realloc(asize, qMax(asize, a)); }
179 template <
class T,
int Prealloc>
181 {
if (asize > a) realloc(s, asize); }
183 template <
class T,
int Prealloc>
191 const int news = s + asize;
193 realloc(s, qMax(s<<1, news));
196 if (QTypeInfo<T>::isComplex) {
200 new (i++) T(*abuf++);
202 qMemCopy(&ptr[idx], abuf, asize *
sizeof(T));
206 template <
class T,
int Prealloc>
209 Q_ASSERT(aalloc >= asize);
215 ptr =
reinterpret_cast<T *
>(std::malloc(aalloc *
sizeof(T)));
219 if (QTypeInfo<T>::isStatic) {
221 T *j = oldPtr + osize;
227 qMemCopy(ptr, oldPtr, osize *
sizeof(T));
236 if (QTypeInfo<T>::isComplex) {
238 T *i = oldPtr + osize;
239 T *j = oldPtr + asize;
250 if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr)
258 #endif // GAIA_QVARLENGTHARRAY_H Definition: gvarlengtharray.h:77