Qt 4.8
Public Types | Public Functions | Private Functions | Properties | Friends | List of all members
QVarLengthArray< T, Prealloc > Class Template Reference

#include <qcontainerfwd.h>

Inheritance diagram for QVarLengthArray< T, Prealloc >:
QPodList< T, Prealloc > QPodList< QSockNot *, 32 >

Public Types

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

Public Functions

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

Private Functions

void realloc (int size, int alloc)
 

Properties

union {
   char   array [sizeof(qint64) *(((Prealloc
      *sizeof(T))/sizeof(qint64))+1)]
 
   qint64   q_for_alignment_1
 
   double   q_for_alignment_2
 
}; 
 
int a
 
T * ptr
 
int s
 

Friends

class QPodList< T, Prealloc >
 

Detailed Description

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

Definition at line 64 of file qcontainerfwd.h.

Typedefs

◆ const_iterator

template<class T, int Prealloc>
typedef const T* QVarLengthArray< T, Prealloc >::const_iterator

Definition at line 155 of file qvarlengtharray.h.

◆ const_pointer

template<class T, int Prealloc>
typedef const value_type* QVarLengthArray< T, Prealloc >::const_pointer

Definition at line 148 of file qvarlengtharray.h.

◆ const_reference

template<class T, int Prealloc>
typedef const value_type& QVarLengthArray< T, Prealloc >::const_reference

Definition at line 150 of file qvarlengtharray.h.

◆ difference_type

template<class T, int Prealloc>
typedef qptrdiff QVarLengthArray< T, Prealloc >::difference_type

Definition at line 151 of file qvarlengtharray.h.

◆ iterator

template<class T, int Prealloc>
typedef T* QVarLengthArray< T, Prealloc >::iterator

Definition at line 154 of file qvarlengtharray.h.

◆ pointer

template<class T, int Prealloc>
typedef value_type* QVarLengthArray< T, Prealloc >::pointer

Definition at line 147 of file qvarlengtharray.h.

◆ reference

template<class T, int Prealloc>
typedef value_type& QVarLengthArray< T, Prealloc >::reference

Definition at line 149 of file qvarlengtharray.h.

◆ size_type

template<class T, int Prealloc>
typedef int QVarLengthArray< T, Prealloc >::size_type

Definition at line 145 of file qvarlengtharray.h.

◆ value_type

template<class T, int Prealloc>
typedef T QVarLengthArray< T, Prealloc >::value_type

Definition at line 146 of file qvarlengtharray.h.

Constructors and Destructors

◆ QVarLengthArray() [1/2]

template<class T , int Prealloc>
Q_INLINE_TEMPLATE QVarLengthArray< T, Prealloc >::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  }
195  T *i = ptr + s;
196  while (i != ptr)
197  new (--i) T;
198  }
199 }
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
char array[sizeof(qint64) *(((Prealloc *sizeof(T))/sizeof(qint64))+1)]

◆ QVarLengthArray() [2/2]

template<class T, int Prealloc>
QVarLengthArray< T, Prealloc >::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  }
const T * constData() const
void append(const T &t)
char array[sizeof(qint64) *(((Prealloc *sizeof(T))/sizeof(qint64))+1)]
int size() const

◆ ~QVarLengthArray()

template<class T, int Prealloc>
QVarLengthArray< T, Prealloc >::~QVarLengthArray ( )
inline

Definition at line 74 of file qvarlengtharray.h.

74  {
76  T *i = ptr + s;
77  while (i-- != ptr)
78  i->~T();
79  }
80  if (ptr != reinterpret_cast<T *>(array))
81  qFree(ptr);
82  }
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
char array[sizeof(qint64) *(((Prealloc *sizeof(T))/sizeof(qint64))+1)]

Functions

◆ append() [1/2]

template<class T, int Prealloc>
void QVarLengthArray< T, Prealloc >::append ( const T &  t)
inline

