QVarLengthArray< T, Prealloc > Class Template Reference

QVarLengthArray< T, Prealloc > Class Template Reference

#include <qcontainerfwd.h>

Class Description

template<class T, int Prealloc>
class QVarLengthArray< T, Prealloc >

Definition at line 64 of file qcontainerfwd.h.

Public Types

typedef int size_type
 
typedef T value_type
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef qptrdiff difference_type
 
typedef T * iterator
 
typedef const T * const_iterator
 

Public Member Functions

 QVarLengthArray (int size=0)
 
 QVarLengthArray (const QVarLengthArray< T, Prealloc > &other)
 
 ~QVarLengthArray ()
 
QVarLengthArray< T, Prealloc > & operator= (const QVarLengthArray< T, Prealloc > &other)
 
void removeLast ()
 
int size () const
 
int count () const
 
bool isEmpty () const
 
void resize (int size)
 
void clear ()
 
int capacity () const
 
void reserve (int size)
 
T & operator[] (int idx)
 
const T & operator[] (int idx) const
 
const T & at (int idx) const
 
value (int i) const
 
value (int i, const T &defaultValue) const
 
void append (const T &t)
 
void append (const T *buf, int size)
 
QVarLengthArray< T, Prealloc > & operator<< (const T &t)
 
QVarLengthArray< T, Prealloc > & operator+= (const T &t)
 
void prepend (const T &t)
 
void insert (int i, const T &t)
 
void insert (int i, int n, const T &t)
 
void replace (int i, const T &t)
 
void remove (int i)
 
void remove (int i, int n)
 
T * data ()
 
const T * data () const
 
const T * constData () const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator constBegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator constEnd () const
 
iterator insert (iterator before, int n, const T &x)
 
iterator insert (iterator before, const T &x)
 
iterator erase (iterator begin, iterator end)
 
iterator erase (iterator pos)
 

Friends

class QPodList< T, Prealloc >
 

Member Typedef Documentation

typedef int size_type

Definition at line 145 of file qvarlengtharray.h.

typedef T value_type

Definition at line 146 of file qvarlengtharray.h.

typedef value_type* pointer

Definition at line 147 of file qvarlengtharray.h.

typedef const value_type* const_pointer

Definition at line 148 of file qvarlengtharray.h.

Definition at line 149 of file qvarlengtharray.h.

typedef const value_type& const_reference

Definition at line 150 of file qvarlengtharray.h.

typedef qptrdiff difference_type

Definition at line 151 of file qvarlengtharray.h.

typedef T* iterator

Definition at line 154 of file qvarlengtharray.h.

typedef const T* const_iterator

Definition at line 155 of file qvarlengtharray.h.

Constructor & Destructor Documentation

Q_INLINE_TEMPLATE QVarLengthArray ( int  size = 0)
inlineexplicit

Definition at line 184 of file qvarlengtharray.h.

185  : s(asize) {
186  if (s > Prealloc) {
187  ptr = reinterpret_cast<T *>(qMalloc(s * sizeof(T)));
188  Q_CHECK_PTR(ptr);
189  a = s;
190  } else {
191  ptr = reinterpret_cast<T *>(array);
192  a = Prealloc;
193  }
194  if (QTypeInfo<T>::isComplex) {
195  T *i = ptr + s;
196  while (i != ptr)
197  new (--i) T;
198  }
199 }
char array[sizeof(qint64)*(((Prealloc *sizeof(T))/sizeof(qint64))+1)]
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
GLdouble s
Definition: GLee.h:1173
QVarLengthArray ( const QVarLengthArray< T, Prealloc > &  other)
inline

Definition at line 68 of file qvarlengtharray.h.

69  : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array))
70  {
71  append(other.constData(), other.size());
72  }
char array[sizeof(qint64)*(((Prealloc *sizeof(T))/sizeof(qint64))+1)]
void append(const T &t)
const T * constData() const
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
int size() const
GLdouble s
Definition: GLee.h:1173
~QVarLengthArray ( )
inline

Definition at line 74 of file qvarlengtharray.h.

