56 #ifdef Q_COMPILER_INITIALIZER_LISTS
57 #include <initializer_list>
71 #if defined(QT_ARCH_SPARC) && defined(Q_CC_GNU) && defined(__LP64__) && defined(QT_BOOTSTRAPPED)
86 static QVectorData *malloc(
int sizeofTypedData,
int size,
int sizeofT, QVectorData *init);
87 static QVectorData *allocate(
int size,
int alignment);
88 static QVectorData *reallocate(QVectorData *old,
int newsize,
int oldsize,
int alignment);
89 static void free(QVectorData *
data,
int alignment);
90 static int grow(
int sizeofTypedData,
int size,
int sizeofT,
bool excessive);
104 template <
typename T>
110 #if defined(Q_CC_SUN) && (__SUNPRO_CC <= 0x550)
126 #ifdef Q_COMPILER_RVALUE_REFS
128 {
qSwap(
p, other.p);
return *
this; }
131 #ifdef Q_COMPILER_INITIALIZER_LISTS
132 inline QVector(std::initializer_list<T> args);
153 inline const T *
data()
const {
return p->array; }
157 const T &
at(
int i)
const;
162 void insert(
int i,
const T &
t);
163 void insert(
int i,
int n,
const T &
t);
166 void remove(
int i,
int n);
170 int indexOf(
const T &
t,
int from = 0)
const;
173 int count(
const T &
t)
const;
175 #ifdef QT_STRICT_ITERATORS
179 typedef std::random_access_iterator_tag iterator_category;
188 inline T &
operator*()
const {
return *i; }
189 inline T *operator->()
const {
return i; }
190 inline T &
operator[](
int j)
const {
return *(i + j); }
197 inline iterator &operator++() { ++i;
return *
this; }
198 inline iterator operator++(
int) { T *
n = i; ++i;
return n; }
199 inline iterator &operator--() { i--;
return *
this; }
200 inline iterator operator--(
int) { T *
n = i; i--;
return n; }
202 inline iterator &operator-=(
int j) { i-=j;
return *
this; }
212 typedef std::random_access_iterator_tag iterator_category;
222 inline const T &
operator*()
const {
return *i; }
223 inline const T *operator->()
const {
return i; }
224 inline const T &
operator[](
int j)
const {
return *(i + j); }
248 inline const_iterator
begin()
const {
return p->array; }
251 inline const_iterator
end()
const {
return p->array +
d->
size; }
253 iterator
insert(iterator before,
int n,
const T &
x);
254 inline iterator
insert(iterator before,
const T &
x) {
return insert(before, 1, x); }
256 inline iterator
erase(iterator pos) {
return erase(pos, pos+1); }
268 T
value(
int i)
const;
269 T
value(
int i,
const T &defaultValue)
const;
286 {
return d->
size == 0; }
290 inline const_reference
back()
const {
return last(); }
297 {
append(t);
return *
this; }
299 {
append(t);
return *
this; }
301 { *
this += l;
return *
this; }
309 {
QVector<T> tmp; tmp.
reserve(
int(vector.size()));
qCopy(vector.begin(), vector.end(), std::back_inserter(tmp));
return tmp; }
316 void detach_helper();
318 void realloc(
int size,
int alloc);
320 int sizeOfTypedData() {
323 return reinterpret_cast<const char *
>(&(
reinterpret_cast<const Data *
>(
this))->array[1]) - reinterpret_cast<const char *>(
this);
325 inline int alignOfTypedData()
const
328 return qMax<int>(
sizeof(
void*), Q_ALIGNOF(Data));
335 template <
typename T>
337 { realloc(d->size, d->alloc); }
338 template <
typename T>
340 {
if (asize > d->alloc) realloc(d->size, asize);
if (d->ref == 1) d->capacity = 1; }
341 template <
typename T>
343 { realloc(asize, (asize > d->alloc || (!d->capacity && asize < d->
size && asize < (d->alloc >> 1))) ?
346 template <
typename T>
349 template <
typename T>
351 { Q_ASSERT_X(i >= 0 && i < d->
size,
"QVector<T>::at",
"index out of range");
352 return p->array[i]; }
353 template <
typename T>
355 { Q_ASSERT_X(i >= 0 && i < d->
size,
"QVector<T>::operator[]",
"index out of range");
356 return p->array[i]; }
357 template <
typename T>
359 { Q_ASSERT_X(i >= 0 && i < d->
size,
"QVector<T>::operator[]",
"index out of range");
361 template <
typename T>
363 { Q_ASSERT_X(i >= 0 && i <= d->
size,
"QVector<T>::insert",
"index out of range");
364 insert(begin() + i, 1, t); }
365 template <
typename T>
367 { Q_ASSERT_X(i >= 0 && i <= d->
size,
"QVector<T>::insert",
"index out of range");
368 insert(begin() + i, n, t); }
369 template <
typename T>
371 { Q_ASSERT_X(i >= 0 && n >= 0 && i +
n <= d->size,
"QVector<T>::remove",
"index out of range");
372 erase(begin() + i, begin() + i + n); }
373 template <
typename T>
375 { Q_ASSERT_X(i >= 0 && i < d->
size,
"QVector<T>::remove",
"index out of range");
376 erase(begin() + i, begin() + i + 1); }
377 template <
typename T>
379 { insert(begin(), 1, t); }
381 template <
typename T>
384 Q_ASSERT_X(i >= 0 && i < d->
size,
"QVector<T>::replace",
"index out of range");
389 template <
typename T>
402 template <
typename T>
406 Q_CHECK_PTR(vectordata);
410 template <
typename T>
415 d->alloc = d->size = asize;
418 if (QTypeInfo<T>::isComplex) {
420 T* i =
p->array + d->size;
424 qMemSet(
p->array, 0, asize *
sizeof(T));
428 template <
typename T>
433 d->alloc = d->size = asize;
436 T* i =
p->array + d->size;
437 while (i !=
p->array)
441 #ifdef Q_COMPILER_INITIALIZER_LISTS
442 template <
typename T>
445 d = malloc(
int(args.size()));
447 d->alloc = d->size =
int(args.size());
450 T* i =
p->array + d->size;
451 auto it = args.end();
452 while (i !=
p->array)
453 new (--i) T(*(--it));
457 template <
typename T>
460 if (QTypeInfo<T>::isComplex) {
464 T* i = b + u.d->size;
468 x->free(x, alignOfTypedData());
471 template <
typename T>
474 Q_ASSERT(asize <= aalloc);
480 if (QTypeInfo<T>::isComplex && asize < d->
size && d->ref == 1 ) {
483 pOld =
p->array + d->size;
484 pNew =
p->array + asize;
485 while (asize < d->
size) {
491 if (aalloc != d->alloc || d->ref != 1) {
493 if (QTypeInfo<T>::isStatic) {
494 x.d = malloc(aalloc);
497 }
else if (d->ref != 1) {
498 x.d = malloc(aalloc);
500 if (QTypeInfo<T>::isComplex) {
503 ::memcpy(x.p,
p, sizeOfTypedData() + (qMin(aalloc, d->alloc) - 1) *
sizeof(T));
509 sizeOfTypedData() + (d->alloc - 1) *
sizeof(T), alignOfTypedData());
513 } QT_CATCH (
const std::bad_alloc &) {
514 if (aalloc > d->alloc)
520 x.d->sharable =
true;
521 x.d->capacity = d->capacity;
525 if (QTypeInfo<T>::isComplex) {
527 pOld =
p->array + x.d->size;
528 pNew = x.p->array + x.d->size;
530 const int toMove = qMin(asize, d->size);
531 while (x.d->size < toMove) {
532 new (pNew++) T(*pOld++);
536 while (x.d->size < asize) {
545 }
else if (asize > x.d->size) {
547 qMemSet(x.p->array + x.d->size, 0, (asize - x.d->size) *
sizeof(T));
561 if (i < 0 || i >= d->size) {
569 return ((i < 0 || i >= d->size) ? defaultValue :
p->array[i]);
572 template <
typename T>
575 if (d->ref != 1 || d->size + 1 > d->alloc) {
578 QTypeInfo<T>::isStatic));
579 if (QTypeInfo<T>::isComplex)
580 new (
p->array + d->size) T(copy);
582 p->array[d->size] = copy;
584 if (QTypeInfo<T>::isComplex)
585 new (
p->array + d->size) T(t);
587 p->array[d->size] =
t;
592 template <
typename T>
598 if (d->ref != 1 || d->size + n > d->alloc)
600 QTypeInfo<T>::isStatic));
601 if (QTypeInfo<T>::isStatic) {
602 T *b =
p->array + d->size;
603 T *i =
p->array + d->size +
n;
606 i =
p->array + d->size;
617 memmove(i, b, (d->size - offset) *
sizeof(T));
626 template <
typename T>
629 int f =
int(abegin -
p->array);
630 int l =
int(aend -
p->array);
633 if (QTypeInfo<T>::isComplex) {
634 qCopy(
p->array+l,
p->array+d->size,
p->array+f);
635 T *i =
p->array+d->size;
636 T* b =
p->array+d->size-
n;
642 memmove(
p->array + f,
p->array + l, (d->size-l)*
sizeof(T));
648 template <
typename T>
651 if (d->size != v.
d->
size)
657 T* j = v.
p->
array + d->size;
664 template <
typename T>
668 resize(asize < 0 ? d->size : asize);
670 T *i =
p->array + d->size;
678 template <
typename T>
681 int newSize = d->size + l.
d->
size;
682 realloc(d->size, newSize);
684 T *
w =
p->array + newSize;
688 if (QTypeInfo<T>::isComplex)
697 template <
typename T>
701 from = qMax(from + d->size, 0);
702 if (from < d->size) {
703 T*
n =
p->array + from - 1;
704 T* e =
p->array + d->size;
712 template <
typename T>
717 else if (from >= d->size)
721 T*
n =
p->array + from + 1;
730 template <
typename T>
734 T* i =
p->array + d->size;
741 template <
typename T>
746 T* i =
p->array + d->size;
753 template <
typename T>
757 length =
size() - pos;
758 if (pos == 0 && length ==
size())
760 if (pos + length >
size())
761 length =
size() - pos;
764 for (
int i = pos; i < pos +
length; ++i)
769 template <
typename T>
774 for (
int i = 0; i <
size(); ++i)
779 template <
typename T>
783 for (
int i = 0; i <
size(); ++i)
788 template <
typename T>
794 template <
typename T>
812 #include <QtCore/QPointF>
813 #include <QtCore/QPoint>
816 #if defined(QT_BUILD_CORE_LIB)
817 #define Q_TEMPLATE_EXTERN
819 #define Q_TEMPLATE_EXTERN extern
const T & at(int i) const
unsigned int(APIENTRYP PFNGLXGETAGPOFFSETMESAPROC)(const void *pointer)
static void free(QVectorData *data, int alignment)
QVector< T > & operator+=(const QVector< T > &l)
bool operator>(const QByteArray &a1, const QByteArray &a2)
std::vector< T > toStdVector() const
iterator insert(iterator before, const T &x)
void insert(int i, const T &t)
const_iterator constEnd() const
void push_front(const T &t)
const_iterator constBegin() const
void replace(int i, const T &t)
static QVectorData shared_null
const_iterator begin() const
#define QT_END_INCLUDE_NAMESPACE
bool startsWith(const T &t) const
#define Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C)
bool operator==(const QVector< T > &v) const
const_reference front() const
bool operator<=(const QByteArray &a1, const QByteArray &a2)
const_iterator end() const
QVector< T > toVector() const
#define QT_BEGIN_NAMESPACE
#define Q_DECLARE_SEQUENTIAL_ITERATOR(C)
iterator erase(iterator pos)
GLsizei GLsizei GLenum GLenum const GLvoid * data
static void free(QVectorTypedData< T > *x, int alignment)
Q_INLINE_TEMPLATE void qSwap(QScopedPointer< T, Cleanup > &p1, QScopedPointer< T, Cleanup > &p2)
void swap(QVector< T > &other)
QVector< T > & operator+=(const T &t)
QVector< T > & operator=(const QVector< T > &v)
QVector< T > mid(int pos, int length=-1) const
int lastIndexOf(const T &t, int from=-1) const
static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive)
static QVector< T > fromStdVector(const std::vector< T > &vector)
bool contains(const T &t) const
void push_back(const T &t)
bool isSharedWith(const QVector< T > &other) const
GLuint GLsizei GLsizei * length
iterator erase(iterator begin, iterator end)
int indexOf(const T &t, int from=0) const
QList< T > toList() const
const T * constData() const
static QList< T > fromVector(const QVector< T > &vector)
MBDLL_DECL Vector operator*(float f, const Vector &v)
Multiplies a float scalar value by a vector, the result is a vector.
QVector< T > operator+(const QVector< T > &l) const
bool operator>=(const QByteArray &a1, const QByteArray &a2)
static QVector< T > fromList(const QList< T > &list)
const value_type * const_pointer
void setSharable(bool sharable)
const QPoint operator-(const QPoint &p1, const QPoint &p2)
#define QT_BEGIN_INCLUDE_NAMESPACE
bool operator<(const QByteArray &a1, const QByteArray &a2)
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
static QVectorData * allocate(int size, int alignment)
GLubyte GLubyte GLubyte GLubyte w
QVector(const QVector< T > &v)
bool operator!=(const QVector< T > &v) const
QVector< T > & operator<<(const T &t)
const_reference back() const
static QVectorData * reallocate(QVectorData *old, int newsize, int oldsize, int alignment)
const value_type & const_reference
QVector< T > & fill(const T &t, int size=-1)
bool endsWith(const T &t) const
const_iterator ConstIterator