Definition at line 118 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::append(), QTriangulatingStroker::arcPoints(), QGLShader::compileSourceCode(), QVGPixmapConvolutionFilter::draw(), QPlastiqueStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QVGPaintEngine::drawPixmapFragments(), QVGPaintEngine::drawPolygon(), QPlastiqueStyle::drawPrimitive(), QODBCResult::exec(), QOCICols::execBatch(), init(), QTriangulator< T >::ComplexToSimple::insertEdgeIntoVectorIfWanted(), QMetaObject::invokeMethod(), QTextDocumentLayoutPrivate::layoutTable(), QMetaObject::newInstance(), QLocalePrivate::numberToCLocale(), QVarLengthArray< QVariant, 9 >::operator+=(), QVarLengthArray< QVariant, 9 >::operator<<(), QVarLengthArray< QVariant, 9 >::operator=(), QVGPaintEnginePrivate::painterPathToVGPath(), QDBusMetaObjectGenerator::parseMethods(), parseNumbersArray(), parsePathDataFast(), QDBusMetaObjectGenerator::parseSignals(), qDrawBorderPixmap(), QEglProperties::QEglProperties(), QVarLengthArray< QVariant, 9 >::QVarLengthArray(), QCoreApplication::removePostedEvents(), QTriangulator< T >::ComplexToSimple::removeUnwantedEdgesAndConnect(), QDeclarativeJS::Parser::reparseAsQualifiedId(), QWSRegionCommand::setData(), QEglProperties::setValue(), QTextEngine::shapeTextWithHarfbuzz(), QObjectPrivate::signalSignature(), QDBusConnectionPrivate::socketRead(), QDBusConnectionPrivate::socketWrite(), QWidgetBackingStore::sync(), toSQLTCHAR(), and QVGPaintEnginePrivate::vectorPathToVGPath().

118  {
119  if (s == a) // i.e. s != 0
120  realloc(s, s<<1);
121  const int idx = s++;
123  new (ptr + idx) T(t);
124  } else {
125  ptr[idx] = t;
126  }
127  }
void realloc(int size, int alloc)

◆ append() [2/2]

template<class T, int Prealloc>
Q_OUTOFLINE_TEMPLATE void QVarLengthArray< T, Prealloc >::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 
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 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void * qMemCopy(void *dest, const void *src, size_t n)
Definition: qglobal.cpp:2508
void realloc(int size, int alloc)

◆ at()

template<class T, int Prealloc>
const T& QVarLengthArray< T, Prealloc >::at ( int  idx) const
inline

◆ begin() [1/2]

template<class T, int Prealloc>
iterator QVarLengthArray< T, Prealloc >::begin ( )
inline

◆ begin() [2/2]

template<class T, int Prealloc>
const_iterator QVarLengthArray< T, Prealloc >::begin ( ) const
inline

Definition at line 158 of file qvarlengtharray.h.

158 { return ptr; }

◆ capacity()

template<class T, int Prealloc>
int QVarLengthArray< T, Prealloc >::capacity ( ) const
inline

Definition at line 102 of file qvarlengtharray.h.

Referenced by QBBSystemLocaleData::readPpsValue().

102 { return a; }

◆ clear()

template<class T, int Prealloc>
void QVarLengthArray< T, Prealloc >::clear ( )
inline

◆ constBegin()

template<class T, int Prealloc>
const_iterator QVarLengthArray< T, Prealloc >::constBegin ( ) const
inline

Definition at line 159 of file qvarlengtharray.h.

159 { return ptr; }

◆ constData()

template<class T, int Prealloc>
const T* QVarLengthArray< T, Prealloc >::constData ( ) const
inline

Definition at line 144 of file qvarlengtharray.h.

Referenced by blendCursor(), QGLContext::choosePixelFormat(), QODBCDriver::cleanup(), QDeclarativePropertyPrivate::connect(), QObject::connect(), QDeclarativeNotifierEndpoint::disconnect(), QDeclarativeBoundSignal::disconnect(), QObject::disconnect(), QVGPixmapConvolutionFilter::draw(), QPlastiqueStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QX11PaintEngine::drawFreetype(), QOpenGLPaintEngine::drawLines(), drawLines(), QOpenGLPaintEngine::drawPoints(), drawPoints(), QVGPaintEngine::drawPolygon(), QOpenGLPaintEngine::drawPolygon(), QPlastiqueStyle::drawPrimitive(), QRasterPaintEngine::drawTextItem(), QDirectFBPaintEnginePrivate::drawTiledPixmap(), QODBCResult::exec(), fillRects(), fromSQLTCHAR(), QStaticTextPrivate::get(), QMetaObject::invokeMethod(), QSystemLibrary::load(), QMetaObject::newInstance(), QVarLengthArray< QVariant, 9 >::operator=(), QVGPaintEnginePrivate::painterPathToVGPath(), parsePathDataFast(), pfiToQGLFormat(), qGetStringData(), qMakeFieldInfo(), qt_find_latin1_string(), QVarLengthArray< QVariant, 9 >::QVarLengthArray(), qWarnODBCHandle(), QWSRegionCommand::setData(), QGLPixmapConvolutionFilter::setUniforms(), QLocalePrivate::stringToDouble(), QLocalePrivate::stringToLongLong(), QLocalePrivate::stringToUnsLongLong(), QSslSocketBackendPrivate::transmit(), QSystemLocalePrivate::uiLanguages(), and QVGPaintEnginePrivate::vectorPathToVGPath().