74  {
75  if (QTypeInfo<T>::isComplex) {
76  T *i = ptr + s;
77  while (i-- != ptr)
78  i->~T();
79  }
80  if (ptr != reinterpret_cast<T *>(array))
81  qFree(ptr);
82  }
char array[sizeof(qint64)*(((Prealloc *sizeof(T))/sizeof(qint64))+1)]
GLdouble s
Definition: GLee.h:1173

Member Function Documentation

QVarLengthArray<T, Prealloc>& operator= ( const QVarLengthArray< T, Prealloc > &  other)
inline

Definition at line 83 of file qvarlengtharray.h.

84  {
85  if (this != &other) {
86  clear();
87  append(other.constData(), other.size());
88  }
89  return *this;
90  }
void append(const T &t)
const T * constData() const
int size() const
void removeLast ( )
inline

Definition at line 92 of file qvarlengtharray.h.

92  {
93  Q_ASSERT(s > 0);
94  realloc(s - 1, a);
95  }
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
GLdouble s
Definition: GLee.h:1173
int size ( ) const
inline

Definition at line 96 of file qvarlengtharray.h.

96 { return s; }
GLdouble s
Definition: GLee.h:1173
int count ( ) const
inline

Definition at line 97 of file qvarlengtharray.h.

97 { return s; }
GLdouble s
Definition: GLee.h:1173
bool isEmpty ( ) const
inline

Definition at line 98 of file qvarlengtharray.h.

98 { return (s == 0); }
GLdouble s
Definition: GLee.h:1173
Q_INLINE_TEMPLATE void resize ( int  size)
inline

Definition at line 202 of file qvarlengtharray.h.

203 { realloc(asize, qMax(asize, a)); }
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
void clear ( )
inline

Definition at line 100 of file qvarlengtharray.h.

100 { resize(0); }
void resize(int size)
int capacity ( ) const
inline

Definition at line 102 of file qvarlengtharray.h.

102 { return a; }
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
Q_INLINE_TEMPLATE void reserve ( int  size)
inline

Definition at line 206 of file qvarlengtharray.h.

207 { if (asize > a) realloc(s, asize); }
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
GLdouble s
Definition: GLee.h:1173
T& operator[] ( int  idx)
inline

Definition at line 105 of file qvarlengtharray.h.

105  {
106  Q_ASSERT(idx >= 0 && idx < s);
107  return ptr[idx];
108  }
GLdouble s
Definition: GLee.h:1173
const T& operator[] ( int  idx) const
inline

Definition at line 109 of file qvarlengtharray.h.

109  {
110  Q_ASSERT(idx >= 0 && idx < s);
111  return ptr[idx];
112  }
GLdouble s
Definition: GLee.h:1173
const T& at ( int  idx) const
inline

Definition at line 113 of file qvarlengtharray.h.

113 { return operator[](idx); }
T & operator[](int idx)
Q_OUTOFLINE_TEMPLATE T value ( int  i) const

Definition at line 292 of file qvarlengtharray.h.

293 {
294  if (i < 0 || i >= size()) {
295  return T();
296  }
297  return at(i);
298 }
const T & at(int idx) const
int size() const
Q_OUTOFLINE_TEMPLATE T value ( int  i,
const T &  defaultValue 
) const

Definition at line 300 of file qvarlengtharray.h.

301 {
302  return (i < 0 || i >= size()) ? defaultValue : at(i);
303 }
const T & at(int idx) const
int size() const
void append ( const T &  t)
inline

Definition at line 118 of file qvarlengtharray.h.

118  {
119  if (s == a) // i.e. s != 0
120  realloc(s, s<<1);
121  const int idx = s++;
122  if (QTypeInfo<T>::isComplex) {
123  new (ptr + idx) T(t);
124  } else {
125  ptr[idx] = t;
126  }
127  }
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
GLdouble GLdouble t
Definition: GLee.h:1181
GLdouble s
Definition: GLee.h:1173
Q_OUTOFLINE_TEMPLATE void append ( const T *  buf,
int  size 
)

Definition at line 210 of file qvarlengtharray.h.

