| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include <new> | - |
| 43 | #include "qlist.h" | - |
| 44 | #include "qtools_p.h" | - |
| 45 | | - |
| 46 | #include <string.h> | - |
| 47 | #include <stdlib.h> | - |
| 48 | | - |
| 49 | QT_BEGIN_NAMESPACE | - |
| 50 | | - |
| 51 | /* | - |
| 52 | QList as an array-list combines the easy-of-use of a random | - |
| 53 | access interface with fast list operations and the low memory | - |
| 54 | management overhead of an array. Accessing elements by index, | - |
| 55 | appending, prepending, and removing elements from both the front | - |
| 56 | and the back all happen in constant time O(1). Inserting or | - |
| 57 | removing elements at random index positions \ai happens in linear | - |
| 58 | time, or more precisly in O(min{i,n-i}) <= O(n/2), with n being | - |
| 59 | the number of elements in the list. | - |
| 60 | */ | - |
| 61 | | - |
| 62 | const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, { 0 } }; | - |
| 63 | | - |
| 64 | static int grow(int size) | - |
| 65 | { | - |
| 66 | // dear compiler: don't optimize me out. | - |
| 67 | volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *); executed (the execution status of this line is deduced): volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *); | - |
| 68 | return x; executed: return x;Execution Count:1053559 | 1053559 |
| 69 | } | - |
| 70 | | - |
| 71 | /*! | - |
| 72 | * Detaches the QListData by allocating new memory for a list which will be bigger | - |
| 73 | * than the copied one and is expected to grow further. | - |
| 74 | * *idx is the desired insertion point and is clamped to the actual size of the list. | - |
| 75 | * num is the number of new elements to insert at the insertion point. | - |
| 76 | * Returns the old (shared) data, it is up to the caller to deref() and free(). | - |
| 77 | * For the new data node_copy needs to be called. | - |
| 78 | * | - |
| 79 | * \internal | - |
| 80 | */ | - |
| 81 | QListData::Data *QListData::detach_grow(int *idx, int num) | - |
| 82 | { | - |
| 83 | Data *x = d; executed (the execution status of this line is deduced): Data *x = d; | - |
| 84 | int l = x->end - x->begin; executed (the execution status of this line is deduced): int l = x->end - x->begin; | - |
| 85 | int nl = l + num; executed (the execution status of this line is deduced): int nl = l + num; | - |
| 86 | int alloc = grow(nl); executed (the execution status of this line is deduced): int alloc = grow(nl); | - |
| 87 | Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *))); executed (the execution status of this line is deduced): Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *))); | - |
| 88 | Q_CHECK_PTR(t); never executed: qBadAlloc(); executed: }Execution Count:817133 partially evaluated: !(t)| no Evaluation Count:0 | yes Evaluation Count:817134 |
partially evaluated: 0| no Evaluation Count:0 | yes Evaluation Count:817126 |
| 0-817134 |
| 89 | | - |
| 90 | t->ref.initializeOwned(); executed (the execution status of this line is deduced): t->ref.initializeOwned(); | - |
| 91 | t->alloc = alloc; executed (the execution status of this line is deduced): t->alloc = alloc; | - |
| 92 | // The space reservation algorithm's optimization is biased towards appending: | - |
| 93 | // Something which looks like an append will put the data at the beginning, | - |
| 94 | // while something which looks like a prepend will put it in the middle | - |
| 95 | // instead of at the end. That's based on the assumption that prepending | - |
| 96 | // is uncommon and even an initial prepend will eventually be followed by | - |
| 97 | // at least some appends. | - |
| 98 | int bg; executed (the execution status of this line is deduced): int bg; | - |
| 99 | if (*idx < 0) { partially evaluated: *idx < 0| no Evaluation Count:0 | yes Evaluation Count:817126 |
| 0-817126 |
| 100 | *idx = 0; never executed (the execution status of this line is deduced): *idx = 0; | - |
| 101 | bg = (alloc - nl) >> 1; never executed (the execution status of this line is deduced): bg = (alloc - nl) >> 1; | - |
| 102 | } else if (*idx > l) { never executed: } evaluated: *idx > l| yes Evaluation Count:761434 | yes Evaluation Count:55696 |
| 0-761434 |
| 103 | *idx = l; executed (the execution status of this line is deduced): *idx = l; | - |
| 104 | bg = 0; executed (the execution status of this line is deduced): bg = 0; | - |
| 105 | } else if (*idx < (l >> 1)) { executed: }Execution Count:761433 evaluated: *idx < (l >> 1)| yes Evaluation Count:106 | yes Evaluation Count:55590 |
| 106-761433 |
| 106 | bg = (alloc - nl) >> 1; executed (the execution status of this line is deduced): bg = (alloc - nl) >> 1; | - |
| 107 | } else { executed: }Execution Count:106 | 106 |
| 108 | bg = 0; executed (the execution status of this line is deduced): bg = 0; | - |
| 109 | } executed: }Execution Count:55590 | 55590 |
| 110 | t->begin = bg; executed (the execution status of this line is deduced): t->begin = bg; | - |
| 111 | t->end = bg + nl; executed (the execution status of this line is deduced): t->end = bg + nl; | - |
| 112 | d = t; executed (the execution status of this line is deduced): d = t; | - |
| 113 | | - |
| 114 | return x; executed: return x;Execution Count:817126 | 817126 |
| 115 | } | - |
| 116 | | - |
| 117 | /*! | - |
| 118 | * Detaches the QListData by allocating new memory for a list which possibly | - |
| 119 | * has a different size than the copied one. | - |
| 120 | * Returns the old (shared) data, it is up to the caller to deref() and free() | - |
| 121 | * For the new data node_copy needs to be called. | - |
| 122 | * | - |
| 123 | * \internal | - |
| 124 | */ | - |
| 125 | QListData::Data *QListData::detach(int alloc) | - |
| 126 | { | - |
| 127 | Data *x = d; executed (the execution status of this line is deduced): Data *x = d; | - |
| 128 | Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *))); executed (the execution status of this line is deduced): Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *))); | - |
| 129 | Q_CHECK_PTR(t); never executed: qBadAlloc(); executed: }Execution Count:83251 partially evaluated: !(t)| no Evaluation Count:0 | yes Evaluation Count:83251 |
partially evaluated: 0| no Evaluation Count:0 | yes Evaluation Count:83251 |
| 0-83251 |
| 130 | | - |
| 131 | t->ref.initializeOwned(); executed (the execution status of this line is deduced): t->ref.initializeOwned(); | - |
| 132 | t->alloc = alloc; executed (the execution status of this line is deduced): t->alloc = alloc; | - |
| 133 | if (!alloc) { evaluated: !alloc| yes Evaluation Count:17658 | yes Evaluation Count:65593 |
| 17658-65593 |
| 134 | t->begin = 0; executed (the execution status of this line is deduced): t->begin = 0; | - |
| 135 | t->end = 0; executed (the execution status of this line is deduced): t->end = 0; | - |
| 136 | } else { executed: }Execution Count:17658 | 17658 |
| 137 | t->begin = x->begin; executed (the execution status of this line is deduced): t->begin = x->begin; | - |
| 138 | t->end = x->end; executed (the execution status of this line is deduced): t->end = x->end; | - |
| 139 | } executed: }Execution Count:65593 | 65593 |
| 140 | d = t; executed (the execution status of this line is deduced): d = t; | - |
| 141 | | - |
| 142 | return x; executed: return x;Execution Count:83251 | 83251 |
| 143 | } | - |
| 144 | | - |
| 145 | void QListData::realloc(int alloc) | - |
| 146 | { | - |
| 147 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 148 | Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *))); executed (the execution status of this line is deduced): Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *))); | - |
| 149 | Q_CHECK_PTR(x); never executed: qBadAlloc(); executed: }Execution Count:236434 partially evaluated: !(x)| no Evaluation Count:0 | yes Evaluation Count:236434 |
partially evaluated: 0| no Evaluation Count:0 | yes Evaluation Count:236434 |
| 0-236434 |
| 150 | | - |
| 151 | d = x; executed (the execution status of this line is deduced): d = x; | - |
| 152 | d->alloc = alloc; executed (the execution status of this line is deduced): d->alloc = alloc; | - |
| 153 | if (!alloc) partially evaluated: !alloc| no Evaluation Count:0 | yes Evaluation Count:236434 |
| 0-236434 |
| 154 | d->begin = d->end = 0; never executed: d->begin = d->end = 0; | 0 |
| 155 | } executed: }Execution Count:236434 | 236434 |
| 156 | | - |
| 157 | void QListData::dispose(Data *d) | - |
| 158 | { | - |
| 159 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 160 | free(d); executed (the execution status of this line is deduced): free(d); | - |
| 161 | } executed: }Execution Count:901061 | 901061 |
| 162 | | - |
| 163 | // ensures that enough space is available to append n elements | - |
| 164 | void **QListData::append(int n) | - |
| 165 | { | - |
| 166 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 167 | int e = d->end; executed (the execution status of this line is deduced): int e = d->end; | - |
| 168 | if (e + n > d->alloc) { evaluated: e + n > d->alloc| yes Evaluation Count:282396 | yes Evaluation Count:6671648 |
| 282396-6671648 |
| 169 | int b = d->begin; executed (the execution status of this line is deduced): int b = d->begin; | - |
| 170 | if (b - n >= 2 * d->alloc / 3) { evaluated: b - n >= 2 * d->alloc / 3| yes Evaluation Count:70983 | yes Evaluation Count:211413 |
| 70983-211413 |
| 171 | // we have enough space. Just not at the end -> move it. | - |
| 172 | e -= b; executed (the execution status of this line is deduced): e -= b; | - |
| 173 | ::memcpy(d->array, d->array + b, e * sizeof(void *)); executed (the execution status of this line is deduced): ::memcpy(d->array, d->array + b, e * sizeof(void *)); | - |
| 174 | d->begin = 0; executed (the execution status of this line is deduced): d->begin = 0; | - |
| 175 | } else { executed: }Execution Count:70982 | 70982 |
| 176 | realloc(grow(d->alloc + n)); executed (the execution status of this line is deduced): realloc(grow(d->alloc + n)); | - |
| 177 | } executed: }Execution Count:211414 | 211414 |
| 178 | } | - |
| 179 | d->end = e + n; executed (the execution status of this line is deduced): d->end = e + n; | - |
| 180 | return d->array + e; executed: return d->array + e;Execution Count:6954023 | 6954023 |
| 181 | } | - |
| 182 | | - |
| 183 | // ensures that enough space is available to append one element | - |
| 184 | void **QListData::append() | - |
| 185 | { | - |
| 186 | return append(1); executed: return append(1);Execution Count:6950936 | 6950936 |
| 187 | } | - |
| 188 | | - |
| 189 | // ensures that enough space is available to append the list | - |
| 190 | void **QListData::append(const QListData& l) | - |
| 191 | { | - |
| 192 | return append(l.d->end - l.d->begin); executed: return append(l.d->end - l.d->begin);Execution Count:1772 | 1772 |
| 193 | } | - |
| 194 | | - |
| 195 | void **QListData::prepend() | - |
| 196 | { | - |
| 197 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 198 | if (d->begin == 0) { evaluated: d->begin == 0| yes Evaluation Count:25372 | yes Evaluation Count:4248307 |
| 25372-4248307 |
| 199 | if (d->end >= d->alloc / 3) evaluated: d->end >= d->alloc / 3| yes Evaluation Count:24906 | yes Evaluation Count:466 |
| 466-24906 |
| 200 | realloc(grow(d->alloc + 1)); executed: realloc(grow(d->alloc + 1));Execution Count:24906 | 24906 |
| 201 | | - |
| 202 | if (d->end < d->alloc / 3) evaluated: d->end < d->alloc / 3| yes Evaluation Count:18529 | yes Evaluation Count:6843 |
| 6843-18529 |
| 203 | d->begin = d->alloc - 2 * d->end; executed: d->begin = d->alloc - 2 * d->end;Execution Count:18529 | 18529 |
| 204 | else | - |
| 205 | d->begin = d->alloc - d->end; executed: d->begin = d->alloc - d->end;Execution Count:6843 | 6843 |
| 206 | | - |
| 207 | ::memmove(d->array + d->begin, d->array, d->end * sizeof(void *)); executed (the execution status of this line is deduced): ::memmove(d->array + d->begin, d->array, d->end * sizeof(void *)); | - |
| 208 | d->end += d->begin; executed (the execution status of this line is deduced): d->end += d->begin; | - |
| 209 | } executed: }Execution Count:25372 | 25372 |
| 210 | return d->array + --d->begin; executed: return d->array + --d->begin;Execution Count:4273679 | 4273679 |
| 211 | } | - |
| 212 | | - |
| 213 | void **QListData::insert(int i) | - |
| 214 | { | - |
| 215 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 216 | if (i <= 0) evaluated: i <= 0| yes Evaluation Count:4223476 | yes Evaluation Count:1894015 |
| 1894015-4223476 |
| 217 | return prepend(); executed: return prepend();Execution Count:4223476 | 4223476 |
| 218 | int size = d->end - d->begin; executed (the execution status of this line is deduced): int size = d->end - d->begin; | - |
| 219 | if (i >= size) evaluated: i >= size| yes Evaluation Count:1844889 | yes Evaluation Count:49126 |
| 49126-1844889 |
| 220 | return append(); executed: return append();Execution Count:1844889 | 1844889 |
| 221 | | - |
| 222 | bool leftward = false; executed (the execution status of this line is deduced): bool leftward = false; | - |
| 223 | | - |
| 224 | if (d->begin == 0) { evaluated: d->begin == 0| yes Evaluation Count:3199 | yes Evaluation Count:45927 |
| 3199-45927 |
| 225 | if (d->end == d->alloc) { evaluated: d->end == d->alloc| yes Evaluation Count:114 | yes Evaluation Count:3085 |
| 114-3085 |
| 226 | // If the array is full, we expand it and move some items rightward | - |
| 227 | realloc(grow(d->alloc + 1)); executed (the execution status of this line is deduced): realloc(grow(d->alloc + 1)); | - |
| 228 | } else { executed: }Execution Count:114 | 114 |
| 229 | // If there is free space at the end of the array, we move some items rightward | - |
| 230 | } executed: }Execution Count:3085 | 3085 |
| 231 | } else { | - |
| 232 | if (d->end == d->alloc) { evaluated: d->end == d->alloc| yes Evaluation Count:17815 | yes Evaluation Count:28112 |
| 17815-28112 |
| 233 | // If there is free space at the beginning of the array, we move some items leftward | - |
| 234 | leftward = true; executed (the execution status of this line is deduced): leftward = true; | - |
| 235 | } else { executed: }Execution Count:17815 | 17815 |
| 236 | // If there is free space at both ends, we move as few items as possible | - |
| 237 | leftward = (i < size - i); executed (the execution status of this line is deduced): leftward = (i < size - i); | - |
| 238 | } executed: }Execution Count:28112 | 28112 |
| 239 | } | - |
| 240 | | - |
| 241 | if (leftward) { evaluated: leftward| yes Evaluation Count:19452 | yes Evaluation Count:29674 |
| 19452-29674 |
| 242 | --d->begin; executed (the execution status of this line is deduced): --d->begin; | - |
| 243 | ::memmove(d->array + d->begin, d->array + d->begin + 1, i * sizeof(void *)); executed (the execution status of this line is deduced): ::memmove(d->array + d->begin, d->array + d->begin + 1, i * sizeof(void *)); | - |
| 244 | } else { executed: }Execution Count:19452 | 19452 |
| 245 | ::memmove(d->array + d->begin + i + 1, d->array + d->begin + i, executed (the execution status of this line is deduced): ::memmove(d->array + d->begin + i + 1, d->array + d->begin + i, | - |
| 246 | (size - i) * sizeof(void *)); executed (the execution status of this line is deduced): (size - i) * sizeof(void *)); | - |
| 247 | ++d->end; executed (the execution status of this line is deduced): ++d->end; | - |
| 248 | } executed: }Execution Count:29674 | 29674 |
| 249 | return d->array + d->begin + i; executed: return d->array + d->begin + i;Execution Count:49126 | 49126 |
| 250 | } | - |
| 251 | | - |
| 252 | void QListData::remove(int i) | - |
| 253 | { | - |
| 254 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 255 | i += d->begin; executed (the execution status of this line is deduced): i += d->begin; | - |
| 256 | if (i - d->begin < d->end - i) { evaluated: i - d->begin < d->end - i| yes Evaluation Count:6749003 | yes Evaluation Count:670433 |
| 670433-6749003 |
| 257 | if (int offset = i - d->begin) evaluated: int offset = i - d->begin| yes Evaluation Count:27254 | yes Evaluation Count:6721749 |
| 27254-6721749 |
| 258 | ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *)); executed: ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));Execution Count:27254 | 27254 |
| 259 | d->begin++; executed (the execution status of this line is deduced): d->begin++; | - |
| 260 | } else { executed: }Execution Count:6749002 | 6749002 |
| 261 | if (int offset = d->end - i - 1) evaluated: int offset = d->end - i - 1| yes Evaluation Count:516649 | yes Evaluation Count:153784 |
| 153784-516649 |
| 262 | ::memmove(d->array + i, d->array + i + 1, offset * sizeof(void *)); executed: ::memmove(d->array + i, d->array + i + 1, offset * sizeof(void *));Execution Count:516649 | 516649 |
| 263 | d->end--; executed (the execution status of this line is deduced): d->end--; | - |
| 264 | } executed: }Execution Count:670433 | 670433 |
| 265 | } | - |
| 266 | | - |
| 267 | void QListData::remove(int i, int n) | - |
| 268 | { | - |
| 269 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 270 | i += d->begin; executed (the execution status of this line is deduced): i += d->begin; | - |
| 271 | int middle = i + n/2; executed (the execution status of this line is deduced): int middle = i + n/2; | - |
| 272 | if (middle - d->begin < d->end - middle) { evaluated: middle - d->begin < d->end - middle| yes Evaluation Count:43 | yes Evaluation Count:109333 |
| 43-109333 |
| 273 | ::memmove(d->array + d->begin + n, d->array + d->begin, executed (the execution status of this line is deduced): ::memmove(d->array + d->begin + n, d->array + d->begin, | - |
| 274 | (i - d->begin) * sizeof(void*)); executed (the execution status of this line is deduced): (i - d->begin) * sizeof(void*)); | - |
| 275 | d->begin += n; executed (the execution status of this line is deduced): d->begin += n; | - |
| 276 | } else { executed: }Execution Count:43 | 43 |
| 277 | ::memmove(d->array + i, d->array + i + n, executed (the execution status of this line is deduced): ::memmove(d->array + i, d->array + i + n, | - |
| 278 | (d->end - i - n) * sizeof(void*)); executed (the execution status of this line is deduced): (d->end - i - n) * sizeof(void*)); | - |
| 279 | d->end -= n; executed (the execution status of this line is deduced): d->end -= n; | - |
| 280 | } executed: }Execution Count:109332 | 109332 |
| 281 | } | - |
| 282 | | - |
| 283 | void QListData::move(int from, int to) | - |
| 284 | { | - |
| 285 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 286 | if (from == to) evaluated: from == to| yes Evaluation Count:4329 | yes Evaluation Count:5950 |
| 4329-5950 |
| 287 | return; executed: return;Execution Count:4329 | 4329 |
| 288 | | - |
| 289 | from += d->begin; executed (the execution status of this line is deduced): from += d->begin; | - |
| 290 | to += d->begin; executed (the execution status of this line is deduced): to += d->begin; | - |
| 291 | void *t = d->array[from]; executed (the execution status of this line is deduced): void *t = d->array[from]; | - |
| 292 | | - |
| 293 | if (from < to) { evaluated: from < to| yes Evaluation Count:4584 | yes Evaluation Count:1366 |
| 1366-4584 |
| 294 | if (d->end == d->alloc || 3 * (to - from) < 2 * (d->end - d->begin)) { evaluated: d->end == d->alloc| yes Evaluation Count:1133 | yes Evaluation Count:3451 |
evaluated: 3 * (to - from) < 2 * (d->end - d->begin)| yes Evaluation Count:2640 | yes Evaluation Count:811 |
| 811-3451 |
| 295 | ::memmove(d->array + from, d->array + from + 1, (to - from) * sizeof(void *)); executed (the execution status of this line is deduced): ::memmove(d->array + from, d->array + from + 1, (to - from) * sizeof(void *)); | - |
| 296 | } else { executed: }Execution Count:3773 | 3773 |
| 297 | // optimization | - |
| 298 | if (int offset = from - d->begin) evaluated: int offset = from - d->begin| yes Evaluation Count:474 | yes Evaluation Count:337 |
| 337-474 |
| 299 | ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *)); executed: ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));Execution Count:474 | 474 |
| 300 | if (int offset = d->end - (to + 1)) partially evaluated: int offset = d->end - (to + 1)| no Evaluation Count:0 | yes Evaluation Count:811 |
| 0-811 |
| 301 | ::memmove(d->array + to + 2, d->array + to + 1, offset * sizeof(void *)); never executed: ::memmove(d->array + to + 2, d->array + to + 1, offset * sizeof(void *)); | 0 |
| 302 | ++d->begin; executed (the execution status of this line is deduced): ++d->begin; | - |
| 303 | ++d->end; executed (the execution status of this line is deduced): ++d->end; | - |
| 304 | ++to; executed (the execution status of this line is deduced): ++to; | - |
| 305 | } executed: }Execution Count:811 | 811 |
| 306 | } else { | - |
| 307 | if (d->begin == 0 || 3 * (from - to) < 2 * (d->end - d->begin)) { evaluated: d->begin == 0| yes Evaluation Count:899 | yes Evaluation Count:467 |
evaluated: 3 * (from - to) < 2 * (d->end - d->begin)| yes Evaluation Count:35 | yes Evaluation Count:432 |
| 35-899 |
| 308 | ::memmove(d->array + to + 1, d->array + to, (from - to) * sizeof(void *)); executed (the execution status of this line is deduced): ::memmove(d->array + to + 1, d->array + to, (from - to) * sizeof(void *)); | - |
| 309 | } else { executed: }Execution Count:934 | 934 |
| 310 | // optimization | - |
| 311 | if (int offset = to - d->begin) partially evaluated: int offset = to - d->begin| no Evaluation Count:0 | yes Evaluation Count:432 |
| 0-432 |
| 312 | ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * sizeof(void *)); never executed: ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * sizeof(void *)); | 0 |
| 313 | if (int offset = d->end - (from + 1)) evaluated: int offset = d->end - (from + 1)| yes Evaluation Count:388 | yes Evaluation Count:44 |
| 44-388 |
| 314 | ::memmove(d->array + from, d->array + from + 1, offset * sizeof(void *)); executed: ::memmove(d->array + from, d->array + from + 1, offset * sizeof(void *));Execution Count:388 | 388 |
| 315 | --d->begin; executed (the execution status of this line is deduced): --d->begin; | - |
| 316 | --d->end; executed (the execution status of this line is deduced): --d->end; | - |
| 317 | --to; executed (the execution status of this line is deduced): --to; | - |
| 318 | } executed: }Execution Count:432 | 432 |
| 319 | } | - |
| 320 | d->array[to] = t; executed (the execution status of this line is deduced): d->array[to] = t; | - |
| 321 | } executed: }Execution Count:5950 | 5950 |
| 322 | | - |
| 323 | void **QListData::erase(void **xi) | - |
| 324 | { | - |
| 325 | Q_ASSERT(!d->ref.isShared()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 326 | int i = xi - (d->array + d->begin); executed (the execution status of this line is deduced): int i = xi - (d->array + d->begin); | - |
| 327 | remove(i); executed (the execution status of this line is deduced): remove(i); | - |
| 328 | return d->array + d->begin + i; executed: return d->array + d->begin + i;Execution Count:7164638 | 7164638 |
| 329 | } | - |
| 330 | | - |
| 331 | /*! \class QList | - |
| 332 | \inmodule QtCore | - |
| 333 | \brief The QList class is a template class that provides lists. | - |
| 334 | | - |
| 335 | \ingroup tools | - |
| 336 | \ingroup shared | - |
| 337 | | - |
| 338 | \reentrant | - |
| 339 | | - |
| 340 | QList\<T\> is one of Qt's generic \l{container classes}. It | - |
| 341 | stores a list of values and provides fast index-based access as | - |
| 342 | well as fast insertions and removals. | - |
| 343 | | - |
| 344 | QList\<T\>, QLinkedList\<T\>, and QVector\<T\> provide similar | - |
| 345 | functionality. Here's an overview: | - |
| 346 | | - |
| 347 | \list | - |
| 348 | \li For most purposes, QList is the right class to use. Its | - |
| 349 | index-based API is more convenient than QLinkedList's | - |
| 350 | iterator-based API, and it is usually faster than | - |
| 351 | QVector because of the way it stores its items in | - |
| 352 | memory. It also expands to less code in your executable. | - |
| 353 | \li If you need a real linked list, with guarantees of \l{constant | - |
| 354 | time} insertions in the middle of the list and iterators to | - |
| 355 | items rather than indexes, use QLinkedList. | - |
| 356 | \li If you want the items to occupy adjacent memory positions, | - |
| 357 | use QVector. | - |
| 358 | \endlist | - |
| 359 | | - |
| 360 | | - |
| 361 | Internally, QList\<T\> is represented as an array of pointers to | - |
| 362 | items of type T. If T is itself a pointer type or a basic type | - |
| 363 | that is no larger than a pointer, or if T is one of Qt's \l{shared | - |
| 364 | classes}, then QList\<T\> stores the items directly in the pointer | - |
| 365 | array. For lists under a thousand items, this array representation | - |
| 366 | allows for very fast insertions in the middle, and it allows | - |
| 367 | index-based access. Furthermore, operations like prepend() and | - |
| 368 | append() are very fast, because QList preallocates memory at both | - |
| 369 | ends of its internal array. (See \l{Algorithmic Complexity} for | - |
| 370 | details.) Note, however, that for unshared list items that are | - |
| 371 | larger than a pointer, each append or insert of a new item | - |
| 372 | requires allocating the new item on the heap, and this per item | - |
| 373 | allocation might make QVector a better choice in cases that do | - |
| 374 | lots of appending or inserting, since QVector allocates memory for | - |
| 375 | its items in a single heap allocation. | - |
| 376 | | - |
| 377 | Note that the internal array only ever gets bigger over the life | - |
| 378 | of the list. It never shrinks. The internal array is deallocated | - |
| 379 | by the destructor and by the assignment operator, when one list | - |
| 380 | is assigned to another. | - |
| 381 | | - |
| 382 | Here's an example of a QList that stores integers and | - |
| 383 | a QList that stores QDate values: | - |
| 384 | | - |
| 385 | \snippet code/src_corelib_tools_qlistdata.cpp 0 | - |
| 386 | | - |
| 387 | Qt includes a QStringList class that inherits QList\<QString\> | - |
| 388 | and adds a few convenience functions, such as QStringList::join() | - |
| 389 | and QStringList::find(). (QString::split() creates QStringLists | - |
| 390 | from strings.) | - |
| 391 | | - |
| 392 | QList stores a list of items. The default constructor creates an | - |
| 393 | empty list. To insert items into the list, you can use | - |
| 394 | operator<<(): | - |
| 395 | | - |
| 396 | \snippet code/src_corelib_tools_qlistdata.cpp 1 | - |
| 397 | | - |
| 398 | QList provides these basic functions to add, move, and remove | - |
| 399 | items: insert(), replace(), removeAt(), move(), and swap(). In | - |
| 400 | addition, it provides the following convenience functions: | - |
| 401 | append(), prepend(), removeFirst(), and removeLast(). | - |
| 402 | | - |
| 403 | QList uses 0-based indexes, just like C++ arrays. To access the | - |
| 404 | item at a particular index position, you can use operator[](). On | - |
| 405 | non-const lists, operator[]() returns a reference to the item and | - |
| 406 | can be used on the left side of an assignment: | - |
| 407 | | - |
| 408 | \snippet code/src_corelib_tools_qlistdata.cpp 2 | - |
| 409 | | - |
| 410 | Because QList is implemented as an array of pointers, this | - |
| 411 | operation is very fast (\l{constant time}). For read-only access, | - |
| 412 | an alternative syntax is to use at(): | - |
| 413 | | - |
| 414 | \snippet code/src_corelib_tools_qlistdata.cpp 3 | - |
| 415 | | - |
| 416 | at() can be faster than operator[](), because it never causes a | - |
| 417 | \l{deep copy} to occur. | - |
| 418 | | - |
| 419 | A common requirement is to remove an item from a list and do | - |
| 420 | something with it. For this, QList provides takeAt(), takeFirst(), | - |
| 421 | and takeLast(). Here's a loop that removes the items from a list | - |
| 422 | one at a time and calls \c delete on them: | - |
| 423 | | - |
| 424 | \snippet code/src_corelib_tools_qlistdata.cpp 4 | - |
| 425 | | - |
| 426 | Inserting and removing items at either ends of the list is very | - |
| 427 | fast (\l{constant time} in most cases), because QList | - |
| 428 | preallocates extra space on both sides of its internal buffer to | - |
| 429 | allow for fast growth at both ends of the list. | - |
| 430 | | - |
| 431 | If you want to find all occurrences of a particular value in a | - |
| 432 | list, use indexOf() or lastIndexOf(). The former searches forward | - |
| 433 | starting from a given index position, the latter searches | - |
| 434 | backward. Both return the index of a matching item if they find | - |
| 435 | it; otherwise, they return -1. For example: | - |
| 436 | | - |
| 437 | \snippet code/src_corelib_tools_qlistdata.cpp 5 | - |
| 438 | | - |
| 439 | If you simply want to check whether a list contains a particular | - |
| 440 | value, use contains(). If you want to find out how many times a | - |
| 441 | particular value occurs in the list, use count(). If you want to | - |
| 442 | replace all occurrences of a particular value with another, use | - |
| 443 | replace(). | - |
| 444 | | - |
| 445 | QList's value type must be an \l{assignable data type}. This | - |
| 446 | covers most data types that are commonly used, but the compiler | - |
| 447 | won't let you, for example, store a QWidget as a value; instead, | - |
| 448 | store a QWidget *. A few functions have additional requirements; | - |
| 449 | for example, indexOf() and lastIndexOf() expect the value type to | - |
| 450 | support \c operator==(). These requirements are documented on a | - |
| 451 | per-function basis. | - |
| 452 | | - |
| 453 | Like the other container classes, QList provides \l{Java-style | - |
| 454 | iterators} (QListIterator and QMutableListIterator) and | - |
| 455 | \l{STL-style iterators} (QList::const_iterator and | - |
| 456 | QList::iterator). In practice, these are rarely used, because you | - |
| 457 | can use indexes into the QList. QList is implemented in such a way | - |
| 458 | that direct index-based access is just as fast as using iterators. | - |
| 459 | | - |
| 460 | QList does \e not support inserting, prepending, appending or | - |
| 461 | replacing with references to its own values. Doing so will cause | - |
| 462 | your application to abort with an error message. | - |
| 463 | | - |
| 464 | To make QList as efficient as possible, its member functions don't | - |
| 465 | validate their input before using it. Except for isEmpty(), member | - |
| 466 | functions always assume the list is \e not empty. Member functions | - |
| 467 | that take index values as parameters always assume their index | - |
| 468 | value parameters are in the valid range. This means QList member | - |
| 469 | functions can fail. If you define QT_NO_DEBUG when you compile, | - |
| 470 | failures will not be detected. If you \e don't define QT_NO_DEBUG, | - |
| 471 | failures will be detected using Q_ASSERT() or Q_ASSERT_X() with an | - |
| 472 | appropriate message. | - |
| 473 | | - |
| 474 | To avoid failures when your list can be empty, call isEmpty() | - |
| 475 | before calling other member functions. If you must pass an index | - |
| 476 | value that might not be in the valid range, check that it is less | - |
| 477 | than the value returned by size() but \e not less than 0. | - |
| 478 | | - |
| 479 | \sa QListIterator, QMutableListIterator, QLinkedList, QVector | - |
| 480 | */ | - |
| 481 | | - |
| 482 | /*! | - |
| 483 | \fn QList<T> QList<T>::mid(int pos, int length) const | - |
| 484 | | - |
| 485 | Returns a list whose elements are copied from this list, | - |
| 486 | starting at position \a pos. If \a length is -1 (the default), all | - |
| 487 | elements from \a pos are copied; otherwise \a length elements (or | - |
| 488 | all remaining elements if there are less than \a length elements) | - |
| 489 | are copied. | - |
| 490 | */ | - |
| 491 | | - |
| 492 | /*! \fn QList::QList() | - |
| 493 | | - |
| 494 | Constructs an empty list. | - |
| 495 | */ | - |
| 496 | | - |
| 497 | /*! \fn QList::QList(const QList<T> &other) | - |
| 498 | | - |
| 499 | Constructs a copy of \a other. | - |
| 500 | | - |
| 501 | This operation takes \l{constant time}, because QList is | - |
| 502 | \l{implicitly shared}. This makes returning a QList from a | - |
| 503 | function very fast. If a shared instance is modified, it will be | - |
| 504 | copied (copy-on-write), and that takes \l{linear time}. | - |
| 505 | | - |
| 506 | \sa operator=() | - |
| 507 | */ | - |
| 508 | | - |
| 509 | /*! \fn inline QList::QList(std::initializer_list<T> args) | - |
| 510 | \since 4.8 | - |
| 511 | | - |
| 512 | Construct a list from the std::initializer_list specified by \a args. | - |
| 513 | | - |
| 514 | This constructor is only enabled if the compiler supports C++0x | - |
| 515 | */ | - |
| 516 | | - |
| 517 | /*! \fn QList::~QList() | - |
| 518 | | - |
| 519 | Destroys the list. References to the values in the list and all | - |
| 520 | iterators of this list become invalid. | - |
| 521 | */ | - |
| 522 | | - |
| 523 | /*! \fn QList<T> &QList::operator=(const QList<T> &other) | - |
| 524 | | - |
| 525 | Assigns \a other to this list and returns a reference to this | - |
| 526 | list. | - |
| 527 | */ | - |
| 528 | | - |
| 529 | /*! \fn void QList::swap(QList<T> &other) | - |
| 530 | \since 4.8 | - |
| 531 | | - |
| 532 | Swaps list \a other with this list. This operation is very | - |
| 533 | fast and never fails. | - |
| 534 | */ | - |
| 535 | | - |
| 536 | /*! \fn bool QList::operator==(const QList<T> &other) const | - |
| 537 | | - |
| 538 | Returns true if \a other is equal to this list; otherwise returns | - |
| 539 | false. | - |
| 540 | | - |
| 541 | Two lists are considered equal if they contain the same values in | - |
| 542 | the same order. | - |
| 543 | | - |
| 544 | This function requires the value type to have an implementation of | - |
| 545 | \c operator==(). | - |
| 546 | | - |
| 547 | \sa operator!=() | - |
| 548 | */ | - |
| 549 | | - |
| 550 | /*! \fn bool QList::operator!=(const QList<T> &other) const | - |
| 551 | | - |
| 552 | Returns true if \a other is not equal to this list; otherwise | - |
| 553 | returns false. | - |
| 554 | | - |
| 555 | Two lists are considered equal if they contain the same values in | - |
| 556 | the same order. | - |
| 557 | | - |
| 558 | This function requires the value type to have an implementation of | - |
| 559 | \c operator==(). | - |
| 560 | | - |
| 561 | \sa operator==() | - |
| 562 | */ | - |
| 563 | | - |
| 564 | /*! | - |
| 565 | \fn int QList::size() const | - |
| 566 | | - |
| 567 | Returns the number of items in the list. | - |
| 568 | | - |
| 569 | \sa isEmpty(), count() | - |
| 570 | */ | - |
| 571 | | - |
| 572 | /*! \fn void QList::detach() | - |
| 573 | | - |
| 574 | \internal | - |
| 575 | */ | - |
| 576 | | - |
| 577 | /*! \fn void QList::detachShared() | - |
| 578 | | - |
| 579 | \internal | - |
| 580 | | - |
| 581 | like detach(), but does nothing if we're shared_null. | - |
| 582 | This prevents needless mallocs, and makes QList more exception safe | - |
| 583 | in case of cleanup work done in destructors on empty lists. | - |
| 584 | */ | - |
| 585 | | - |
| 586 | /*! \fn bool QList::isDetached() const | - |
| 587 | | - |
| 588 | \internal | - |
| 589 | */ | - |
| 590 | | - |
| 591 | /*! \fn void QList::setSharable(bool sharable) | - |
| 592 | | - |
| 593 | \internal | - |
| 594 | */ | - |
| 595 | | - |
| 596 | /*! \fn bool QList::isSharedWith(const QList<T> &other) const | - |
| 597 | | - |
| 598 | \internal | - |
| 599 | */ | - |
| 600 | | - |
| 601 | /*! \fn bool QList::isEmpty() const | - |
| 602 | | - |
| 603 | Returns true if the list contains no items; otherwise returns | - |
| 604 | false. | - |
| 605 | | - |
| 606 | \sa size() | - |
| 607 | */ | - |
| 608 | | - |
| 609 | /*! \fn void QList::clear() | - |
| 610 | | - |
| 611 | Removes all items from the list. | - |
| 612 | | - |
| 613 | \sa removeAll() | - |
| 614 | */ | - |
| 615 | | - |
| 616 | /*! \fn const T &QList::at(int i) const | - |
| 617 | | - |
| 618 | Returns the item at index position \a i in the list. \a i must be | - |
| 619 | a valid index position in the list (i.e., 0 <= \a i < size()). | - |
| 620 | | - |
| 621 | This function is very fast (\l{constant time}). | - |
| 622 | | - |
| 623 | \sa value(), operator[]() | - |
| 624 | */ | - |
| 625 | | - |
| 626 | /*! \fn T &QList::operator[](int i) | - |
| 627 | | - |
| 628 | Returns the item at index position \a i as a modifiable reference. | - |
| 629 | \a i must be a valid index position in the list (i.e., 0 <= \a i < | - |
| 630 | size()). | - |
| 631 | | - |
| 632 | This function is very fast (\l{constant time}). | - |
| 633 | | - |
| 634 | \sa at(), value() | - |
| 635 | */ | - |
| 636 | | - |
| 637 | /*! \fn const T &QList::operator[](int i) const | - |
| 638 | | - |
| 639 | \overload | - |
| 640 | | - |
| 641 | Same as at(). | - |
| 642 | */ | - |
| 643 | | - |
| 644 | /*! \fn QList::reserve(int alloc) | - |
| 645 | | - |
| 646 | Reserve space for \a alloc elements. | - |
| 647 | | - |
| 648 | If \a alloc is smaller than the current size of the list, nothing will happen. | - |
| 649 | | - |
| 650 | Use this function to avoid repetetive reallocation of QList's internal | - |
| 651 | data if you can predict how many elements will be appended. | - |
| 652 | Note that the reservation applies only to the internal pointer array. | - |
| 653 | | - |
| 654 | \since 4.7 | - |
| 655 | */ | - |
| 656 | | - |
| 657 | /*! \fn void QList::append(const T &value) | - |
| 658 | | - |
| 659 | Inserts \a value at the end of the list. | - |
| 660 | | - |
| 661 | Example: | - |
| 662 | \snippet code/src_corelib_tools_qlistdata.cpp 6 | - |
| 663 | | - |
| 664 | This is the same as list.insert(size(), \a value). | - |
| 665 | | - |
| 666 | This operation is typically very fast (\l{constant time}), | - |
| 667 | because QList preallocates extra space on both sides of its | - |
| 668 | internal buffer to allow for fast growth at both ends of the | - |
| 669 | list. | - |
| 670 | | - |
| 671 | \sa operator<<(), prepend(), insert() | - |
| 672 | */ | - |
| 673 | | - |
| 674 | /*! \fn void QList::append(const QList<T> &value) | - |
| 675 | | - |
| 676 | \overload | - |
| 677 | | - |
| 678 | \since 4.5 | - |
| 679 | | - |
| 680 | Appends the items of the \a value list to this list. | - |
| 681 | | - |
| 682 | \sa operator<<(), operator+=() | - |
| 683 | */ | - |
| 684 | | - |
| 685 | /*! \fn void QList::prepend(const T &value) | - |
| 686 | | - |
| 687 | Inserts \a value at the beginning of the list. | - |
| 688 | | - |
| 689 | Example: | - |
| 690 | \snippet code/src_corelib_tools_qlistdata.cpp 7 | - |
| 691 | | - |
| 692 | This is the same as list.insert(0, \a value). | - |
| 693 | | - |
| 694 | This operation is usually very fast (\l{constant time}), because | - |
| 695 | QList preallocates extra space on both sides of its internal | - |
| 696 | buffer to allow for fast growth at both ends of the list. | - |
| 697 | | - |
| 698 | \sa append(), insert() | - |
| 699 | */ | - |
| 700 | | - |
| 701 | /*! \fn void QList::insert(int i, const T &value) | - |
| 702 | | - |
| 703 | Inserts \a value at index position \a i in the list. If \a i | - |
| 704 | is 0, the value is prepended to the list. If \a i is size(), the | - |
| 705 | value is appended to the list. | - |
| 706 | | - |
| 707 | Example: | - |
| 708 | \snippet code/src_corelib_tools_qlistdata.cpp 8 | - |
| 709 | | - |
| 710 | \sa append(), prepend(), replace(), removeAt() | - |
| 711 | */ | - |
| 712 | | - |
| 713 | /*! \fn QList::iterator QList::insert(iterator before, const T &value) | - |
| 714 | | - |
| 715 | \overload | - |
| 716 | | - |
| 717 | Inserts \a value in front of the item pointed to by the | - |
| 718 | iterator \a before. Returns an iterator pointing at the inserted | - |
| 719 | item. Note that the iterator passed to the function will be | - |
| 720 | invalid after the call; the returned iterator should be used | - |
| 721 | instead. | - |
| 722 | */ | - |
| 723 | | - |
| 724 | /*! \fn void QList::replace(int i, const T &value) | - |
| 725 | | - |
| 726 | Replaces the item at index position \a i with \a value. \a i must | - |
| 727 | be a valid index position in the list (i.e., 0 <= \a i < size()). | - |
| 728 | | - |
| 729 | \sa operator[](), removeAt() | - |
| 730 | */ | - |
| 731 | | - |
| 732 | /*! | - |
| 733 | \fn int QList::removeAll(const T &value) | - |
| 734 | | - |
| 735 | Removes all occurrences of \a value in the list and returns the | - |
| 736 | number of entries removed. | - |
| 737 | | - |
| 738 | Example: | - |
| 739 | \snippet code/src_corelib_tools_qlistdata.cpp 9 | - |
| 740 | | - |
| 741 | This function requires the value type to have an implementation of | - |
| 742 | \c operator==(). | - |
| 743 | | - |
| 744 | \sa removeOne(), removeAt(), takeAt(), replace() | - |
| 745 | */ | - |
| 746 | | - |
| 747 | /*! | - |
| 748 | \fn bool QList::removeOne(const T &value) | - |
| 749 | \since 4.4 | - |
| 750 | | - |
| 751 | Removes the first occurrence of \a value in the list and returns | - |
| 752 | true on success; otherwise returns false. | - |
| 753 | | - |
| 754 | Example: | - |
| 755 | \snippet code/src_corelib_tools_qlistdata.cpp 10 | - |
| 756 | | - |
| 757 | This function requires the value type to have an implementation of | - |
| 758 | \c operator==(). | - |
| 759 | | - |
| 760 | \sa removeAll(), removeAt(), takeAt(), replace() | - |
| 761 | */ | - |
| 762 | | - |
| 763 | /*! \fn void QList::removeAt(int i) | - |
| 764 | | - |
| 765 | Removes the item at index position \a i. \a i must be a valid | - |
| 766 | index position in the list (i.e., 0 <= \a i < size()). | - |
| 767 | | - |
| 768 | \sa takeAt(), removeFirst(), removeLast(), removeOne() | - |
| 769 | */ | - |
| 770 | | - |
| 771 | /*! \fn T QList::takeAt(int i) | - |
| 772 | | - |
| 773 | Removes the item at index position \a i and returns it. \a i must | - |
| 774 | be a valid index position in the list (i.e., 0 <= \a i < size()). | - |
| 775 | | - |
| 776 | If you don't use the return value, removeAt() is more efficient. | - |
| 777 | | - |
| 778 | \sa removeAt(), takeFirst(), takeLast() | - |
| 779 | */ | - |
| 780 | | - |
| 781 | /*! \fn T QList::takeFirst() | - |
| 782 | | - |
| 783 | Removes the first item in the list and returns it. This is the | - |
| 784 | same as takeAt(0). This function assumes the list is not empty. To | - |
| 785 | avoid failure, call isEmpty() before calling this function. | - |
| 786 | | - |
| 787 | This operation takes \l{constant time}. | - |
| 788 | | - |
| 789 | If you don't use the return value, removeFirst() is more | - |
| 790 | efficient. | - |
| 791 | | - |
| 792 | \sa takeLast(), takeAt(), removeFirst() | - |
| 793 | */ | - |
| 794 | | - |
| 795 | /*! \fn T QList::takeLast() | - |
| 796 | | - |
| 797 | Removes the last item in the list and returns it. This is the | - |
| 798 | same as takeAt(size() - 1). This function assumes the list is | - |
| 799 | not empty. To avoid failure, call isEmpty() before calling this | - |
| 800 | function. | - |
| 801 | | - |
| 802 | This operation takes \l{constant time}. | - |
| 803 | | - |
| 804 | If you don't use the return value, removeLast() is more | - |
| 805 | efficient. | - |
| 806 | | - |
| 807 | \sa takeFirst(), takeAt(), removeLast() | - |
| 808 | */ | - |
| 809 | | - |
| 810 | /*! \fn void QList::move(int from, int to) | - |
| 811 | | - |
| 812 | Moves the item at index position \a from to index position \a to. | - |
| 813 | | - |
| 814 | Example: | - |
| 815 | \snippet code/src_corelib_tools_qlistdata.cpp 11 | - |
| 816 | | - |
| 817 | This is the same as insert(\a{to}, takeAt(\a{from})).This function | - |
| 818 | assumes that both \a from and \a to are at least 0 but less than | - |
| 819 | size(). To avoid failure, test that both \a from and \a to are at | - |
| 820 | least 0 and less than size(). | - |
| 821 | | - |
| 822 | \sa swap(), insert(), takeAt() | - |
| 823 | */ | - |
| 824 | | - |
| 825 | /*! \fn void QList::swap(int i, int j) | - |
| 826 | | - |
| 827 | Exchange the item at index position \a i with the item at index | - |
| 828 | position \a j. This function assumes that both \a i and \a j are | - |
| 829 | at least 0 but less than size(). To avoid failure, test that both | - |
| 830 | \a i and \a j are at least 0 and less than size(). | - |
| 831 | | - |
| 832 | Example: | - |
| 833 | \snippet code/src_corelib_tools_qlistdata.cpp 12 | - |
| 834 | | - |
| 835 | \sa move() | - |
| 836 | */ | - |
| 837 | | - |
| 838 | /*! \fn int QList::indexOf(const T &value, int from = 0) const | - |
| 839 | | - |
| 840 | Returns the index position of the first occurrence of \a value in | - |
| 841 | the list, searching forward from index position \a from. Returns | - |
| 842 | -1 if no item matched. | - |
| 843 | | - |
| 844 | Example: | - |
| 845 | \snippet code/src_corelib_tools_qlistdata.cpp 13 | - |
| 846 | | - |
| 847 | This function requires the value type to have an implementation of | - |
| 848 | \c operator==(). | - |
| 849 | | - |
| 850 | Note that QList uses 0-based indexes, just like C++ arrays. Negative | - |
| 851 | indexes are not supported with the exception of the value mentioned | - |
| 852 | above. | - |
| 853 | | - |
| 854 | \sa lastIndexOf(), contains() | - |
| 855 | */ | - |
| 856 | | - |
| 857 | /*! \fn int QList::lastIndexOf(const T &value, int from = -1) const | - |
| 858 | | - |
| 859 | Returns the index position of the last occurrence of \a value in | - |
| 860 | the list, searching backward from index position \a from. If \a | - |
| 861 | from is -1 (the default), the search starts at the last item. | - |
| 862 | Returns -1 if no item matched. | - |
| 863 | | - |
| 864 | Example: | - |
| 865 | \snippet code/src_corelib_tools_qlistdata.cpp 14 | - |
| 866 | | - |
| 867 | This function requires the value type to have an implementation of | - |
| 868 | \c operator==(). | - |
| 869 | | - |
| 870 | Note that QList uses 0-based indexes, just like C++ arrays. Negative | - |
| 871 | indexes are not supported with the exception of the value mentioned | - |
| 872 | above. | - |
| 873 | | - |
| 874 | \sa indexOf() | - |
| 875 | */ | - |
| 876 | | - |
| 877 | /*! \fn bool QList::contains(const T &value) const | - |
| 878 | | - |
| 879 | Returns true if the list contains an occurrence of \a value; | - |
| 880 | otherwise returns false. | - |
| 881 | | - |
| 882 | This function requires the value type to have an implementation of | - |
| 883 | \c operator==(). | - |
| 884 | | - |
| 885 | \sa indexOf(), count() | - |
| 886 | */ | - |
| 887 | | - |
| 888 | /*! \fn int QList::count(const T &value) const | - |
| 889 | | - |
| 890 | Returns the number of occurrences of \a value in the list. | - |
| 891 | | - |
| 892 | This function requires the value type to have an implementation of | - |
| 893 | \c operator==(). | - |
| 894 | | - |
| 895 | \sa contains(), indexOf() | - |
| 896 | */ | - |
| 897 | | - |
| 898 | /*! \fn bool QList::startsWith(const T &value) const | - |
| 899 | \since 4.5 | - |
| 900 | | - |
| 901 | Returns true if this list is not empty and its first | - |
| 902 | item is equal to \a value; otherwise returns false. | - |
| 903 | | - |
| 904 | \sa isEmpty(), contains() | - |
| 905 | */ | - |
| 906 | | - |
| 907 | /*! \fn bool QList::endsWith(const T &value) const | - |
| 908 | \since 4.5 | - |
| 909 | | - |
| 910 | Returns true if this list is not empty and its last | - |
| 911 | item is equal to \a value; otherwise returns false. | - |
| 912 | | - |
| 913 | \sa isEmpty(), contains() | - |
| 914 | */ | - |
| 915 | | - |
| 916 | /*! \fn QList::iterator QList::begin() | - |
| 917 | | - |
| 918 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in | - |
| 919 | the list. | - |
| 920 | | - |
| 921 | \sa constBegin(), end() | - |
| 922 | */ | - |
| 923 | | - |
| 924 | /*! \fn QList::const_iterator QList::begin() const | - |
| 925 | | - |
| 926 | \overload | - |
| 927 | */ | - |
| 928 | | - |
| 929 | /*! \fn QList::const_iterator QList::cbegin() const | - |
| 930 | \since 5.0 | - |
| 931 | | - |
| 932 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item | - |
| 933 | in the list. | - |
| 934 | | - |
| 935 | \sa begin(), cend() | - |
| 936 | */ | - |
| 937 | | - |
| 938 | /*! \fn QList::const_iterator QList::constBegin() const | - |
| 939 | | - |
| 940 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item | - |
| 941 | in the list. | - |
| 942 | | - |
| 943 | \sa begin(), constEnd() | - |
| 944 | */ | - |
| 945 | | - |
| 946 | /*! \fn QList::iterator QList::end() | - |
| 947 | | - |
| 948 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item | - |
| 949 | after the last item in the list. | - |
| 950 | | - |
| 951 | \sa begin(), constEnd() | - |
| 952 | */ | - |
| 953 | | - |
| 954 | /*! \fn const_iterator QList::end() const | - |
| 955 | | - |
| 956 | \overload | - |
| 957 | */ | - |
| 958 | | - |
| 959 | /*! \fn QList::const_iterator QList::cend() const | - |
| 960 | \since 5.0 | - |
| 961 | | - |
| 962 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - |
| 963 | item after the last item in the list. | - |
| 964 | | - |
| 965 | \sa cbegin(), end() | - |
| 966 | */ | - |
| 967 | | - |
| 968 | /*! \fn QList::const_iterator QList::constEnd() const | - |
| 969 | | - |
| 970 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - |
| 971 | item after the last item in the list. | - |
| 972 | | - |
| 973 | \sa constBegin(), end() | - |
| 974 | */ | - |
| 975 | | - |
| 976 | /*! \fn QList::iterator QList::erase(iterator pos) | - |
| 977 | | - |
| 978 | Removes the item associated with the iterator \a pos from the | - |
| 979 | list, and returns an iterator to the next item in the list (which | - |
| 980 | may be end()). | - |
| 981 | | - |
| 982 | \sa insert(), removeAt() | - |
| 983 | */ | - |
| 984 | | - |
| 985 | /*! \fn QList::iterator QList::erase(iterator begin, iterator end) | - |
| 986 | | - |
| 987 | \overload | - |
| 988 | | - |
| 989 | Removes all the items from \a begin up to (but not including) \a | - |
| 990 | end. Returns an iterator to the same item that \a end referred to | - |
| 991 | before the call. | - |
| 992 | */ | - |
| 993 | | - |
| 994 | /*! \typedef QList::Iterator | - |
| 995 | | - |
| 996 | Qt-style synonym for QList::iterator. | - |
| 997 | */ | - |
| 998 | | - |
| 999 | /*! \typedef QList::ConstIterator | - |
| 1000 | | - |
| 1001 | Qt-style synonym for QList::const_iterator. | - |
| 1002 | */ | - |
| 1003 | | - |
| 1004 | /*! | - |
| 1005 | \typedef QList::size_type | - |
| 1006 | | - |
| 1007 | Typedef for int. Provided for STL compatibility. | - |
| 1008 | */ | - |
| 1009 | | - |
| 1010 | /*! | - |
| 1011 | \typedef QList::value_type | - |
| 1012 | | - |
| 1013 | Typedef for T. Provided for STL compatibility. | - |
| 1014 | */ | - |
| 1015 | | - |
| 1016 | /*! | - |
| 1017 | \typedef QList::difference_type | - |
| 1018 | | - |
| 1019 | Typedef for ptrdiff_t. Provided for STL compatibility. | - |
| 1020 | */ | - |
| 1021 | | - |
| 1022 | /*! | - |
| 1023 | \typedef QList::pointer | - |
| 1024 | | - |
| 1025 | Typedef for T *. Provided for STL compatibility. | - |
| 1026 | */ | - |
| 1027 | | - |
| 1028 | /*! | - |
| 1029 | \typedef QList::const_pointer | - |
| 1030 | | - |
| 1031 | Typedef for const T *. Provided for STL compatibility. | - |
| 1032 | */ | - |
| 1033 | | - |
| 1034 | /*! | - |
| 1035 | \typedef QList::reference | - |
| 1036 | | - |
| 1037 | Typedef for T &. Provided for STL compatibility. | - |
| 1038 | */ | - |
| 1039 | | - |
| 1040 | /*! | - |
| 1041 | \typedef QList::const_reference | - |
| 1042 | | - |
| 1043 | Typedef for const T &. Provided for STL compatibility. | - |
| 1044 | */ | - |
| 1045 | | - |
| 1046 | /*! \fn int QList::count() const | - |
| 1047 | | - |
| 1048 | Returns the number of items in the list. This is effectively the | - |
| 1049 | same as size(). | - |
| 1050 | */ | - |
| 1051 | | - |
| 1052 | /*! \fn int QList::length() const | - |
| 1053 | \since 4.5 | - |
| 1054 | | - |
| 1055 | This function is identical to count(). | - |
| 1056 | | - |
| 1057 | \sa count() | - |
| 1058 | */ | - |
| 1059 | | - |
| 1060 | /*! \fn T& QList::first() | - |
| 1061 | | - |
| 1062 | Returns a reference to the first item in the list. The list must | - |
| 1063 | not be empty. If the list can be empty, call isEmpty() before | - |
| 1064 | calling this function. | - |
| 1065 | | - |
| 1066 | \sa last(), isEmpty() | - |
| 1067 | */ | - |
| 1068 | | - |
| 1069 | /*! \fn const T& QList::first() const | - |
| 1070 | | - |
| 1071 | \overload | - |
| 1072 | */ | - |
| 1073 | | - |
| 1074 | /*! \fn T& QList::last() | - |
| 1075 | | - |
| 1076 | Returns a reference to the last item in the list. The list must | - |
| 1077 | not be empty. If the list can be empty, call isEmpty() before | - |
| 1078 | calling this function. | - |
| 1079 | | - |
| 1080 | \sa first(), isEmpty() | - |
| 1081 | */ | - |
| 1082 | | - |
| 1083 | /*! \fn const T& QList::last() const | - |
| 1084 | | - |
| 1085 | \overload | - |
| 1086 | */ | - |
| 1087 | | - |
| 1088 | /*! \fn void QList::removeFirst() | - |
| 1089 | | - |
| 1090 | Removes the first item in the list. Calling this function is | - |
| 1091 | equivalent to calling removeAt(0). The list must not be empty. If | - |
| 1092 | the list can be empty, call isEmpty() before calling this | - |
| 1093 | function. | - |
| 1094 | | - |
| 1095 | \sa removeAt(), takeFirst() | - |
| 1096 | */ | - |
| 1097 | | - |
| 1098 | /*! \fn void QList::removeLast() | - |
| 1099 | | - |
| 1100 | Removes the last item in the list. Calling this function is | - |
| 1101 | equivalent to calling removeAt(size() - 1). The list must not be | - |
| 1102 | empty. If the list can be empty, call isEmpty() before calling | - |
| 1103 | this function. | - |
| 1104 | | - |
| 1105 | \sa removeAt(), takeLast() | - |
| 1106 | */ | - |
| 1107 | | - |
| 1108 | /*! \fn T QList::value(int i) const | - |
| 1109 | | - |
| 1110 | Returns the value at index position \a i in the list. | - |
| 1111 | | - |
| 1112 | If the index \a i is out of bounds, the function returns a | - |
| 1113 | \l{default-constructed value}. If you are certain that the index | - |
| 1114 | is going to be within bounds, you can use at() instead, which is | - |
| 1115 | slightly faster. | - |
| 1116 | | - |
| 1117 | \sa at(), operator[]() | - |
| 1118 | */ | - |
| 1119 | | - |
| 1120 | /*! \fn T QList::value(int i, const T &defaultValue) const | - |
| 1121 | | - |
| 1122 | \overload | - |
| 1123 | | - |
| 1124 | If the index \a i is out of bounds, the function returns | - |
| 1125 | \a defaultValue. | - |
| 1126 | */ | - |
| 1127 | | - |
| 1128 | /*! \fn void QList::push_back(const T &value) | - |
| 1129 | | - |
| 1130 | This function is provided for STL compatibility. It is equivalent | - |
| 1131 | to \l{QList::append()}{append(\a value)}. | - |
| 1132 | */ | - |
| 1133 | | - |
| 1134 | /*! \fn void QList::push_front(const T &value) | - |
| 1135 | | - |
| 1136 | This function is provided for STL compatibility. It is equivalent | - |
| 1137 | to \l{QList::prepend()}{prepend(\a value)}. | - |
| 1138 | */ | - |
| 1139 | | - |
| 1140 | /*! \fn T& QList::front() | - |
| 1141 | | - |
| 1142 | This function is provided for STL compatibility. It is equivalent | - |
| 1143 | to first(). The list must not be empty. If the list can be empty, | - |
| 1144 | call isEmpty() before calling this function. | - |
| 1145 | */ | - |
| 1146 | | - |
| 1147 | /*! \fn const T& QList::front() const | - |
| 1148 | | - |
| 1149 | \overload | - |
| 1150 | */ | - |
| 1151 | | - |
| 1152 | /*! \fn T& QList::back() | - |
| 1153 | | - |
| 1154 | This function is provided for STL compatibility. It is equivalent | - |
| 1155 | to last(). The list must not be empty. If the list can be empty, | - |
| 1156 | call isEmpty() before calling this function. | - |
| 1157 | */ | - |
| 1158 | | - |
| 1159 | /*! \fn const T& QList::back() const | - |
| 1160 | | - |
| 1161 | \overload | - |
| 1162 | */ | - |
| 1163 | | - |
| 1164 | /*! \fn void QList::pop_front() | - |
| 1165 | | - |
| 1166 | This function is provided for STL compatibility. It is equivalent | - |
| 1167 | to removeFirst(). The list must not be empty. If the list can be | - |
| 1168 | empty, call isEmpty() before calling this function. | - |
| 1169 | */ | - |
| 1170 | | - |
| 1171 | /*! \fn void QList::pop_back() | - |
| 1172 | | - |
| 1173 | This function is provided for STL compatibility. It is equivalent | - |
| 1174 | to removeLast(). The list must not be empty. If the list can be | - |
| 1175 | empty, call isEmpty() before calling this function. | - |
| 1176 | */ | - |
| 1177 | | - |
| 1178 | /*! \fn bool QList::empty() const | - |
| 1179 | | - |
| 1180 | This function is provided for STL compatibility. It is equivalent | - |
| 1181 | to isEmpty() and returns true if the list is empty. | - |
| 1182 | */ | - |
| 1183 | | - |
| 1184 | /*! \fn QList<T> &QList::operator+=(const QList<T> &other) | - |
| 1185 | | - |
| 1186 | Appends the items of the \a other list to this list and returns a | - |
| 1187 | reference to this list. | - |
| 1188 | | - |
| 1189 | \sa operator+(), append() | - |
| 1190 | */ | - |
| 1191 | | - |
| 1192 | /*! \fn void QList::operator+=(const T &value) | - |
| 1193 | | - |
| 1194 | \overload | - |
| 1195 | | - |
| 1196 | Appends \a value to the list. | - |
| 1197 | | - |
| 1198 | \sa append(), operator<<() | - |
| 1199 | */ | - |
| 1200 | | - |
| 1201 | /*! \fn QList<T> QList::operator+(const QList<T> &other) const | - |
| 1202 | | - |
| 1203 | Returns a list that contains all the items in this list followed | - |
| 1204 | by all the items in the \a other list. | - |
| 1205 | | - |
| 1206 | \sa operator+=() | - |
| 1207 | */ | - |
| 1208 | | - |
| 1209 | /*! \fn QList<T> &QList::operator<<(const QList<T> &other) | - |
| 1210 | | - |
| 1211 | Appends the items of the \a other list to this list and returns a | - |
| 1212 | reference to this list. | - |
| 1213 | | - |
| 1214 | \sa operator+=(), append() | - |
| 1215 | */ | - |
| 1216 | | - |
| 1217 | /*! \fn void QList::operator<<(const T &value) | - |
| 1218 | | - |
| 1219 | \overload | - |
| 1220 | | - |
| 1221 | Appends \a value to the list. | - |
| 1222 | */ | - |
| 1223 | | - |
| 1224 | /*! \class QList::iterator | - |
| 1225 | \inmodule QtCore | - |
| 1226 | \brief The QList::iterator class provides an STL-style non-const iterator for QList and QQueue. | - |
| 1227 | | - |
| 1228 | QList features both \l{STL-style iterators} and \l{Java-style | - |
| 1229 | iterators}. The STL-style iterators are more low-level and more | - |
| 1230 | cumbersome to use; on the other hand, they are slightly faster | - |
| 1231 | and, for developers who already know STL, have the advantage of | - |
| 1232 | familiarity. | - |
| 1233 | | - |
| 1234 | QList\<T\>::iterator allows you to iterate over a QList\<T\> (or | - |
| 1235 | QQueue\<T\>) and to modify the list item associated with the | - |
| 1236 | iterator. If you want to iterate over a const QList, use | - |
| 1237 | QList::const_iterator instead. It is generally good practice to | - |
| 1238 | use QList::const_iterator on a non-const QList as well, unless | - |
| 1239 | you need to change the QList through the iterator. Const | - |
| 1240 | iterators are slightly faster, and can improve code readability. | - |
| 1241 | | - |
| 1242 | The default QList::iterator constructor creates an uninitialized | - |
| 1243 | iterator. You must initialize it using a QList function like | - |
| 1244 | QList::begin(), QList::end(), or QList::insert() before you can | - |
| 1245 | start iterating. Here's a typical loop that prints all the items | - |
| 1246 | stored in a list: | - |
| 1247 | | - |
| 1248 | \snippet code/src_corelib_tools_qlistdata.cpp 15 | - |
| 1249 | | - |
| 1250 | Let's see a few examples of things we can do with a | - |
| 1251 | QList::iterator that we cannot do with a QList::const_iterator. | - |
| 1252 | Here's an example that increments every value stored in a | - |
| 1253 | QList\<int\> by 2: | - |
| 1254 | | - |
| 1255 | \snippet code/src_corelib_tools_qlistdata.cpp 16 | - |
| 1256 | | - |
| 1257 | Most QList functions accept an integer index rather than an | - |
| 1258 | iterator. For that reason, iterators are rarely useful in | - |
| 1259 | connection with QList. One place where STL-style iterators do | - |
| 1260 | make sense is as arguments to \l{generic algorithms}. | - |
| 1261 | | - |
| 1262 | For example, here's how to delete all the widgets stored in a | - |
| 1263 | QList\<QWidget *\>: | - |
| 1264 | | - |
| 1265 | \snippet code/src_corelib_tools_qlistdata.cpp 17 | - |
| 1266 | | - |
| 1267 | Multiple iterators can be used on the same list. However, be | - |
| 1268 | aware that any non-const function call performed on the QList | - |
| 1269 | will render all existing iterators undefined. If you need to keep | - |
| 1270 | iterators over a long period of time, we recommend that you use | - |
| 1271 | QLinkedList rather than QList. | - |
| 1272 | | - |
| 1273 | \sa QList::const_iterator, QMutableListIterator | - |
| 1274 | */ | - |
| 1275 | | - |
| 1276 | /*! \typedef QList::iterator::iterator_category | - |
| 1277 | | - |
| 1278 | A synonym for \e {std::random_access_iterator_tag} indicating | - |
| 1279 | this iterator is a random access iterator. | - |
| 1280 | */ | - |
| 1281 | | - |
| 1282 | /*! \typedef QList::iterator::difference_type | - |
| 1283 | | - |
| 1284 | \internal | - |
| 1285 | */ | - |
| 1286 | | - |
| 1287 | /*! \typedef QList::iterator::value_type | - |
| 1288 | | - |
| 1289 | \internal | - |
| 1290 | */ | - |
| 1291 | | - |
| 1292 | /*! \typedef QList::iterator::pointer | - |
| 1293 | | - |
| 1294 | \internal | - |
| 1295 | */ | - |
| 1296 | | - |
| 1297 | /*! \typedef QList::iterator::reference | - |
| 1298 | | - |
| 1299 | \internal | - |
| 1300 | */ | - |
| 1301 | | - |
| 1302 | /*! \fn QList::iterator::iterator() | - |
| 1303 | | - |
| 1304 | Constructs an uninitialized iterator. | - |
| 1305 | | - |
| 1306 | Functions like operator*() and operator++() should not be called | - |
| 1307 | on an uninitialized iterator. Use operator=() to assign a value | - |
| 1308 | to it before using it. | - |
| 1309 | | - |
| 1310 | \sa QList::begin(), QList::end() | - |
| 1311 | */ | - |
| 1312 | | - |
| 1313 | /*! \fn QList::iterator::iterator(Node *node) | - |
| 1314 | | - |
| 1315 | \internal | - |
| 1316 | */ | - |
| 1317 | | - |
| 1318 | /*! \fn QList::iterator::iterator(const iterator &other) | - |
| 1319 | | - |
| 1320 | Constructs a copy of \a other. | - |
| 1321 | */ | - |
| 1322 | | - |
| 1323 | /*! \fn T &QList::iterator::operator*() const | - |
| 1324 | | - |
| 1325 | Returns a modifiable reference to the current item. | - |
| 1326 | | - |
| 1327 | You can change the value of an item by using operator*() on the | - |
| 1328 | left side of an assignment, for example: | - |
| 1329 | | - |
| 1330 | \snippet code/src_corelib_tools_qlistdata.cpp 18 | - |
| 1331 | | - |
| 1332 | \sa operator->() | - |
| 1333 | */ | - |
| 1334 | | - |
| 1335 | /*! \fn T *QList::iterator::operator->() const | - |
| 1336 | | - |
| 1337 | Returns a pointer to the current item. | - |
| 1338 | | - |
| 1339 | \sa operator*() | - |
| 1340 | */ | - |
| 1341 | | - |
| 1342 | /*! \fn T &QList::iterator::operator[](int j) const | - |
| 1343 | | - |
| 1344 | Returns a modifiable reference to the item at position *this + | - |
| 1345 | \a{j}. | - |
| 1346 | | - |
| 1347 | This function is provided to make QList iterators behave like C++ | - |
| 1348 | pointers. | - |
| 1349 | | - |
| 1350 | \sa operator+() | - |
| 1351 | */ | - |
| 1352 | | - |
| 1353 | /*! | - |
| 1354 | \fn bool QList::iterator::operator==(const iterator &other) const | - |
| 1355 | \fn bool QList::iterator::operator==(const const_iterator &other) const | - |
| 1356 | | - |
| 1357 | Returns true if \a other points to the same item as this | - |
| 1358 | iterator; otherwise returns false. | - |
| 1359 | | - |
| 1360 | \sa operator!=() | - |
| 1361 | */ | - |
| 1362 | | - |
| 1363 | /*! | - |
| 1364 | \fn bool QList::iterator::operator!=(const iterator &other) const | - |
| 1365 | \fn bool QList::iterator::operator!=(const const_iterator &other) const | - |
| 1366 | | - |
| 1367 | Returns true if \a other points to a different item than this | - |
| 1368 | iterator; otherwise returns false. | - |
| 1369 | | - |
| 1370 | \sa operator==() | - |
| 1371 | */ | - |
| 1372 | | - |
| 1373 | /*! | - |
| 1374 | \fn bool QList::iterator::operator<(const iterator& other) const | - |
| 1375 | \fn bool QList::iterator::operator<(const const_iterator& other) const | - |
| 1376 | | - |
| 1377 | Returns true if the item pointed to by this iterator is less than | - |
| 1378 | the item pointed to by the \a other iterator. | - |
| 1379 | */ | - |
| 1380 | | - |
| 1381 | /*! | - |
| 1382 | \fn bool QList::iterator::operator<=(const iterator& other) const | - |
| 1383 | \fn bool QList::iterator::operator<=(const const_iterator& other) const | - |
| 1384 | | - |
| 1385 | Returns true if the item pointed to by this iterator is less than | - |
| 1386 | or equal to the item pointed to by the \a other iterator. | - |
| 1387 | */ | - |
| 1388 | | - |
| 1389 | /*! | - |
| 1390 | \fn bool QList::iterator::operator>(const iterator& other) const | - |
| 1391 | \fn bool QList::iterator::operator>(const const_iterator& other) const | - |
| 1392 | | - |
| 1393 | Returns true if the item pointed to by this iterator is greater | - |
| 1394 | than the item pointed to by the \a other iterator. | - |
| 1395 | */ | - |
| 1396 | | - |
| 1397 | /*! | - |
| 1398 | \fn bool QList::iterator::operator>=(const iterator& other) const | - |
| 1399 | \fn bool QList::iterator::operator>=(const const_iterator& other) const | - |
| 1400 | | - |
| 1401 | Returns true if the item pointed to by this iterator is greater | - |
| 1402 | than or equal to the item pointed to by the \a other iterator. | - |
| 1403 | */ | - |
| 1404 | | - |
| 1405 | /*! \fn QList::iterator &QList::iterator::operator++() | - |
| 1406 | | - |
| 1407 | The prefix ++ operator (\c{++it}) advances the iterator to the | - |
| 1408 | next item in the list and returns an iterator to the new current | - |
| 1409 | item. | - |
| 1410 | | - |
| 1411 | Calling this function on QList::end() leads to undefined results. | - |
| 1412 | | - |
| 1413 | \sa operator--() | - |
| 1414 | */ | - |
| 1415 | | - |
| 1416 | /*! \fn QList::iterator QList::iterator::operator++(int) | - |
| 1417 | | - |
| 1418 | \overload | - |
| 1419 | | - |
| 1420 | The postfix ++ operator (\c{it++}) advances the iterator to the | - |
| 1421 | next item in the list and returns an iterator to the previously | - |
| 1422 | current item. | - |
| 1423 | */ | - |
| 1424 | | - |
| 1425 | /*! \fn QList::iterator &QList::iterator::operator--() | - |
| 1426 | | - |
| 1427 | The prefix -- operator (\c{--it}) makes the preceding item | - |
| 1428 | current and returns an iterator to the new current item. | - |
| 1429 | | - |
| 1430 | Calling this function on QList::begin() leads to undefined results. | - |
| 1431 | | - |
| 1432 | \sa operator++() | - |
| 1433 | */ | - |
| 1434 | | - |
| 1435 | /*! \fn QList::iterator QList::iterator::operator--(int) | - |
| 1436 | | - |
| 1437 | \overload | - |
| 1438 | | - |
| 1439 | The postfix -- operator (\c{it--}) makes the preceding item | - |
| 1440 | current and returns an iterator to the previously current item. | - |
| 1441 | */ | - |
| 1442 | | - |
| 1443 | /*! \fn QList::iterator &QList::iterator::operator+=(int j) | - |
| 1444 | | - |
| 1445 | Advances the iterator by \a j items. (If \a j is negative, the | - |
| 1446 | iterator goes backward.) | - |
| 1447 | | - |
| 1448 | \sa operator-=(), operator+() | - |
| 1449 | */ | - |
| 1450 | | - |
| 1451 | /*! \fn QList::iterator &QList::iterator::operator-=(int j) | - |
| 1452 | | - |
| 1453 | Makes the iterator go back by \a j items. (If \a j is negative, | - |
| 1454 | the iterator goes forward.) | - |
| 1455 | | - |
| 1456 | \sa operator+=(), operator-() | - |
| 1457 | */ | - |
| 1458 | | - |
| 1459 | /*! \fn QList::iterator QList::iterator::operator+(int j) const | - |
| 1460 | | - |
| 1461 | Returns an iterator to the item at \a j positions forward from | - |
| 1462 | this iterator. (If \a j is negative, the iterator goes backward.) | - |
| 1463 | | - |
| 1464 | \sa operator-(), operator+=() | - |
| 1465 | */ | - |
| 1466 | | - |
| 1467 | /*! \fn QList::iterator QList::iterator::operator-(int j) const | - |
| 1468 | | - |
| 1469 | Returns an iterator to the item at \a j positions backward from | - |
| 1470 | this iterator. (If \a j is negative, the iterator goes forward.) | - |
| 1471 | | - |
| 1472 | \sa operator+(), operator-=() | - |
| 1473 | */ | - |
| 1474 | | - |
| 1475 | /*! \fn int QList::iterator::operator-(iterator other) const | - |
| 1476 | | - |
| 1477 | Returns the number of items between the item pointed to by \a | - |
| 1478 | other and the item pointed to by this iterator. | - |
| 1479 | */ | - |
| 1480 | | - |
| 1481 | /*! \class QList::const_iterator | - |
| 1482 | \inmodule QtCore | - |
| 1483 | \brief The QList::const_iterator class provides an STL-style const iterator for QList and QQueue. | - |
| 1484 | | - |
| 1485 | QList provides both \l{STL-style iterators} and \l{Java-style | - |
| 1486 | iterators}. The STL-style iterators are more low-level and more | - |
| 1487 | cumbersome to use; on the other hand, they are slightly faster | - |
| 1488 | and, for developers who already know STL, have the advantage of | - |
| 1489 | familiarity. | - |
| 1490 | | - |
| 1491 | QList\<T\>::const_iterator allows you to iterate over a | - |
| 1492 | QList\<T\> (or a QQueue\<T\>). If you want to modify the QList as | - |
| 1493 | you iterate over it, use QList::iterator instead. It is generally | - |
| 1494 | good practice to use QList::const_iterator on a non-const QList | - |
| 1495 | as well, unless you need to change the QList through the | - |
| 1496 | iterator. Const iterators are slightly faster, and can improve | - |
| 1497 | code readability. | - |
| 1498 | | - |
| 1499 | The default QList::const_iterator constructor creates an | - |
| 1500 | uninitialized iterator. You must initialize it using a QList | - |
| 1501 | function like QList::constBegin(), QList::constEnd(), or | - |
| 1502 | QList::insert() before you can start iterating. Here's a typical | - |
| 1503 | loop that prints all the items stored in a list: | - |
| 1504 | | - |
| 1505 | \snippet code/src_corelib_tools_qlistdata.cpp 19 | - |
| 1506 | | - |
| 1507 | Most QList functions accept an integer index rather than an | - |
| 1508 | iterator. For that reason, iterators are rarely useful in | - |
| 1509 | connection with QList. One place where STL-style iterators do | - |
| 1510 | make sense is as arguments to \l{generic algorithms}. | - |
| 1511 | | - |
| 1512 | For example, here's how to delete all the widgets stored in a | - |
| 1513 | QList\<QWidget *\>: | - |
| 1514 | | - |
| 1515 | \snippet code/src_corelib_tools_qlistdata.cpp 20 | - |
| 1516 | | - |
| 1517 | Multiple iterators can be used on the same list. However, be | - |
| 1518 | aware that any non-const function call performed on the QList | - |
| 1519 | will render all existing iterators undefined. If you need to keep | - |
| 1520 | iterators over a long period of time, we recommend that you use | - |
| 1521 | QLinkedList rather than QList. | - |
| 1522 | | - |
| 1523 | \sa QList::iterator, QListIterator | - |
| 1524 | */ | - |
| 1525 | | - |
| 1526 | /*! \fn QList::const_iterator::const_iterator() | - |
| 1527 | | - |
| 1528 | Constructs an uninitialized iterator. | - |
| 1529 | | - |
| 1530 | Functions like operator*() and operator++() should not be called | - |
| 1531 | on an uninitialized iterator. Use operator=() to assign a value | - |
| 1532 | to it before using it. | - |
| 1533 | | - |
| 1534 | \sa QList::constBegin(), QList::constEnd() | - |
| 1535 | */ | - |
| 1536 | | - |
| 1537 | /*! \typedef QList::const_iterator::iterator_category | - |
| 1538 | | - |
| 1539 | A synonym for \e {std::random_access_iterator_tag} indicating | - |
| 1540 | this iterator is a random access iterator. | - |
| 1541 | */ | - |
| 1542 | | - |
| 1543 | /*! \typedef QList::const_iterator::difference_type | - |
| 1544 | | - |
| 1545 | \internal | - |
| 1546 | */ | - |
| 1547 | | - |
| 1548 | /*! \typedef QList::const_iterator::value_type | - |
| 1549 | | - |
| 1550 | \internal | - |
| 1551 | */ | - |
| 1552 | | - |
| 1553 | /*! \typedef QList::const_iterator::pointer | - |
| 1554 | | - |
| 1555 | \internal | - |
| 1556 | */ | - |
| 1557 | | - |
| 1558 | /*! \typedef QList::const_iterator::reference | - |
| 1559 | | - |
| 1560 | \internal | - |
| 1561 | */ | - |
| 1562 | | - |
| 1563 | /*! \fn QList::const_iterator::const_iterator(Node *node) | - |
| 1564 | | - |
| 1565 | \internal | - |
| 1566 | */ | - |
| 1567 | | - |
| 1568 | /*! \fn QList::const_iterator::const_iterator(const const_iterator &other) | - |
| 1569 | | - |
| 1570 | Constructs a copy of \a other. | - |
| 1571 | */ | - |
| 1572 | | - |
| 1573 | /*! \fn QList::const_iterator::const_iterator(const iterator &other) | - |
| 1574 | | - |
| 1575 | Constructs a copy of \a other. | - |
| 1576 | */ | - |
| 1577 | | - |
| 1578 | /*! \fn const T &QList::const_iterator::operator*() const | - |
| 1579 | | - |
| 1580 | Returns the current item. | - |
| 1581 | | - |
| 1582 | \sa operator->() | - |
| 1583 | */ | - |
| 1584 | | - |
| 1585 | /*! \fn const T *QList::const_iterator::operator->() const | - |
| 1586 | | - |
| 1587 | Returns a pointer to the current item. | - |
| 1588 | | - |
| 1589 | \sa operator*() | - |
| 1590 | */ | - |
| 1591 | | - |
| 1592 | /*! \fn const T &QList::const_iterator::operator[](int j) const | - |
| 1593 | | - |
| 1594 | Returns the item at position *this + \a{j}. | - |
| 1595 | | - |
| 1596 | This function is provided to make QList iterators behave like C++ | - |
| 1597 | pointers. | - |
| 1598 | | - |
| 1599 | \sa operator+() | - |
| 1600 | */ | - |
| 1601 | | - |
| 1602 | /*! \fn bool QList::const_iterator::operator==(const const_iterator &other) const | - |
| 1603 | | - |
| 1604 | Returns true if \a other points to the same item as this | - |
| 1605 | iterator; otherwise returns false. | - |
| 1606 | | - |
| 1607 | \sa operator!=() | - |
| 1608 | */ | - |
| 1609 | | - |
| 1610 | /*! \fn bool QList::const_iterator::operator!=(const const_iterator &other) const | - |
| 1611 | | - |
| 1612 | Returns true if \a other points to a different item than this | - |
| 1613 | iterator; otherwise returns false. | - |
| 1614 | | - |
| 1615 | \sa operator==() | - |
| 1616 | */ | - |
| 1617 | | - |
| 1618 | /*! | - |
| 1619 | \fn bool QList::const_iterator::operator<(const const_iterator& other) const | - |
| 1620 | | - |
| 1621 | Returns true if the item pointed to by this iterator is less than | - |
| 1622 | the item pointed to by the \a other iterator. | - |
| 1623 | */ | - |
| 1624 | | - |
| 1625 | /*! | - |
| 1626 | \fn bool QList::const_iterator::operator<=(const const_iterator& other) const | - |
| 1627 | | - |
| 1628 | Returns true if the item pointed to by this iterator is less than | - |
| 1629 | or equal to the item pointed to by the \a other iterator. | - |
| 1630 | */ | - |
| 1631 | | - |
| 1632 | /*! | - |
| 1633 | \fn bool QList::const_iterator::operator>(const const_iterator& other) const | - |
| 1634 | | - |
| 1635 | Returns true if the item pointed to by this iterator is greater | - |
| 1636 | than the item pointed to by the \a other iterator. | - |
| 1637 | */ | - |
| 1638 | | - |
| 1639 | /*! | - |
| 1640 | \fn bool QList::const_iterator::operator>=(const const_iterator& other) const | - |
| 1641 | | - |
| 1642 | Returns true if the item pointed to by this iterator is greater | - |
| 1643 | than or equal to the item pointed to by the \a other iterator. | - |
| 1644 | */ | - |
| 1645 | | - |
| 1646 | /*! \fn QList::const_iterator &QList::const_iterator::operator++() | - |
| 1647 | | - |
| 1648 | The prefix ++ operator (\c{++it}) advances the iterator to the | - |
| 1649 | next item in the list and returns an iterator to the new current | - |
| 1650 | item. | - |
| 1651 | | - |
| 1652 | Calling this function on QList::end() leads to undefined results. | - |
| 1653 | | - |
| 1654 | \sa operator--() | - |
| 1655 | */ | - |
| 1656 | | - |
| 1657 | /*! \fn QList::const_iterator QList::const_iterator::operator++(int) | - |
| 1658 | | - |
| 1659 | \overload | - |
| 1660 | | - |
| 1661 | The postfix ++ operator (\c{it++}) advances the iterator to the | - |
| 1662 | next item in the list and returns an iterator to the previously | - |
| 1663 | current item. | - |
| 1664 | */ | - |
| 1665 | | - |
| 1666 | /*! \fn QList::const_iterator &QList::const_iterator::operator--() | - |
| 1667 | | - |
| 1668 | The prefix -- operator (\c{--it}) makes the preceding item | - |
| 1669 | current and returns an iterator to the new current item. | - |
| 1670 | | - |
| 1671 | Calling this function on QList::begin() leads to undefined results. | - |
| 1672 | | - |
| 1673 | \sa operator++() | - |
| 1674 | */ | - |
| 1675 | | - |
| 1676 | /*! \fn QList::const_iterator QList::const_iterator::operator--(int) | - |
| 1677 | | - |
| 1678 | \overload | - |
| 1679 | | - |
| 1680 | The postfix -- operator (\c{it--}) makes the preceding item | - |
| 1681 | current and returns an iterator to the previously current item. | - |
| 1682 | */ | - |
| 1683 | | - |
| 1684 | /*! \fn QList::const_iterator &QList::const_iterator::operator+=(int j) | - |
| 1685 | | - |
| 1686 | Advances the iterator by \a j items. (If \a j is negative, the | - |
| 1687 | iterator goes backward.) | - |
| 1688 | | - |
| 1689 | \sa operator-=(), operator+() | - |
| 1690 | */ | - |
| 1691 | | - |
| 1692 | /*! \fn QList::const_iterator &QList::const_iterator::operator-=(int j) | - |
| 1693 | | - |
| 1694 | Makes the iterator go back by \a j items. (If \a j is negative, | - |
| 1695 | the iterator goes forward.) | - |
| 1696 | | - |
| 1697 | \sa operator+=(), operator-() | - |
| 1698 | */ | - |
| 1699 | | - |
| 1700 | /*! \fn QList::const_iterator QList::const_iterator::operator+(int j) const | - |
| 1701 | | - |
| 1702 | Returns an iterator to the item at \a j positions forward from | - |
| 1703 | this iterator. (If \a j is negative, the iterator goes backward.) | - |
| 1704 | | - |
| 1705 | \sa operator-(), operator+=() | - |
| 1706 | */ | - |
| 1707 | | - |
| 1708 | /*! \fn QList::const_iterator QList::const_iterator::operator-(int j) const | - |
| 1709 | | - |
| 1710 | Returns an iterator to the item at \a j positions backward from | - |
| 1711 | this iterator. (If \a j is negative, the iterator goes forward.) | - |
| 1712 | | - |
| 1713 | \sa operator+(), operator-=() | - |
| 1714 | */ | - |
| 1715 | | - |
| 1716 | /*! \fn int QList::const_iterator::operator-(const_iterator other) const | - |
| 1717 | | - |
| 1718 | Returns the number of items between the item pointed to by \a | - |
| 1719 | other and the item pointed to by this iterator. | - |
| 1720 | */ | - |
| 1721 | | - |
| 1722 | /*! \fn QDataStream &operator<<(QDataStream &out, const QList<T> &list) | - |
| 1723 | \relates QList | - |
| 1724 | | - |
| 1725 | Writes the list \a list to stream \a out. | - |
| 1726 | | - |
| 1727 | This function requires the value type to implement \c | - |
| 1728 | operator<<(). | - |
| 1729 | | - |
| 1730 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - |
| 1731 | */ | - |
| 1732 | | - |
| 1733 | /*! \fn QDataStream &operator>>(QDataStream &in, QList<T> &list) | - |
| 1734 | \relates QList | - |
| 1735 | | - |
| 1736 | Reads a list from stream \a in into \a list. | - |
| 1737 | | - |
| 1738 | This function requires the value type to implement \c | - |
| 1739 | operator>>(). | - |
| 1740 | | - |
| 1741 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - |
| 1742 | */ | - |
| 1743 | | - |
| 1744 | /*! \fn QList<T> QList<T>::fromVector(const QVector<T> &vector) | - |
| 1745 | | - |
| 1746 | Returns a QList object with the data contained in \a vector. | - |
| 1747 | | - |
| 1748 | Example: | - |
| 1749 | | - |
| 1750 | \snippet code/src_corelib_tools_qlistdata.cpp 21 | - |
| 1751 | | - |
| 1752 | \sa fromSet(), toVector(), QVector::toList() | - |
| 1753 | */ | - |
| 1754 | | - |
| 1755 | /*! \fn QVector<T> QList<T>::toVector() const | - |
| 1756 | | - |
| 1757 | Returns a QVector object with the data contained in this QList. | - |
| 1758 | | - |
| 1759 | Example: | - |
| 1760 | | - |
| 1761 | \snippet code/src_corelib_tools_qlistdata.cpp 22 | - |
| 1762 | | - |
| 1763 | \sa toSet(), fromVector(), QVector::fromList() | - |
| 1764 | */ | - |
| 1765 | | - |
| 1766 | /*! \fn QList<T> QList<T>::fromSet(const QSet<T> &set) | - |
| 1767 | | - |
| 1768 | Returns a QList object with the data contained in \a set. The | - |
| 1769 | order of the elements in the QList is undefined. | - |
| 1770 | | - |
| 1771 | Example: | - |
| 1772 | | - |
| 1773 | \snippet code/src_corelib_tools_qlistdata.cpp 23 | - |
| 1774 | | - |
| 1775 | \sa fromVector(), toSet(), QSet::toList() | - |
| 1776 | */ | - |
| 1777 | | - |
| 1778 | /*! \fn QSet<T> QList<T>::toSet() const | - |
| 1779 | | - |
| 1780 | Returns a QSet object with the data contained in this QList. | - |
| 1781 | Since QSet doesn't allow duplicates, the resulting QSet might be | - |
| 1782 | smaller than the original list was. | - |
| 1783 | | - |
| 1784 | Example: | - |
| 1785 | | - |
| 1786 | \snippet code/src_corelib_tools_qlistdata.cpp 24 | - |
| 1787 | | - |
| 1788 | \sa toVector(), fromSet(), QSet::fromList() | - |
| 1789 | */ | - |
| 1790 | | - |
| 1791 | /*! \fn QList<T> QList<T>::fromStdList(const std::list<T> &list) | - |
| 1792 | | - |
| 1793 | Returns a QList object with the data contained in \a list. The | - |
| 1794 | order of the elements in the QList is the same as in \a list. | - |
| 1795 | | - |
| 1796 | Example: | - |
| 1797 | | - |
| 1798 | \snippet code/src_corelib_tools_qlistdata.cpp 25 | - |
| 1799 | | - |
| 1800 | \sa toStdList(), QVector::fromStdVector() | - |
| 1801 | */ | - |
| 1802 | | - |
| 1803 | /*! \fn std::list<T> QList<T>::toStdList() const | - |
| 1804 | | - |
| 1805 | Returns a std::list object with the data contained in this QList. | - |
| 1806 | Example: | - |
| 1807 | | - |
| 1808 | \snippet code/src_corelib_tools_qlistdata.cpp 26 | - |
| 1809 | | - |
| 1810 | \sa fromStdList(), QVector::toStdVector() | - |
| 1811 | */ | - |
| 1812 | | - |
| 1813 | QT_END_NAMESPACE | - |
| 1814 | | - |
| | |