144 { return ptr; }

◆ constEnd()

template<class T, int Prealloc>
const_iterator QVarLengthArray< T, Prealloc >::constEnd ( ) const
inline

Definition at line 162 of file qvarlengtharray.h.

162 { return ptr + s; }

◆ count()

template<class T, int Prealloc>
int QVarLengthArray< T, Prealloc >::count ( ) const
inline

◆ data() [1/2]

template<class T, int Prealloc>
T* QVarLengthArray< T, Prealloc >::data ( )
inline

Definition at line 142 of file qvarlengtharray.h.

Referenced by QFontEngineDirectWrite::addGlyphsToPath(), QFontEngine::addOutlineToPath(), QPainterPath::addText(), QRawFont::advancesForGlyphIndexes(), buttonChange(), QScript::callQtMethod(), QProxyFontEngine::canRender(), QFontEngineDirectWrite::canRender(), QDir::cleanPath(), QODBCDriver::cleanup(), QGLShader::compileSourceCode(), convertARGB32_to_RGBA4444(), QWindowsLocalCodec::convertToUnicode(), QSystemLocalePrivate::currencySymbol(), QTextLine::cursorToX(), QGridLayoutRowData::distributeMultiCells(), draw_text_item_win(), QVGPaintEngine::drawCachedGlyphs(), QPainter::drawGlyphRun(), QPainterPrivate::drawGlyphs(), QOpenGLPaintEngine::drawPolygon(), QRasterPaintEngine::drawPolygon(), QPaintEngine::drawPolygon(), QPaintEngineEx::drawPolygon(), QX11PaintEngine::drawRects(), QPainter::drawText(), QGL2PaintEngineEx::drawTextItem(), QOpenGLPaintEngine::drawTextItem(), QVGPaintEngine::drawTextItem(), QDB2Result::exec(), QScript::QObjectConnectionManager::execute(), QIBaseResultPrivate::fetchArray(), QX11PaintEnginePrivate::fillPolygon_dev(), QX11PaintEnginePrivate::fillPolygon_translated(), QSystemLocalePrivate::getLocaleInfo(), QDirectFBScreen::getSurfaceDescription(), QMacInputContext::globalEventProcessor(), init(), init_direct(), QSqlQueryModelPrivate::initColOffsets(), initWritingSystems(), QTextEngine::itemize(), QString::lastIndexOf(), QStringRef::lastIndexOf(), QSystemLibrary::load(), macList(), macValue(), QFileSystemEngine::nativeAbsoluteFilePath(), QNativeSocketEnginePrivate::nativePendingDatagramSize(), QFileSystemModelPrivate::node(), QMetaObject::normalizedSignature(), QMetaObject::normalizedType(), QODBCDriver::open(), QFileSystemEngine::owner(), QDeclarativeParticlesPainter::paint(), pfiToQGLFormat(), QProcessPrivate::processStarted(), PtsToRegion(), QTest::qExec(), qGetBinaryData(), qGetStringData(), qMakeFieldInfo(), qt_format_text(), qt_merge_clip(), QTextLineItemIterator::QTextLineItemIterator(), qtKey2CocoaKey(), qtValue(), qWarnODBCHandle(), QInotifyFileSystemWatcherEngine::readFromInotify(), QConfFileSettingsPrivate::readPlistFile(), QBBSystemLocaleData::readPpsValue(), QFontEngineMac::recalcAdvances(), QProxyFontEngine::recalcAdvances(), QFontEngineDirectWrite::recalcAdvances(), registerFont(), removeGroupSeparators(), QVarLengthArray< QVariant, 9 >::replace(), QFileSystemEngine::resolveGroupName(), QFileSystemEngine::resolveUserName(), QVGCompositionHelper::setScissor(), QGridLayoutPrivate::setupLayoutData(), QTextEngine::shapeTextMac(), sm_performSaveYourself(), QProxyFontEngine::stringToCMap(), QFontEngineDirectWrite::stringToCMap(), QFontEngineXLFD::stringToCMap(), QFontEngineMacMulti::stringToCMapInternal(), QX11PaintEnginePrivate::strokePolygon_dev(), QX11PaintEnginePrivate::strokePolygon_translated(), QEglContext::swapBuffersRegion2NOK(), QSystemLocalePrivate::toCurrencyString(), QApplication::topLevelAt(), toSQLTCHAR(), QSslSocketBackendPrivate::transmit(), QSystemLocalePrivate::uiLanguages(), QVGPaintEngine::updateScissor(), QDBusMetaObjectGenerator::write(), QRfbSingleColorHextile< SRC >::write(), QRfbDualColorHextile< SRC >::write(), QRfbMultiColorHextile< SRC >::write(), and QTextLine::xToCursor().