211 {
212  Q_ASSERT(abuf);
213  if (increment <= 0)
214  return;
215 
216  const int asize = s + increment;
217 
218  if (asize >= a)
219  realloc(s, qMax(s*2, asize));
220 
221  if (QTypeInfo<T>::isComplex) {
222  // call constructor for new objects (which can throw)
223  while (s < asize)
224  new (ptr+(s++)) T(*abuf++);
225  } else {
226  qMemCopy(&ptr[s], abuf, increment * sizeof(T));
227  s = asize;
228  }
229 }
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
GLdouble s
Definition: GLee.h:1173
QVarLengthArray<T, Prealloc>& operator<< ( const T &  t)
inline

Definition at line 129 of file qvarlengtharray.h.

130  { append(t); return *this; }
void append(const T &t)
GLdouble GLdouble t
Definition: GLee.h:1181
QVarLengthArray<T, Prealloc>& operator+= ( const T &  t)
inline

Definition at line 131 of file qvarlengtharray.h.

132  { append(t); return *this; }
void append(const T &t)
GLdouble GLdouble t
Definition: GLee.h:1181
void prepend ( const T &  t)
inline

Definition at line 322 of file qvarlengtharray.h.

323 { insert(begin(), 1, t); }
void insert(int i, const T &t)
GLdouble GLdouble t
Definition: GLee.h:1181
void insert ( int  i,
const T &  t 
)
inline

Definition at line 306 of file qvarlengtharray.h.

307 { Q_ASSERT_X(i >= 0 && i <= s, "QVarLengthArray::insert", "index out of range");
308  insert(begin() + i, 1, t); }
void insert(int i, const T &t)
GLdouble GLdouble t
Definition: GLee.h:1181
GLdouble s
Definition: GLee.h:1173
void insert ( int  i,
int  n,
const T &  t 
)
inline

Definition at line 310 of file qvarlengtharray.h.

311 { Q_ASSERT_X(i >= 0 && i <= s, "QVarLengthArray::insert", "index out of range");
312  insert(begin() + i, n, t); }
void insert(int i, const T &t)
GLenum GLsizei n
Definition: GLee.h:3432
GLdouble GLdouble t
Definition: GLee.h:1181
GLdouble s
Definition: GLee.h:1173
void replace ( int  i,
const T &  t 
)
inline

Definition at line 326 of file qvarlengtharray.h.

327 {
328  Q_ASSERT_X(i >= 0 && i < s, "QVarLengthArray::replace", "index out of range");
329  const T copy(t);
330  data()[i] = copy;
331 }
GLdouble GLdouble t
Definition: GLee.h:1181
GLdouble s
Definition: GLee.h:1173
void remove ( int  i)
inline

Definition at line 318 of file qvarlengtharray.h.

319 { Q_ASSERT_X(i >= 0 && i < s, "QVarLengthArray::remove", "index out of range");
320  erase(begin() + i, begin() + i + 1); }
iterator erase(iterator begin, iterator end)
GLdouble s
Definition: GLee.h:1173
void remove ( int  i,
int  n 
)
inline

Definition at line 314 of file qvarlengtharray.h.

315 { Q_ASSERT_X(i >= 0 && n >= 0 && i + n <= s, "QVarLengthArray::remove", "index out of range");
316  erase(begin() + i, begin() + i + n); }
GLenum GLsizei n
Definition: GLee.h:3432
iterator erase(iterator begin, iterator end)
GLdouble s
Definition: GLee.h:1173
T* data ( )
inline

Definition at line 142 of file qvarlengtharray.h.

142 { return ptr; }
const T* data ( ) const
inline

Definition at line 143 of file qvarlengtharray.h.

143 { return ptr; }
const T* constData ( ) const
inline

Definition at line 144 of file qvarlengtharray.h.

144 { return ptr; }
iterator begin ( )
inline

Definition at line 157 of file qvarlengtharray.h.

157 { return ptr; }
const_iterator begin ( ) const
inline

Definition at line 158 of file qvarlengtharray.h.

158 { return ptr; }
const_iterator constBegin ( ) const
inline

