| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef Q3VALUELIST_H
|
|---|
| 43 | #define Q3VALUELIST_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtCore/qalgorithms.h>
|
|---|
| 46 | #include <QtCore/qdatastream.h>
|
|---|
| 47 | #include <QtCore/qlinkedlist.h>
|
|---|
| 48 | #include <QtCore/qlist.h>
|
|---|
| 49 |
|
|---|
| 50 | #ifndef QT_NO_STL
|
|---|
| 51 | #include <iterator>
|
|---|
| 52 | #include <list>
|
|---|
| 53 | #endif
|
|---|
| 54 |
|
|---|
| 55 | QT_BEGIN_HEADER
|
|---|
| 56 |
|
|---|
| 57 | QT_BEGIN_NAMESPACE
|
|---|
| 58 |
|
|---|
| 59 | QT_MODULE(Qt3SupportLight)
|
|---|
| 60 |
|
|---|
| 61 | template <typename T>
|
|---|
| 62 | class Q3ValueListIterator : public QLinkedList<T>::iterator
|
|---|
| 63 | {
|
|---|
| 64 | public:
|
|---|
| 65 | inline Q3ValueListIterator() :
|
|---|
| 66 | QLinkedList<T>::iterator() {}
|
|---|
| 67 | inline Q3ValueListIterator(const Q3ValueListIterator &o) :
|
|---|
| 68 | QLinkedList<T>::iterator(o) {}
|
|---|
| 69 | inline Q3ValueListIterator(const typename QLinkedList<T>::iterator &o) :
|
|---|
| 70 | QLinkedList<T>::iterator(o) {}
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | template <typename T>
|
|---|
| 74 | class Q3ValueListConstIterator : public QLinkedList<T>::const_iterator
|
|---|
| 75 | {
|
|---|
| 76 | public:
|
|---|
| 77 | inline Q3ValueListConstIterator() {}
|
|---|
| 78 | inline Q3ValueListConstIterator(const Q3ValueListConstIterator &o) :
|
|---|
| 79 | QLinkedList<T>::const_iterator(o) {}
|
|---|
| 80 | inline Q3ValueListConstIterator(const typename QLinkedList<T>::const_iterator &o) :
|
|---|
| 81 | QLinkedList<T>::const_iterator(o) {}
|
|---|
| 82 | inline Q3ValueListConstIterator(const typename QLinkedList<T>::iterator &o) :
|
|---|
| 83 | QLinkedList<T>::const_iterator(o) {}
|
|---|
| 84 | };
|
|---|
| 85 |
|
|---|
| 86 | template <typename T>
|
|---|
| 87 | class Q3ValueList : public QLinkedList<T>
|
|---|
| 88 | {
|
|---|
| 89 | public:
|
|---|
| 90 | typedef T value_type;
|
|---|
| 91 | typedef value_type* pointer;
|
|---|
| 92 | typedef const value_type* const_pointer;
|
|---|
| 93 | typedef value_type& reference;
|
|---|
| 94 | typedef const value_type& const_reference;
|
|---|
| 95 | #ifndef QT_NO_STL
|
|---|
| 96 | typedef ptrdiff_t difference_type;
|
|---|
| 97 | #else
|
|---|
| 98 | typedef int difference_type;
|
|---|
| 99 | #endif
|
|---|
| 100 |
|
|---|
| 101 | typedef Q3ValueListIterator<T> Iterator;
|
|---|
| 102 | typedef Q3ValueListConstIterator<T> ConstIterator;
|
|---|
| 103 | typedef Q3ValueListIterator<T> iterator;
|
|---|
| 104 | typedef Q3ValueListConstIterator<T> const_iterator;
|
|---|
| 105 | typedef typename QLinkedList<T>::size_type size_type;
|
|---|
| 106 |
|
|---|
| 107 | /**
|
|---|
| 108 | * API
|
|---|
| 109 | */
|
|---|
| 110 | Q3ValueList() {}
|
|---|
| 111 | Q3ValueList(const Q3ValueList<T>& l) : QLinkedList<T>(l) {}
|
|---|
| 112 | Q3ValueList(const QLinkedList<T>& l) : QLinkedList<T>(l) {}
|
|---|
| 113 | Q3ValueList(const QList<T>& l)
|
|---|
| 114 | {
|
|---|
| 115 | for (int i = 0; i < l.size(); ++i) append(l.at(i));
|
|---|
| 116 | }
|
|---|
| 117 | #ifndef QT_NO_STL
|
|---|
| 118 | Q3ValueList(const std::list<T>& l)
|
|---|
| 119 | {
|
|---|
| 120 | qCopy(l.begin(), l.end(), std::back_inserter(*this));
|
|---|
| 121 | }
|
|---|
| 122 | #endif
|
|---|
| 123 | ~Q3ValueList() {}
|
|---|
| 124 |
|
|---|
| 125 | Q3ValueList<T>& operator= (const Q3ValueList<T>& l)
|
|---|
| 126 | {
|
|---|
| 127 | QLinkedList<T>::operator=(l);
|
|---|
| 128 | return *this;
|
|---|
| 129 | }
|
|---|
| 130 | Q3ValueList<T>& operator= (const QList<T>& l)
|
|---|
| 131 | {
|
|---|
| 132 | this->clear();
|
|---|
| 133 | for (int i = 0; i < l.size(); ++i) append(l.at(i));
|
|---|
| 134 | return *this;
|
|---|
| 135 | }
|
|---|
| 136 | #ifndef QT_NO_STL
|
|---|
| 137 | Q3ValueList<T>& operator= (const std::list<T>& l)
|
|---|
| 138 | {
|
|---|
| 139 | this->detach();
|
|---|
| 140 | qCopy(l.begin(), l.end(), std::back_inserter(*this));
|
|---|
| 141 | return *this;
|
|---|
| 142 | }
|
|---|
| 143 | bool operator== (const std::list<T>& l) const
|
|---|
| 144 | {
|
|---|
| 145 | if (this->size() != l.size())
|
|---|
| 146 | return false;
|
|---|
| 147 | typename Q3ValueList<T>::const_iterator it2 = this->begin();
|
|---|
| 148 | #if !defined(Q_CC_MIPS)
|
|---|
| 149 | typename
|
|---|
| 150 | #endif
|
|---|
| 151 | std::list<T>::const_iterator it = l.begin();
|
|---|
| 152 | for (; it2 != this->end(); ++it2, ++it)
|
|---|
| 153 | if (!((*it2) == (*it)))
|
|---|
| 154 | return false;
|
|---|
| 155 | return true;
|
|---|
| 156 | }
|
|---|
| 157 | #endif
|
|---|
| 158 | bool operator== (const Q3ValueList<T>& l) const { return QLinkedList<T>::operator==(l); }
|
|---|
| 159 | bool operator!= (const Q3ValueList<T>& l) const { return QLinkedList<T>::operator!=(l); }
|
|---|
| 160 |
|
|---|
| 161 | operator QList<T>() const {
|
|---|
| 162 | QList<T> list;
|
|---|
| 163 | for (typename Q3ValueList<T>::const_iterator it = QLinkedList<T>::constBegin();
|
|---|
| 164 | it != QLinkedList<T>::constEnd(); ++it)
|
|---|
| 165 | list.append(*it);
|
|---|
| 166 | return list;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | inline Q3ValueList<T>& operator<< (const T& x) { append(x); return *this; }
|
|---|
| 170 |
|
|---|
| 171 | void insert(typename Q3ValueList<T>::Iterator pos,
|
|---|
| 172 | typename Q3ValueList<T>::size_type n,
|
|---|
| 173 | const T& x);
|
|---|
| 174 |
|
|---|
| 175 | typename Q3ValueList<T>::Iterator insert(typename Q3ValueList<T>::Iterator pos,
|
|---|
| 176 | const T& x)
|
|---|
| 177 | { return QLinkedList<T>::insert(pos, x); }
|
|---|
| 178 | typename Q3ValueList<T>::Iterator remove(typename Q3ValueList<T>::Iterator pos)
|
|---|
| 179 | { return QLinkedList<T>::erase(pos); }
|
|---|
| 180 | int remove(const T &value)
|
|---|
| 181 | { return QLinkedList<T>::removeAll(value); }
|
|---|
| 182 |
|
|---|
| 183 | inline Q3ValueList<T> operator+ (const Q3ValueList<T>& l) const
|
|---|
| 184 | { return static_cast<Q3ValueList<T> >(QLinkedList<T>::operator+(l)); }
|
|---|
| 185 | inline Q3ValueList<T>& operator+= (const Q3ValueList<T>& l)
|
|---|
| 186 | { QLinkedList<T>::operator+=(l); return *this; }
|
|---|
| 187 |
|
|---|
| 188 | typename Q3ValueList<T>::Iterator fromLast()
|
|---|
| 189 | { return (this->isEmpty() ? this->end() : --this->end()); }
|
|---|
| 190 | typename Q3ValueList<T>::ConstIterator fromLast() const
|
|---|
| 191 | { return (this->isEmpty() ? this->end() : --this->end()); }
|
|---|
| 192 |
|
|---|
| 193 | typename Q3ValueList<T>::Iterator append(const T& x)
|
|---|
| 194 | { QLinkedList<T>::append(x); return --this->end(); }
|
|---|
| 195 | typename Q3ValueList<T>::Iterator prepend(const T& x)
|
|---|
| 196 | { QLinkedList<T>::prepend(x); return this->begin(); }
|
|---|
| 197 |
|
|---|
| 198 | typename Q3ValueList<T>::Iterator at(typename Q3ValueList<T>::size_type i)
|
|---|
| 199 | { Q_ASSERT(i < this->size()); this->detach(); return this->begin()+i; }
|
|---|
| 200 | typename Q3ValueList<T>::ConstIterator at(typename Q3ValueList<T>::size_type i) const
|
|---|
| 201 | { Q_ASSERT(i < this->size()); return this->begin()+i; }
|
|---|
| 202 | typename Q3ValueList<T>::size_type contains(const T& x) const
|
|---|
| 203 | { return QLinkedList<T>::count(x); }
|
|---|
| 204 |
|
|---|
| 205 | Q3ValueList<T>& operator+= (const T& x) { append(x); return *this; }
|
|---|
| 206 |
|
|---|
| 207 | T& operator[] (typename Q3ValueList<T>::size_type i) { return *at(i); }
|
|---|
| 208 | const T& operator[] (typename Q3ValueList<T>::size_type i) const { return *at(i); }
|
|---|
| 209 |
|
|---|
| 210 | };
|
|---|
| 211 |
|
|---|
| 212 | template <typename T>
|
|---|
| 213 | Q_OUTOFLINE_TEMPLATE void Q3ValueList<T>::insert(typename Q3ValueList<T>::Iterator pos,
|
|---|
| 214 | typename Q3ValueList<T>::size_type n, const T& x)
|
|---|
| 215 | {
|
|---|
| 216 | for (; n > 0; --n)
|
|---|
| 217 | this->insert(pos, x);
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | #ifndef QT_NO_DATASTREAM
|
|---|
| 221 | template <typename T>
|
|---|
| 222 | Q_OUTOFLINE_TEMPLATE QDataStream& operator>>(QDataStream& s, Q3ValueList<T>& l)
|
|---|
| 223 | {
|
|---|
| 224 | return operator>>(s, static_cast<QLinkedList<T> &>(l));
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | template <typename T>
|
|---|
| 228 | Q_OUTOFLINE_TEMPLATE QDataStream& operator<<(QDataStream& s, const Q3ValueList<T>& l)
|
|---|
| 229 | {
|
|---|
| 230 | return operator<<(s, static_cast<const QLinkedList<T> &>(l));
|
|---|
| 231 | }
|
|---|
| 232 | #endif
|
|---|
| 233 |
|
|---|
| 234 | QT_END_NAMESPACE
|
|---|
| 235 |
|
|---|
| 236 | QT_END_HEADER
|
|---|
| 237 |
|
|---|
| 238 | #endif // Q3VALUELIST_H
|
|---|