142 { return ptr; }

◆ data() [2/2]

template<class T, int Prealloc>
const T* QVarLengthArray< T, Prealloc >::data ( ) const
inline

Definition at line 143 of file qvarlengtharray.h.

143 { return ptr; }

◆ end() [1/2]

template<class T, int Prealloc>
iterator QVarLengthArray< T, Prealloc >::end ( )
inline

Definition at line 160 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::insert().

160 { return ptr + s; }

◆ end() [2/2]

template<class T, int Prealloc>
const_iterator QVarLengthArray< T, Prealloc >::end ( ) const
inline

Definition at line 161 of file qvarlengtharray.h.

161 { return ptr + s; }

◆ erase() [1/2]

template<class T , int Prealloc>
Q_OUTOFLINE_TEMPLATE QVarLengthArray< T, Prealloc >::iterator QVarLengthArray< T, Prealloc >::erase ( iterator  begin,
iterator  end 
)

Definition at line 362 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::insert(), and QVarLengthArray< QVariant, 9 >::remove().

363 {
364  int f = int(abegin - ptr);
365  int l = int(aend - ptr);
366  int n = l - f;
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 }
QFactoryLoader * l
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
Definition: qalgorithms.h:79

◆ erase() [2/2]

template<class T, int Prealloc>
iterator QVarLengthArray< T, Prealloc >::erase ( iterator  pos)
inline

Definition at line 166 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::erase().

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

◆ insert() [1/4]

template<class T, int Prealloc>
void QVarLengthArray< T, Prealloc >::insert ( int  i,
const T &  t 
)
inline

Definition at line 306 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::constEnd(), QVarLengthArray< QVariant, 9 >::insert(), QVarLengthArray< QVariant, 9 >::operator+=(), and QVarLengthArray< QVariant, 9 >::prepend().

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)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ insert() [2/4]

template<class T, int Prealloc>
void QVarLengthArray< T, Prealloc >::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)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ insert() [3/4]

template<class T, int Prealloc>
Q_OUTOFLINE_TEMPLATE QVarLengthArray< T, Prealloc >::iterator QVarLengthArray< T, Prealloc >::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);
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 }
void resize(int size)

◆ insert() [4/4]

template<class T, int Prealloc>
iterator QVarLengthArray< T, Prealloc >::insert ( iterator  before,
const T &  x 
)
inline

Definition at line 164 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::insert().

164 { return insert(before, 1, x); }
void insert(int i, const T &t)

◆ isEmpty()

template<class T, int Prealloc>
bool QVarLengthArray< T, Prealloc >::isEmpty ( ) const
inline

◆ operator+=()

template<class T, int Prealloc>
QVarLengthArray<T, Prealloc>& 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)

◆ operator<<()

template<class T, int Prealloc>
QVarLengthArray<T, Prealloc>& 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)

◆ operator=()

template<class T, int Prealloc>
QVarLengthArray<T, Prealloc>& 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  }
const T * constData() const
void append(const T &t)
int size() const

◆ operator[]() [1/2]

template<class T, int Prealloc>
T& QVarLengthArray< T, Prealloc >::operator[] ( int  idx)
inline

Definition at line 105 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::at().

105  {
106  Q_ASSERT(idx >= 0 && idx < s);
107  return ptr[idx];
108  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ operator[]() [2/2]

template<class T, int Prealloc>
const T& QVarLengthArray< T, Prealloc >::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  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ prepend()

template<class T, int Prealloc>
void QVarLengthArray< T, Prealloc >::prepend ( const T &  t)
inline

Definition at line 322 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::operator+=().

323 { insert(begin(), 1, t); }
void insert(int i, const T &t)

◆ realloc()

template<class T , int Prealloc>
Q_OUTOFLINE_TEMPLATE void QVarLengthArray< T, Prealloc >::realloc ( int  size,
int  alloc 
)
private

Definition at line 232 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::append(), QPodList< QSockNot *, 32 >::insert(), QVarLengthArray< QVariant, 9 >::removeLast(), QVarLengthArray< QVariant, 9 >::reserve(), and QVarLengthArray< QVariant, 9 >::resize().

233 {
234  Q_ASSERT(aalloc >= asize);
235  T *oldPtr = ptr;
236  int osize = s;
237 
238  const int copySize = qMin(asize, osize);
239  if (aalloc != a) {
240  ptr = reinterpret_cast<T *>(qMalloc(aalloc * sizeof(T)));
241  Q_CHECK_PTR(ptr);
242  if (ptr) {
243  s = 0;
244  a = aalloc;
245 
247  QT_TRY {
248  // copy all the old elements
249  while (s < copySize) {
250  new (ptr+s) T(*(oldPtr+s));
251  (oldPtr+s)->~T();
252  s++;
253  }
254  } QT_CATCH(...) {
255  // clean up all the old objects and then free the old ptr
256  int sClean = s;
257  while (sClean < osize)
258  (oldPtr+(sClean++))->~T();
259  if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr)
260  qFree(oldPtr);
261  QT_RETHROW;
262  }
263  } else {
264  qMemCopy(ptr, oldPtr, copySize * sizeof(T));
265  }
266  } else {
267  ptr = oldPtr;
268  return;
269  }
270  }
271  s = copySize;
272 
274  // destroy remaining old objects
275  while (osize > asize)
276  (oldPtr+(--osize))->~T();
277  }
278 
279  if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr)
280  qFree(oldPtr);
281 
283  // call default constructor for new objects (which can throw)
284  while (s < asize)
285  new (ptr+(s++)) T;
286  } else {
287  s = asize;
288  }
289 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define QT_RETHROW
Definition: qglobal.h:1539
#define QT_CATCH(A)
Definition: qglobal.h:1537
void * qMemCopy(void *dest, const void *src, size_t n)
Definition: qglobal.cpp:2508
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
char array[sizeof(qint64) *(((Prealloc *sizeof(T))/sizeof(qint64))+1)]
#define QT_TRY
Definition: qglobal.h:1536

◆ remove() [1/2]

template<class T , int Prealloc>
void QVarLengthArray< T, Prealloc >::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)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ remove() [2/2]

template<class T , int Prealloc>
void QVarLengthArray< T, Prealloc >::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); }
iterator erase(iterator begin, iterator end)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ removeLast()

template<class T, int Prealloc>
void QVarLengthArray< T, Prealloc >::removeLast ( )
inline

Definition at line 92 of file qvarlengtharray.h.

Referenced by QTriangulator< T >::ComplexToSimple::insertEdgeIntoVectorIfWanted().