Definition at line 159 of file qvarlengtharray.h.

159 { return ptr; }
iterator end ( )
inline

Definition at line 160 of file qvarlengtharray.h.

160 { return ptr + s; }
GLdouble s
Definition: GLee.h:1173
const_iterator end ( ) const
inline

Definition at line 161 of file qvarlengtharray.h.

161 { return ptr + s; }
GLdouble s
Definition: GLee.h:1173
const_iterator constEnd ( ) const
inline

Definition at line 162 of file qvarlengtharray.h.

162 { return ptr + s; }
GLdouble s
Definition: GLee.h:1173
Q_OUTOFLINE_TEMPLATE QVarLengthArray< T, Prealloc >::iterator insert ( iterator  before,
int  n,
const T &  x 
)

Definition at line 335 of file qvarlengtharray.h.

336 {
337  int offset = int(before - ptr);
338  if (n != 0) {
339  resize(s + n);
340  const T copy(t);
341  if (QTypeInfo<T>::isStatic) {
342  T *b = ptr + offset;
343  T *j = ptr + s;
344  T *i = j - n;
345  while (i != b)
346  *--j = *--i;
347  i = b + n;
348  while (i != b)
349  *--i = copy;
350  } else {
351  T *b = ptr + offset;
352  T *i = b + n;
353  memmove(i, b, (s - offset - n) * sizeof(T));
354  while (i != b)
355  new (--i) T(copy);
356  }
357  }
358  return ptr + offset;
359 }
unsigned int(APIENTRYP PFNGLXGETAGPOFFSETMESAPROC)(const void *pointer)
Definition: GLee.h:10762
GLintptr offset
Definition: GLee.h:1562
GLenum GLsizei n
Definition: GLee.h:3432
GLubyte GLubyte b
Definition: GLee.h:5404
void resize(int size)
GLdouble GLdouble t
Definition: GLee.h:1181
GLdouble s
Definition: GLee.h:1173
iterator insert ( iterator  before,
const T &  x 
)
inline

Definition at line 164 of file qvarlengtharray.h.

164 { return insert(before, 1, x); }
void insert(int i, const T &t)
GLenum GLint x
Definition: GLee.h:876
Q_OUTOFLINE_TEMPLATE QVarLengthArray< T, Prealloc >::iterator erase ( iterator  begin,
iterator  end 
)

Definition at line 362 of file qvarlengtharray.h.

363 {
364  int f = int(abegin - ptr);
365  int l = int(aend - ptr);
366  int n = l - f;
367  if (QTypeInfo<T>::isComplex) {
368  qCopy(ptr + l, ptr + s, ptr + f);
369  T *i = ptr + s;
370  T *b = ptr + s - n;
371  while (i != b) {
372  --i;
373  i->~T();
374  }
375  } else {
376  memmove(ptr + f, ptr + l, (s - l) * sizeof(T));
377  }
378  s -= n;
379  return ptr + f;
380 }
unsigned int(APIENTRYP PFNGLXGETAGPOFFSETMESAPROC)(const void *pointer)
Definition: GLee.h:10762
GLenum GLsizei n
Definition: GLee.h:3432
GLubyte GLubyte b
Definition: GLee.h:5404
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
Definition: qalgorithms.h:79
GLdouble s
Definition: GLee.h:1173
GLclampf f
Definition: GLee.h:9303
iterator erase ( iterator  pos)
inline

Definition at line 166 of file qvarlengtharray.h.

166 { return erase(pos, pos+1); }
iterator erase(iterator begin, iterator end)

Friends And Related Function Documentation

friend class QPodList< T, Prealloc >
friend

Definition at line 169 of file qvarlengtharray.h.

Member Data Documentation

char array[sizeof(qint64)*(((Prealloc *sizeof(T))/sizeof(qint64))+1)]

Definition at line 177 of file qvarlengtharray.h.

qint64 q_for_alignment_1

Definition at line 178 of file qvarlengtharray.h.

double q_for_alignment_2

Definition at line 179 of file qvarlengtharray.h.


The documentation for this class was generated from the following files: