53 #ifdef Q_COMPILER_INITIALIZER_LISTS
55 #include <initializer_list>
68 template <typename T> class
QVector;
69 template <typename T> class
QSet;
74 int alloc, begin,
end;
78 enum { DataHeaderSize =
sizeof(
Data) -
sizeof(
void *) };
80 Data *detach(
int alloc);
81 Data *detach_grow(
int *i,
int n);
85 void realloc(
int alloc);
88 void **erase(
void **xi);
91 void **append(
const QListData &l);
92 void **append2(
const QListData &l);
96 void remove(
int i,
int n);
97 void move(
int from,
int to);
105 template <
typename T>
108 struct Node {
void *
v;
109 #if defined(Q_CC_BOR)
110 Q_INLINE_TEMPLATE T &
t();
112 Q_INLINE_TEMPLATE T &
t()
113 {
return *
reinterpret_cast<T*
>(QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic
125 #ifdef Q_COMPILER_RVALUE_REFS
127 {
qSwap(
d, other.d);
return *
this; }
130 #ifdef Q_COMPILER_INITIALIZER_LISTS
131 inline QList(std::initializer_list<T> args) :
d(&
QListData::shared_null)
132 {
d->
ref.
ref();
qCopy(args.begin(), args.end(), std::back_inserter(*
this)); }
137 inline int size()
const {
return p.size(); }
152 inline bool isEmpty()
const {
return p.isEmpty(); }
156 const T &
at(
int i)
const;
164 void insert(
int i,
const T &
t);
172 void move(
int from,
int to);
173 void swap(
int i,
int j);
174 int indexOf(
const T &
t,
int from = 0)
const;
177 int count(
const T &
t)
const;
202 #ifndef QT_STRICT_ITERATORS
208 {
return i < other.
i; }
210 {
return i <= other.
i; }
212 {
return i > other.
i; }
214 {
return i >= other.
i; }
240 #ifdef QT_STRICT_ITERATORS
280 inline int count()
const {
return p.size(); }
281 inline int length()
const {
return p.size(); }
292 T
value(
int i)
const;
293 T
value(
int i,
const T &defaultValue)
const;
315 inline QT3_SUPPORT
int remove(
const T &
t) {
return removeAll(
t); }
316 inline QT3_SUPPORT
int findIndex(
const T&
t)
const {
return indexOf(t); }
317 inline QT3_SUPPORT
iterator find(
const T&
t)
330 {
QList n = *
this; n += l;
return n; }
332 {
append(t);
return *
this; }
334 {
append(t);
return *
this; }
336 { *
this += l;
return *
this; }
346 {
QList<T> tmp;
qCopy(list.begin(), list.end(), std::back_inserter(tmp));
return tmp; }
352 Node *detach_helper_grow(
int i,
int n);
353 void detach_helper(
int alloc);
354 void detach_helper();
357 void node_construct(Node *
n,
const T &t);
358 void node_destruct(Node *
n);
359 void node_copy(Node *from, Node *to, Node *
src);
360 void node_destruct(Node *from, Node *to);
363 #if defined(Q_CC_BOR)
364 template <
typename T>
366 {
return QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic ? *(T*)
v:*(T*)this; }
369 template <
typename T>
372 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v =
new T(t);
373 else if (QTypeInfo<T>::isComplex)
new (
n) T(t);
374 #if (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__IBMCPP__)) && !defined(__OPTIMIZE__)
378 else *
reinterpret_cast<T*
>(
n) = t;
381 else ::memcpy(n, &t,
sizeof(T));
385 template <
typename T>
388 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic)
delete reinterpret_cast<T*
>(n->v);
389 else if (QTypeInfo<T>::isComplex)
reinterpret_cast<T*
>(
n)->~T();
392 template <
typename T>
395 Node *current = from;
396 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
398 while(current != to) {
399 current->v =
new T(*reinterpret_cast<T*>(src->v));
404 while (current-- != from)
405 delete reinterpret_cast<T*
>(current->v);
409 }
else if (QTypeInfo<T>::isComplex) {
411 while(current != to) {
412 new (current) T(*reinterpret_cast<T*>(src));
417 while (current-- != from)
418 (
reinterpret_cast<T*
>(current))->~T();
422 if (src != from && to - from > 0)
423 memcpy(from, src, (to - from) *
sizeof(Node *));
427 template <
typename T>
430 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic)
431 while(from != to) --to,
delete reinterpret_cast<T*
>(to->v);
432 else if (QTypeInfo<T>::isComplex)
433 while (from != to) --to,
reinterpret_cast<T*
>(to)->~T();
436 template <
typename T>
450 template <
typename T>
453 int iBefore =
int(before.
i - reinterpret_cast<Node *>(
p.begin()));
454 Node *n =
reinterpret_cast<Node *
>(
p.insert(iBefore));
456 node_construct(n, t);
463 template <
typename T>
465 { node_destruct(it.
i);
466 return reinterpret_cast<Node *
>(
p.erase(reinterpret_cast<void**>(it.
i))); }
467 template <
typename T>
469 { Q_ASSERT_X(i >= 0 && i <
p.size(),
"QList<T>::at",
"index out of range");
470 return reinterpret_cast<Node *
>(
p.at(i))->
t(); }
471 template <
typename T>
473 { Q_ASSERT_X(i >= 0 && i <
p.size(),
"QList<T>::operator[]",
"index out of range");
474 return reinterpret_cast<Node *
>(
p.at(i))->
t(); }
475 template <
typename T>
477 { Q_ASSERT_X(i >= 0 && i <
p.size(),
"QList<T>::operator[]",
"index out of range");
478 detach();
return reinterpret_cast<Node *
>(
p.at(i))->
t(); }
479 template <
typename T>
481 {
if(i >= 0 && i <
p.size()) { detach();
482 node_destruct(reinterpret_cast<Node *>(
p.at(i)));
p.remove(i); } }
483 template <
typename T>
485 { Q_ASSERT_X(i >= 0 && i <
p.size(),
"QList<T>::take",
"index out of range");
486 detach(); Node *n =
reinterpret_cast<Node *
>(
p.at(i)); T t = n->t(); node_destruct(n);
487 p.remove(i);
return t; }
488 template <
typename T>
490 { T t =
first(); removeFirst();
return t; }
491 template <
typename T>
493 { T t = last(); removeLast();
return t; }
495 template <
typename T>
498 if (d->alloc < alloc) {
500 detach_helper(alloc);
506 template <
typename T>
510 Node *n = detach_helper_grow(INT_MAX, 1);
512 node_construct(n, t);
518 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
519 Node *n =
reinterpret_cast<Node *
>(
p.append());
521 node_construct(n, t);
528 node_construct(©, t);
530 n =
reinterpret_cast<Node *
>(
p.append());;
532 node_destruct(©);
540 template <
typename T>
544 Node *n = detach_helper_grow(0, 1);
546 node_construct(n, t);
552 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
553 Node *n =
reinterpret_cast<Node *
>(
p.prepend());
555 node_construct(n, t);
562 node_construct(©, t);
564 n =
reinterpret_cast<Node *
>(
p.prepend());;
566 node_destruct(©);
574 template <
typename T>
578 Node *n = detach_helper_grow(i, 1);
580 node_construct(n, t);
586 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
587 Node *n =
reinterpret_cast<Node *
>(
p.insert(i));
589 node_construct(n, t);
596 node_construct(©, t);
598 n =
reinterpret_cast<Node *
>(
p.insert(i));;
600 node_destruct(©);
608 template <
typename T>
611 Q_ASSERT_X(i >= 0 && i <
p.size(),
"QList<T>::replace",
"index out of range");
613 reinterpret_cast<Node *
>(
p.at(i))->
t() =
t;
616 template <
typename T>
619 Q_ASSERT_X(i >= 0 && i <
p.size() && j >= 0 && j <
p.size(),
620 "QList<T>::swap",
"index out of range");
622 void *t = d->array[d->begin + i];
623 d->array[d->begin + i] = d->array[d->begin + j];
624 d->array[d->begin + j] =
t;
627 template <
typename T>
630 Q_ASSERT_X(from >= 0 && from <
p.size() && to >= 0 && to <
p.size(),
631 "QList<T>::move",
"index out of range");
639 if (alength < 0 || pos + alength >
size())
640 alength =
size() - pos;
641 if (pos == 0 && alength ==
size())
647 cpy.
d->
end = alength;
649 cpy.node_copy(reinterpret_cast<Node *>(cpy.
p.
begin()),
650 reinterpret_cast<Node *>(cpy.
p.
end()),
651 reinterpret_cast<Node *>(
p.begin() + pos));
663 if (i < 0 || i >=
p.size()) {
666 return reinterpret_cast<Node *
>(
p.at(i))->
t();
672 return ((i < 0 || i >=
p.size()) ? defaultValue : reinterpret_cast<Node *>(
p.at(i))->
t());
675 template <
typename T>
678 Node *n =
reinterpret_cast<Node *
>(
p.begin());
681 node_copy(reinterpret_cast<Node *>(
p.begin()),
682 reinterpret_cast<Node *>(
p.begin() + i), n);
689 node_copy(reinterpret_cast<Node *>(
p.begin() + i +
c),
690 reinterpret_cast<Node *>(
p.end()), n + i);
692 node_destruct(reinterpret_cast<Node *>(
p.begin()),
693 reinterpret_cast<Node *>(
p.begin() + i));
702 return reinterpret_cast<Node *
>(
p.begin() + i);
705 template <
typename T>
708 Node *n =
reinterpret_cast<Node *
>(
p.begin());
711 node_copy(reinterpret_cast<Node *>(
p.begin()), reinterpret_cast<Node *>(
p.end()), n);
722 template <
typename T>
725 detach_helper(d->alloc);
728 template <
typename T>
735 template <
typename T>
738 if (
p.size() != l.
p.
size())
742 Node *i =
reinterpret_cast<Node *
>(
p.end());
743 Node *
b =
reinterpret_cast<Node *
>(
p.begin());
744 Node *li =
reinterpret_cast<Node *
>(l.
p.
end());
747 if (!(i->t() == li->t()))
754 template <
typename T>
757 node_destruct(reinterpret_cast<Node *>(data->
array + data->
begin),
758 reinterpret_cast<Node *>(data->
array + data->
end));
763 template <
typename T>
769 template <
typename T>
772 int index = indexOf(_t);
779 Node *i =
reinterpret_cast<Node *
>(
p.at(index));
780 Node *e =
reinterpret_cast<Node *
>(
p.end());
790 int removedCount = e -
n;
791 d->end -= removedCount;
795 template <
typename T>
798 int index = indexOf(_t);
806 template <
typename T>
810 for (Node *n = afirst.
i; n < alast.
i; ++n)
812 int idx = afirst - begin();
813 p.remove(idx, alast - afirst);
814 return begin() + idx;
817 template <
typename T>
824 Node *n = (d->ref != 1)
825 ? detach_helper_grow(INT_MAX, l.
size())
826 : reinterpret_cast<Node *>(
p.append2(l.
p));
828 node_copy(n, reinterpret_cast<Node *>(
p.end()),
829 reinterpret_cast<Node *>(l.
p.
begin()));
832 d->end -=
int(reinterpret_cast<Node *>(
p.end()) - n);
840 template <
typename T>
846 template <
typename T>
850 from = qMax(from +
p.size(), 0);
851 if (from <
p.size()) {
852 Node *n =
reinterpret_cast<Node *
>(
p.at(from -1));
853 Node *e =
reinterpret_cast<Node *
>(
p.end());
856 return int(n - reinterpret_cast<Node *>(
p.begin()));
861 template <
typename T>
866 else if (from >=
p.size())
869 Node *
b =
reinterpret_cast<Node *
>(
p.begin());
870 Node *n =
reinterpret_cast<Node *
>(
p.at(from + 1));
879 template <
typename T>
882 Node *
b =
reinterpret_cast<Node *
>(
p.begin());
883 Node *i =
reinterpret_cast<Node *
>(
p.end());
890 template <
typename T>
894 Node *
b =
reinterpret_cast<Node *
>(
p.begin());
895 Node *i =
reinterpret_cast<Node *
>(
p.end());
unsigned int(APIENTRYP PFNGLXGETAGPOFFSETMESAPROC)(const void *pointer)
QList< T > & operator<<(const T &t)
int operator-(iterator j) const
bool operator!=(const const_iterator &o) const
const T & operator*() const
int removeAll(const T &t)
void push_back(const T &t)
QList< T > mid(int pos, int length=-1) const
bool operator<(const const_iterator &other) const
void setSharable(bool sharable)
const_iterator operator-(int j) const
void move(int from, int to)
const_iterator end() const
iterator(const iterator &o)
bool operator>(const const_iterator &other) const
bool operator>(const const_iterator &other) const
#define Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C)
void push_front(const T &t)
bool operator==(const const_iterator &o) const
QList< T > & operator+=(const T &t)
bool operator!=(const QList< T > &l) const
bool endsWith(const T &t) const
const value_type & const_reference
iterator & operator+=(int j)
iterator erase(iterator pos)
const_iterator(const iterator &o)
const_iterator operator--(int)
const_iterator constEnd() const
void swap(QList< T > &other)
int lastIndexOf(const T &t, int from=-1) const
const value_type * const_pointer
const_iterator & operator--()
QVector< T > toVector() const
#define QT_BEGIN_NAMESPACE
#define Q_DECLARE_SEQUENTIAL_ITERATOR(C)
GLsizei GLsizei GLenum GLenum const GLvoid * data
QList< T > & operator=(const QList< T > &l)
bool operator>=(const iterator &other) const
const_iterator begin() const
bool operator>(const iterator &other) const
Q_INLINE_TEMPLATE void qSwap(QScopedPointer< T, Cleanup > &p1, QScopedPointer< T, Cleanup > &p2)
friend class const_iterator
const_iterator constBegin() const
const T & at(int i) const
bool operator==(const const_iterator &o) const
bool removeOne(const T &t)
QBool contains(const T &t) const
int indexOf(const T &t, int from=0) const
const T * operator->() const
bool operator!=(const iterator &o) const
GLuint GLsizei GLsizei * length
bool operator==(const QList< T > &l) const
const T & operator[](int i) const
bool operator>=(const const_iterator &other) const
const_iterator ConstIterator
bool operator==(const iterator &o) const
static QList< T > fromSet(const QSet< T > &set)
bool operator<(const iterator &other) const
QList(const QList< T > &l)
std::random_access_iterator_tag iterator_category
QList< T > & operator+=(const QList< T > &l)
const_iterator & operator++()
static QList< T > fromVector(const QVector< T > &vector)
const_iterator & operator+=(int j)
std::random_access_iterator_tag iterator_category
void replace(int i, const T &t)
iterator & operator-=(int j)
bool startsWith(const T &t) const
bool operator!=(const const_iterator &o) const
bool operator<=(const const_iterator &other) const
const_iterator operator+(int j) const
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
iterator operator-(int j) const
static QList< T > fromStdList(const std::list< T > &list)
const_iterator operator++(int)
T & operator[](int j) const
bool operator>=(const const_iterator &other) const
QList< T > operator+(const QList< T > &l) const
bool isSharedWith(const QList< T > &other) const
std::list< T > toStdList() const
void insert(int i, const T &t)
bool operator<=(const const_iterator &other) const
int operator-(const_iterator j) const
const_iterator & operator-=(int j)
iterator operator+(int j) const
bool operator<(const const_iterator &other) const
bool operator<=(const iterator &other) const
const T & operator[](int j) const
const_iterator(const const_iterator &o)