92  {
93  Q_ASSERT(s > 0);
94  realloc(s - 1, a);
95  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void realloc(int size, int alloc)

◆ replace()

template<class T, int Prealloc>
void QVarLengthArray< T, Prealloc >::replace ( int  i,
const T &  t 
)
inline

Definition at line 326 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::operator+=().

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 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ reserve()

template<class T , int Prealloc>
Q_INLINE_TEMPLATE void QVarLengthArray< T, Prealloc >::reserve ( int  size)
inline

◆ resize()

template<class T , int Prealloc>
Q_INLINE_TEMPLATE void QVarLengthArray< T, Prealloc >::resize ( int  size)
inline

◆ size()

template<class T, int Prealloc>
int QVarLengthArray< T, Prealloc >::size ( ) const
inline

Definition at line 96 of file qvarlengtharray.h.

Referenced by QFontEngine::addOutlineToPath(), QFontEngineBox::addOutlineToPath(), QTriangulatingStroker::arcPoints(), QFontEngineBox::boundingBox(), QProxyFontEngine::canRender(), QFontEngineDirectWrite::canRender(), QODBCDriver::cleanup(), QGLShader::compileSourceCode(), QWindowsLocalCodec::convertToUnicode(), QGLTextureGlyphCache::createTextureData(), QSystemLocalePrivate::currencySymbol(), QEventDispatcherUNIXPrivate::doSelect(), QFontEngineMac::draw(), QFontEngineQPF::draw(), QFontEngineQPF1::draw(), draw_text_item_win(), QPaintEnginePrivate::drawBoxTextItem(), QRasterPaintEngine::drawCachedGlyphs(), QPlastiqueStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QX11PaintEngine::drawFreetype(), QPainterPrivate::drawGlyphs(), QVGPaintEngine::drawPixmapFragments(), QPlastiqueStyle::drawPrimitive(), QGL2PaintEngineEx::drawTextItem(), QOpenGLPaintEngine::drawTextItem(), QVGPaintEngine::drawTextItem(), QRasterPaintEngine::drawTextItem(), QPdfBaseEnginePrivate::drawTextItem(), QX11PaintEngine::drawXLFD(), QTriangulatingStroker::endCap(), QDB2Result::exec(), QODBCResult::exec(), QScript::QObjectConnectionManager::execute(), fromSQLTCHAR(), QStaticTextPrivate::get(), QFontEngine::getGlyphPositions(), QSystemLocalePrivate::getLocaleInfo(), QTextLine::glyphs(), QDBusConnectionPrivate::handleMessage(), QSqlQueryModelPrivate::initColOffsets(), QTriangulator< T >::ComplexToSimple::insertEdgeIntoVectorIfWanted(), QMetaObject::invokeMethod(), QVarLengthArray< QVariant, 9 >::isEmpty(), QTriangulatingStroker::join(), QTriangulatingStroker::moveTo(), QFileSystemEngine::nativeAbsoluteFilePath(), QNativeSocketEnginePrivate::nativePendingDatagramSize(), QMetaObject::newInstance(), QFileSystemModelPrivate::node(), QODBCDriver::open(), QVarLengthArray< QVariant, 9 >::operator=(), operator==(), QFileSystemEngine::owner(), path_for_glyphs(), PtsToRegion(), qt_merge_clip(), QVarLengthArray< QVariant, 9 >::QVarLengthArray(), qWarnODBCHandle(), QFontEngineDirectWrite::recalcAdvances(), registerFont(), QEventDispatcherUNIX::registerSocketNotifier(), QTriangulator< T >::ComplexToSimple::removeUnwantedEdgesAndConnect(), QEglProperties::removeValue(), QDeclarativeJS::Parser::reparseAsQualifiedId(), QFileSystemEngine::resolveGroupName(), QFileSystemEngine::resolveUserName(), QWSRegionCommand::setData(), QEventDispatcherUNIX::setSocketNotifierPending(), QEglProperties::setValue(), QTextEngine::shapeTextWithHarfbuzz(), sm_performSaveYourself(), QDBusConnectionPrivate::socketRead(), QDBusConnectionPrivate::socketWrite(), QWidgetBackingStore::sync(), QSystemLocalePrivate::toCurrencyString(), QSslSocketBackendPrivate::transmit(), QSystemLocalePrivate::uiLanguages(), QEventDispatcherUNIX::unregisterSocketNotifier(), QEglProperties::value(), QVarLengthArray< QVariant, 9 >::value(), and QDBusMetaObjectGenerator::write().

96 { return s; }

◆ value() [1/2]

template<class T , int Prealloc>
Q_OUTOFLINE_TEMPLATE T QVarLengthArray< T, Prealloc >::value ( int  i) const

Definition at line 292 of file qvarlengtharray.h.

Referenced by QVarLengthArray< QVariant, 9 >::at(), and QTextEngine::justify().

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

◆ value() [2/2]

template<class T, int Prealloc>
Q_OUTOFLINE_TEMPLATE T QVarLengthArray< T, Prealloc >::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

Friends and Related Functions

◆ QPodList< T, Prealloc >

template<class T, int Prealloc>
friend class QPodList< T, Prealloc >
friend

Definition at line 169 of file qvarlengtharray.h.

Properties

◆ @92

union { ... }

◆ a

template<class T, int Prealloc>
int QVarLengthArray< T, Prealloc >::a
private

◆ array

template<class T, int Prealloc>
char QVarLengthArray< T, Prealloc >::array[sizeof(qint64) *(((Prealloc *sizeof(T))/sizeof(qint64))+1)]

◆ ptr

template<class T, int Prealloc>
T* QVarLengthArray< T, Prealloc >::ptr
private

◆ q_for_alignment_1

template<class T, int Prealloc>
qint64 QVarLengthArray< T, Prealloc >::q_for_alignment_1

Definition at line 178 of file qvarlengtharray.h.

◆ q_for_alignment_2

template<class T, int Prealloc>
double QVarLengthArray< T, Prealloc >::q_for_alignment_2

Definition at line 179 of file qvarlengtharray.h.

◆ s

template<class T, int Prealloc>
int QVarLengthArray< T, Prealloc >::s
private

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