json/qjsonarray.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
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 <qjsonobject.h> -
43#include <qjsonvalue.h> -
44#include <qjsonarray.h> -
45#include <qstringlist.h> -
46#include <qvariant.h> -
47#include <qdebug.h> -
48 -
49#include "qjsonwriter_p.h" -
50#include "qjson_p.h" -
51 -
52QT_BEGIN_NAMESPACE -
53 -
54/*! -
55 \class QJsonArray -
56 \inmodule QtCore -
57 \ingroup json -
58 \reentrant -
59 \since 5.0 -
60 -
61 \brief The QJsonArray class encapsulates a JSON array. -
62 -
63 A JSON array is a list of values. The list can be manipulated by inserting and -
64 removing QJsonValue's from the array. -
65 -
66 A QJsonArray can be converted to and from a QVariantList. You can query the -
67 number of entries with size(), insert(), and remove() entries from it -
68 and iterate over its content using the standard C++ iterator pattern. -
69 -
70 QJsonArray is an implicitly shared class and shares the data with the document -
71 it has been created from as long as it is not being modified. -
72 -
73 You can convert the array to and from text based JSON through QJsonDocument. -
74*/ -
75 -
76/*! -
77 \typedef QJsonArray::Iterator -
78 -
79 Qt-style synonym for QJsonArray::iterator. -
80*/ -
81 -
82/*! -
83 \typedef QJsonArray::ConstIterator -
84 -
85 Qt-style synonym for QJsonArray::const_iterator. -
86*/ -
87 -
88/*! -
89 \typedef QJsonArray::size_type -
90 -
91 Typedef for int. Provided for STL compatibility. -
92*/ -
93 -
94/*! -
95 \typedef QJsonArray::value_type -
96 -
97 Typedef for QJsonValue. Provided for STL compatibility. -
98*/ -
99 -
100/*! -
101 \typedef QJsonArray::difference_type -
102 -
103 Typedef for int. Provided for STL compatibility. -
104*/ -
105 -
106/*! -
107 \typedef QJsonArray::pointer -
108 -
109 Typedef for QJsonValue *. Provided for STL compatibility. -
110*/ -
111 -
112/*! -
113 \typedef QJsonArray::const_pointer -
114 -
115 Typedef for const QJsonValue *. Provided for STL compatibility. -
116*/ -
117 -
118/*! -
119 \typedef QJsonArray::reference -
120 -
121 Typedef for QJsonValue &. Provided for STL compatibility. -
122*/ -
123 -
124/*! -
125 \typedef QJsonArray::const_reference -
126 -
127 Typedef for const QJsonValue &. Provided for STL compatibility. -
128*/ -
129 -
130/*! -
131 Creates an empty array. -
132 */ -
133QJsonArray::QJsonArray() -
134 : d(0), a(0) -
135{ -
136}
executed: }
Execution Count:11614
11614
137 -
138/*! -
139 \internal -
140 */ -
141QJsonArray::QJsonArray(QJsonPrivate::Data *data, QJsonPrivate::Array *array) -
142 : d(data), a(array) -
143{ -
144 Q_ASSERT(data);
executed (the execution status of this line is deduced): qt_noop();
-
145 Q_ASSERT(array);
executed (the execution status of this line is deduced): qt_noop();
-
146 d->ref.ref();
executed (the execution status of this line is deduced): d->ref.ref();
-
147}
executed: }
Execution Count:12006
12006
148 -
149/*! -
150 Deletes the array. -
151 */ -
152QJsonArray::~QJsonArray() -
153{ -
154 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:12484
yes
Evaluation Count:11594
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:12456
28-12484
155 delete d;
executed: delete d;
Execution Count:28
28
156}
executed: }
Execution Count:24078
24078
157 -
158/*! -
159 Creates a copy of \a other. -
160 -
161 Since QJsonArray is implicitly shared, the copy is shallow -
162 as long as the object doesn't get modified. -
163 */ -
164QJsonArray::QJsonArray(const QJsonArray &other) -
165{ -
166 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
167 a = other.a;
executed (the execution status of this line is deduced): a = other.a;
-
168 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:449
yes
Evaluation Count:9
9-449
169 d->ref.ref();
executed: d->ref.ref();
Execution Count:449
449
170}
executed: }
Execution Count:458
458
171 -
172/*! -
173 Assigns \a other to this array. -
174 */ -
175QJsonArray &QJsonArray::operator =(const QJsonArray &other) -
176{ -
177 if (d != other.d) {
partially evaluated: d != other.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
178 if (d && !d->ref.deref())
never evaluated: d
never evaluated: !d->ref.deref()
0
179 delete d;
never executed: delete d;
0
180 d = other.d;
never executed (the execution status of this line is deduced): d = other.d;
-
181 if (d)
never evaluated: d
0
182 d->ref.ref();
never executed: d->ref.ref();
0
183 }
never executed: }
0
184 a = other.a;
executed (the execution status of this line is deduced): a = other.a;
-
185 -
186 return *this;
executed: return *this;
Execution Count:3
3
187} -
188 -
189/*! -
190 Converts the string list \a list to a QJsonArray. -
191 -
192 The values in \a list will be converted to JSON values. -
193 -
194 \sa toVariantList(), QJsonValue::fromVariant() -
195 */ -
196QJsonArray QJsonArray::fromStringList(const QStringList &list) -
197{ -
198 QJsonArray array;
never executed (the execution status of this line is deduced): QJsonArray array;
-
199 for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
never evaluated: it != list.constEnd()
0
200 array.append(QJsonValue(*it));
never executed: array.append(QJsonValue(*it));
0
201 return array;
never executed: return array;
0
202} -
203 -
204/*! -
205 Converts the variant list \a list to a QJsonArray. -
206 -
207 The QVariant values in \a list will be converted to JSON values. -
208 -
209 \sa toVariantList(), QJsonValue::fromVariant() -
210 */ -
211QJsonArray QJsonArray::fromVariantList(const QVariantList &list) -
212{ -
213 QJsonArray array;
executed (the execution status of this line is deduced): QJsonArray array;
-
214 for (QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
evaluated: it != list.constEnd()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1
1-4
215 array.append(QJsonValue::fromVariant(*it));
executed: array.append(QJsonValue::fromVariant(*it));
Execution Count:4
4
216 return array;
executed: return array;
Execution Count:1
1
217} -
218 -
219/*! -
220 Converts this object to a QVariantList. -
221 -
222 Returns the created map. -
223 */ -
224QVariantList QJsonArray::toVariantList() const -
225{ -
226 QVariantList list;
executed (the execution status of this line is deduced): QVariantList list;
-
227 -
228 if (a) {
evaluated: a
TRUEFALSE
yes
Evaluation Count:103
yes
Evaluation Count:1
1-103
229 for (int i = 0; i < (int)a->length; ++i)
evaluated: i < (int)a->length
TRUEFALSE
yes
Evaluation Count:491
yes
Evaluation Count:103
103-491
230 list.append(QJsonValue(d, a, a->at(i)).toVariant());
executed: list.append(QJsonValue(d, a, a->at(i)).toVariant());
Execution Count:491
491
231 }
executed: }
Execution Count:103
103
232 return list;
executed: return list;
Execution Count:104
104
233} -
234 -
235 -
236/*! -
237 Returns the number of values stored in the array. -
238 */ -
239int QJsonArray::size() const -
240{ -
241 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:12017
3-12017
242 return 0;
executed: return 0;
Execution Count:3
3
243 -
244 return (int)a->length;
executed: return (int)a->length;
Execution Count:12017
12017
245} -
246 -
247/*! -
248 \fn QJsonArray::count() const -
249 -
250 Same as size(). -
251 -
252 \sa size() -
253*/ -
254 -
255/*! -
256 Returns \c true if the object is empty. This is the same as size() == 0. -
257 -
258 \sa size() -
259 */ -
260bool QJsonArray::isEmpty() const -
261{ -
262 if (!d)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
263 return true;
never executed: return true;
0
264 -
265 return !a->length;
executed: return !a->length;
Execution Count:12
12
266} -
267 -
268/*! -
269 Returns a QJsonValue representing the value for index \a i. -
270 -
271 The returned QJsonValue is \c Undefined, if \a i is out of bounds. -
272 -
273 */ -
274QJsonValue QJsonArray::at(int i) const -
275{ -
276 if (!a || i < 0 || i >= (int)a->length)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:22729
evaluated: i < 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:22726
evaluated: i >= (int)a->length
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:22723
2-22729
277 return QJsonValue(QJsonValue::Undefined);
executed: return QJsonValue(QJsonValue::Undefined);
Execution Count:8
8
278 -
279 return QJsonValue(d, a, a->at(i));
executed: return QJsonValue(d, a, a->at(i));
Execution Count:22723
22723
280} -
281 -
282/*! -
283 Returns the first value stored in the array. -
284 -
285 Same as \c at(0). -
286 -
287 \sa at() -
288 */ -
289QJsonValue QJsonArray::first() const -
290{ -
291 return at(0);
executed: return at(0);
Execution Count:9
9
292} -
293 -
294/*! -
295 Returns the last value stored in the array. -
296 -
297 Same as \c{at(size() - 1)}. -
298 -
299 \sa at() -
300 */ -
301QJsonValue QJsonArray::last() const -
302{ -
303 return at(a ? (a->length - 1) : 0);
executed: return at(a ? (a->length - 1) : 0);
Execution Count:10
10
304} -
305 -
306/*! -
307 Inserts \a value at the beginning of the array. -
308 -
309 This is the same as \c{insert(0, value)} and will prepend \a value to the array. -
310 -
311 \sa append(), insert() -
312 */ -
313void QJsonArray::prepend(const QJsonValue &value) -
314{ -
315 insert(0, value);
executed (the execution status of this line is deduced): insert(0, value);
-
316}
executed: }
Execution Count:1
1
317 -
318/*! -
319 Inserts \a value at the end of the array. -
320 -
321 \sa prepend(), insert() -
322 */ -
323void QJsonArray::append(const QJsonValue &value) -
324{ -
325 insert(a ? (int)a->length : 0, value);
executed (the execution status of this line is deduced): insert(a ? (int)a->length : 0, value);
-
326}
executed: }
Execution Count:121
121
327 -
328/*! -
329 Removes the value at index position \a i. \a i must be a valid -
330 index position in the array (i.e., \c{0 <= i < size()}). -
331 -
332 \sa insert(), replace() -
333 */ -
334void QJsonArray::removeAt(int i) -
335{ -
336 if (!a || i < 0 || i >= (int)a->length)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:19
evaluated: i < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:18
evaluated: i >= (int)a->length
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:17
1-19
337 return;
executed: return;
Execution Count:4
4
338 -
339 detach();
executed (the execution status of this line is deduced): detach();
-
340 a->removeItems(i, 1);
executed (the execution status of this line is deduced): a->removeItems(i, 1);
-
341 ++d->compactionCounter;
executed (the execution status of this line is deduced): ++d->compactionCounter;
-
342 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
partially evaluated: d->compactionCounter > 32u
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
never evaluated: d->compactionCounter >= unsigned(a->length) / 2u
0-17
343 compact();
never executed: compact();
0
344}
executed: }
Execution Count:17
17
345 -
346/*! \fn void QJsonArray::removeFirst() -
347 -
348 Removes the first item in the array. Calling this function is -
349 equivalent to calling \c{removeAt(0)}. The array must not be empty. If -
350 the array can be empty, call isEmpty() before calling this -
351 function. -
352 -
353 \sa removeAt(), removeLast() -
354*/ -
355 -
356/*! \fn void QJsonArray::removeLast() -
357 -
358 Removes the last item in the array. Calling this function is -
359 equivalent to calling \c{removeAt(size() - 1)}. The array must not be -
360 empty. If the array can be empty, call isEmpty() before calling -
361 this function. -
362 -
363 \sa removeAt(), removeFirst() -
364*/ -
365 -
366/*! -
367 Removes the item at index position \a i and returns it. \a i must -
368 be a valid index position in the array (i.e., \c{0 <= i < size()}). -
369 -
370 If you don't use the return value, removeAt() is more efficient. -
371 -
372 \sa removeAt() -
373 */ -
374QJsonValue QJsonArray::takeAt(int i) -
375{ -
376 if (!a || i < 0 || i >= (int)a->length)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
partially evaluated: i < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
evaluated: i >= (int)a->length
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
0-2
377 return QJsonValue(QJsonValue::Undefined);
executed: return QJsonValue(QJsonValue::Undefined);
Execution Count:2
2
378 -
379 QJsonValue v(d, a, a->at(i));
executed (the execution status of this line is deduced): QJsonValue v(d, a, a->at(i));
-
380 removeAt(i); // detaches
executed (the execution status of this line is deduced): removeAt(i);
-
381 return v;
executed: return v;
Execution Count:1
1
382} -
383 -
384/*! -
385 Inserts \a value at index position \a i in the array. If \a i -
386 is \c 0, the value is prepended to the array. If \a i is size(), the -
387 value is appended to the array. -
388 -
389 \sa append(), prepend(), replace(), removeAt() -
390 */ -
391void QJsonArray::insert(int i, const QJsonValue &value) -
392{ -
393 Q_ASSERT (i >= 0 && i <= (a ? (int)a->length : 0));
executed (the execution status of this line is deduced): qt_noop();
-
394 -
395 bool compressed;
executed (the execution status of this line is deduced): bool compressed;
-
396 int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed);
executed (the execution status of this line is deduced): int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed);
-
397 -
398 detach(valueSize + sizeof(QJsonPrivate::Value));
executed (the execution status of this line is deduced): detach(valueSize + sizeof(QJsonPrivate::Value));
-
399 -
400 if (!a->length)
evaluated: !a->length
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:93
29-93
401 a->tableOffset = sizeof(QJsonPrivate::Array);
executed: a->tableOffset = sizeof(QJsonPrivate::Array);
Execution Count:29
29
402 -
403 int valueOffset = a->reserveSpace(valueSize, i, 1, false);
executed (the execution status of this line is deduced): int valueOffset = a->reserveSpace(valueSize, i, 1, false);
-
404 QJsonPrivate::Value &v = (*a)[i];
executed (the execution status of this line is deduced): QJsonPrivate::Value &v = (*a)[i];
-
405 v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
evaluated: value.t == QJsonValue::Undefined
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:121
1-121
406 v.latinOrIntValue = compressed;
executed (the execution status of this line is deduced): v.latinOrIntValue = compressed;
-
407 v.latinKey = false;
executed (the execution status of this line is deduced): v.latinKey = false;
-
408 v.value = QJsonPrivate::Value::valueToStore(value, valueOffset);
executed (the execution status of this line is deduced): v.value = QJsonPrivate::Value::valueToStore(value, valueOffset);
-
409 if (valueSize)
evaluated: valueSize
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:65
57-65
410 QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
executed: QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
Execution Count:57
57
411}
executed: }
Execution Count:122
122
412 -
413/*! -
414 \fn QJsonArray::iterator QJsonArray::insert(iterator before, const QJsonValue &value) -
415 -
416 Inserts \a value before the position pointed to by \a before, and returns an iterator -
417 pointing to the newly inserted item. -
418 -
419 \sa erase(), insert() -
420*/ -
421 -
422/*! -
423 \fn QJsonArray::iterator QJsonArray::erase(iterator it) -
424 -
425 Removes the item pointed to by \a it, and returns an iterator pointing to the -
426 next item. -
427 -
428 \sa removeAt() -
429*/ -
430 -
431/*! -
432 Replaces the item at index position \a i with \a value. \a i must -
433 be a valid index position in the array (i.e., \c{0 <= i < size()}). -
434 -
435 \sa operator[](), removeAt() -
436 */ -
437void QJsonArray::replace(int i, const QJsonValue &value) -
438{ -
439 Q_ASSERT (a && i >= 0 && i < (int)(a->length));
executed (the execution status of this line is deduced): qt_noop();
-
440 -
441 bool compressed;
executed (the execution status of this line is deduced): bool compressed;
-
442 int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed);
executed (the execution status of this line is deduced): int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed);
-
443 -
444 detach(valueSize);
executed (the execution status of this line is deduced): detach(valueSize);
-
445 -
446 if (!a->length)
partially evaluated: !a->length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
447 a->tableOffset = sizeof(QJsonPrivate::Array);
never executed: a->tableOffset = sizeof(QJsonPrivate::Array);
0
448 -
449 int valueOffset = a->reserveSpace(valueSize, i, 1, true);
executed (the execution status of this line is deduced): int valueOffset = a->reserveSpace(valueSize, i, 1, true);
-
450 QJsonPrivate::Value &v = (*a)[i];
executed (the execution status of this line is deduced): QJsonPrivate::Value &v = (*a)[i];
-
451 v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
partially evaluated: value.t == QJsonValue::Undefined
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
452 v.latinOrIntValue = compressed;
executed (the execution status of this line is deduced): v.latinOrIntValue = compressed;
-
453 v.latinKey = false;
executed (the execution status of this line is deduced): v.latinKey = false;
-
454 v.value = QJsonPrivate::Value::valueToStore(value, valueOffset);
executed (the execution status of this line is deduced): v.value = QJsonPrivate::Value::valueToStore(value, valueOffset);
-
455 if (valueSize)
partially evaluated: valueSize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
456 QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
never executed: QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
0
457 -
458 ++d->compactionCounter;
executed (the execution status of this line is deduced): ++d->compactionCounter;
-
459 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
partially evaluated: d->compactionCounter > 32u
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
never evaluated: d->compactionCounter >= unsigned(a->length) / 2u
0-4
460 compact();
never executed: compact();
0
461}
executed: }
Execution Count:4
4
462 -
463/*! -
464 Returns \c true if the array contains an occurrence of \a value, otherwise \c false. -
465 -
466 \sa count() -
467 */ -
468bool QJsonArray::contains(const QJsonValue &value) const -
469{ -
470 for (int i = 0; i < size(); i++) {
never evaluated: i < size()
0
471 if (at(i) == value)
never evaluated: at(i) == value
0
472 return true;
never executed: return true;
0
473 }
never executed: }
0
474 return false;
never executed: return false;
0
475} -
476 -
477/*! -
478 Returns the value at index position \a i as a modifiable reference. -
479 \a i must be a valid index position in the array (i.e., \c{0 <= i < -
480 size()}). -
481 -
482 The return value is of type QJsonValueRef, a helper class for QJsonArray -
483 and QJsonObject. When you get an object of type QJsonValueRef, you can -
484 use it as if it were a reference to a QJsonValue. If you assign to it, -
485 the assignment will apply to the character in the QJsonArray of QJsonObject -
486 from which you got the reference. -
487 -
488 \sa at() -
489 */ -
490QJsonValueRef QJsonArray::operator [](int i) -
491{ -
492 Q_ASSERT(a && i >= 0 && i < (int)a->length);
executed (the execution status of this line is deduced): qt_noop();
-
493 return QJsonValueRef(this, i);
executed: return QJsonValueRef(this, i);
Execution Count:6
6
494} -
495 -
496/*! -
497 \overload -
498 -
499 Same as at(). -
500 */ -
501QJsonValue QJsonArray::operator[](int i) const -
502{ -
503 return at(i);
never executed: return at(i);
0
504} -
505 -
506/*! -
507 Returns \c true if this array is equal to \a other. -
508 */ -
509bool QJsonArray::operator==(const QJsonArray &other) const -
510{ -
511 if (a == other.a)
evaluated: a == other.a
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:160
19-160
512 return true;
executed: return true;
Execution Count:19
19
513 -
514 if (!a)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:159
1-159
515 return !other.a->length;
executed: return !other.a->length;
Execution Count:1
1
516 if (!other.a)
evaluated: !other.a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:157
2-157
517 return !a->length;
executed: return !a->length;
Execution Count:2
2
518 if (a->length != other.a->length)
evaluated: a->length != other.a->length
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:156
1-156
519 return false;
executed: return false;
Execution Count:1
1
520 -
521 for (int i = 0; i < (int)a->length; ++i) {
evaluated: i < (int)a->length
TRUEFALSE
yes
Evaluation Count:727
yes
Evaluation Count:155
155-727
522 if (QJsonValue(d, a, a->at(i)) != QJsonValue(other.d, other.a, other.a->at(i)))
evaluated: QJsonValue(d, a, a->at(i)) != QJsonValue(other.d, other.a, other.a->at(i))
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:726
1-726
523 return false;
executed: return false;
Execution Count:1
1
524 }
executed: }
Execution Count:726
726
525 return true;
executed: return true;
Execution Count:155
155
526} -
527 -
528/*! -
529 Returns \c true if this array is not equal to \a other. -
530 */ -
531bool QJsonArray::operator!=(const QJsonArray &other) const -
532{ -
533 return !(*this == other);
executed: return !(*this == other);
Execution Count:3
3
534} -
535 -
536/*! \fn QJsonArray::iterator QJsonArray::begin() -
537 -
538 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in -
539 the array. -
540 -
541 \sa constBegin(), end() -
542*/ -
543 -
544/*! \fn QJsonArray::const_iterator QJsonArray::begin() const -
545 -
546 \overload -
547*/ -
548 -
549/*! \fn QJsonArray::const_iterator QJsonArray::constBegin() const -
550 -
551 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item -
552 in the array. -
553 -
554 \sa begin(), constEnd() -
555*/ -
556 -
557/*! \fn QJsonArray::iterator QJsonArray::end() -
558 -
559 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item -
560 after the last item in the array. -
561 -
562 \sa begin(), constEnd() -
563*/ -
564 -
565/*! \fn const_iterator QJsonArray::end() const -
566 -
567 \overload -
568*/ -
569 -
570/*! \fn QJsonArray::const_iterator QJsonArray::constEnd() const -
571 -
572 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary -
573 item after the last item in the array. -
574 -
575 \sa constBegin(), end() -
576*/ -
577 -
578/*! \fn void QJsonArray::push_back(const QJsonValue &value) -
579 -
580 This function is provided for STL compatibility. It is equivalent -
581 to \l{QJsonArray::append()}{append(value)} and will append \a value to the array. -
582*/ -
583 -
584/*! \fn void QJsonArray::push_front(const QJsonValue &value) -
585 -
586 This function is provided for STL compatibility. It is equivalent -
587 to \l{QJsonArray::prepend()}{prepend(value)} and will prepend \a value to the array. -
588*/ -
589 -
590/*! \fn void QJsonArray::pop_front() -
591 -
592 This function is provided for STL compatibility. It is equivalent -
593 to removeFirst(). The array must not be empty. If the array can be -
594 empty, call isEmpty() before calling this function. -
595*/ -
596 -
597/*! \fn void QJsonArray::pop_back() -
598 -
599 This function is provided for STL compatibility. It is equivalent -
600 to removeLast(). The array must not be empty. If the array can be -
601 empty, call isEmpty() before calling this function. -
602*/ -
603 -
604/*! \fn bool QJsonArray::empty() const -
605 -
606 This function is provided for STL compatibility. It is equivalent -
607 to isEmpty() and returns \c true if the array is empty. -
608*/ -
609 -
610/*! \class QJsonArray::iterator -
611 \inmodule QtCore -
612 \brief The QJsonArray::iterator class provides an STL-style non-const iterator for QJsonArray. -
613 -
614 QJsonArray::iterator allows you to iterate over a QJsonArray -
615 and to modify the array item associated with the -
616 iterator. If you want to iterate over a const QJsonArray, use -
617 QJsonArray::const_iterator instead. It is generally a good practice to -
618 use QJsonArray::const_iterator on a non-const QJsonArray as well, unless -
619 you need to change the QJsonArray through the iterator. Const -
620 iterators are slightly faster and improves code readability. -
621 -
622 The default QJsonArray::iterator constructor creates an uninitialized -
623 iterator. You must initialize it using a QJsonArray function like -
624 QJsonArray::begin(), QJsonArray::end(), or QJsonArray::insert() before you can -
625 start iterating. -
626 -
627 Most QJsonArray functions accept an integer index rather than an -
628 iterator. For that reason, iterators are rarely useful in -
629 connection with QJsonArray. One place where STL-style iterators do -
630 make sense is as arguments to \l{generic algorithms}. -
631 -
632 Multiple iterators can be used on the same array. However, be -
633 aware that any non-const function call performed on the QJsonArray -
634 will render all existing iterators undefined. -
635 -
636 \sa QJsonArray::const_iterator -
637*/ -
638 -
639/*! \typedef QJsonArray::iterator::iterator_category -
640 -
641 A synonym for \e {std::random_access_iterator_tag} indicating -
642 this iterator is a random access iterator. -
643*/ -
644 -
645/*! \typedef QJsonArray::iterator::difference_type -
646 -
647 \internal -
648*/ -
649 -
650/*! \typedef QJsonArray::iterator::value_type -
651 -
652 \internal -
653*/ -
654 -
655/*! \typedef QJsonArray::iterator::reference -
656 -
657 \internal -
658*/ -
659 -
660/*! \fn QJsonArray::iterator::iterator() -
661 -
662 Constructs an uninitialized iterator. -
663 -
664 Functions like operator*() and operator++() should not be called -
665 on an uninitialized iterator. Use operator=() to assign a value -
666 to it before using it. -
667 -
668 \sa QJsonArray::begin(), QJsonArray::end() -
669*/ -
670 -
671/*! \fn QJsonArray::iterator::iterator(QJsonArray *array, int index) -
672 \internal -
673*/ -
674 -
675/*! \fn QJsonValueRef QJsonArray::iterator::operator*() const -
676 -
677 Returns a modifiable reference to the current item. -
678 -
679 You can change the value of an item by using operator*() on the -
680 left side of an assignment. -
681 -
682 The return value is of type QJsonValueRef, a helper class for QJsonArray -
683 and QJsonObject. When you get an object of type QJsonValueRef, you can -
684 use it as if it were a reference to a QJsonValue. If you assign to it, -
685 the assignment will apply to the character in the QJsonArray of QJsonObject -
686 from which you got the reference. -
687*/ -
688 -
689/*! \fn QJsonValueRef QJsonArray::iterator::operator[](int j) const -
690 -
691 Returns a modifiable reference to the item at offset \a j from the -
692 item pointed to by this iterator (the item at position \c{*this + j}). -
693 -
694 This function is provided to make QJsonArray iterators behave like C++ -
695 pointers. -
696 -
697 The return value is of type QJsonValueRef, a helper class for QJsonArray -
698 and QJsonObject. When you get an object of type QJsonValueRef, you can -
699 use it as if it were a reference to a QJsonValue. If you assign to it, -
700 the assignment will apply to the character in the QJsonArray of QJsonObject -
701 from which you got the reference. -
702 -
703 \sa operator+() -
704*/ -
705 -
706/*! -
707 \fn bool QJsonArray::iterator::operator==(const iterator &other) const -
708 \fn bool QJsonArray::iterator::operator==(const const_iterator &other) const -
709 -
710 Returns \c true if \a other points to the same item as this -
711 iterator; otherwise returns \c false. -
712 -
713 \sa operator!=() -
714*/ -
715 -
716/*! -
717 \fn bool QJsonArray::iterator::operator!=(const iterator &other) const -
718 \fn bool QJsonArray::iterator::operator!=(const const_iterator &other) const -
719 -
720 Returns \c true if \a other points to a different item than this -
721 iterator; otherwise returns \c false. -
722 -
723 \sa operator==() -
724*/ -
725 -
726/*! -
727 \fn bool QJsonArray::iterator::operator<(const iterator& other) const -
728 \fn bool QJsonArray::iterator::operator<(const const_iterator& other) const -
729 -
730 Returns \c true if the item pointed to by this iterator is less than -
731 the item pointed to by the \a other iterator. -
732*/ -
733 -
734/*! -
735 \fn bool QJsonArray::iterator::operator<=(const iterator& other) const -
736 \fn bool QJsonArray::iterator::operator<=(const const_iterator& other) const -
737 -
738 Returns \c true if the item pointed to by this iterator is less than -
739 or equal to the item pointed to by the \a other iterator. -
740*/ -
741 -
742/*! -
743 \fn bool QJsonArray::iterator::operator>(const iterator& other) const -
744 \fn bool QJsonArray::iterator::operator>(const const_iterator& other) const -
745 -
746 Returns \c true if the item pointed to by this iterator is greater -
747 than the item pointed to by the \a other iterator. -
748*/ -
749 -
750/*! -
751 \fn bool QJsonArray::iterator::operator>=(const iterator& other) const -
752 \fn bool QJsonArray::iterator::operator>=(const const_iterator& other) const -
753 -
754 Returns \c true if the item pointed to by this iterator is greater -
755 than or equal to the item pointed to by the \a other iterator. -
756*/ -
757 -
758/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator++() -
759 -
760 The prefix ++ operator, \c{++it}, advances the iterator to the -
761 next item in the array and returns an iterator to the new current -
762 item. -
763 -
764 Calling this function on QJsonArray::end() leads to undefined results. -
765 -
766 \sa operator--() -
767*/ -
768 -
769/*! \fn QJsonArray::iterator QJsonArray::iterator::operator++(int) -
770 -
771 \overload -
772 -
773 The postfix ++ operator, \c{it++}, advances the iterator to the -
774 next item in the array and returns an iterator to the previously -
775 current item. -
776*/ -
777 -
778/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator--() -
779 -
780 The prefix -- operator, \c{--it}, makes the preceding item -
781 current and returns an iterator to the new current item. -
782 -
783 Calling this function on QJsonArray::begin() leads to undefined results. -
784 -
785 \sa operator++() -
786*/ -
787 -
788/*! \fn QJsonArray::iterator QJsonArray::iterator::operator--(int) -
789 -
790 \overload -
791 -
792 The postfix -- operator, \c{it--}, makes the preceding item -
793 current and returns an iterator to the previously current item. -
794*/ -
795 -
796/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator+=(int j) -
797 -
798 Advances the iterator by \a j items. If \a j is negative, the -
799 iterator goes backward. -
800 -
801 \sa operator-=(), operator+() -
802*/ -
803 -
804/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator-=(int j) -
805 -
806 Makes the iterator go back by \a j items. If \a j is negative, -
807 the iterator goes forward. -
808 -
809 \sa operator+=(), operator-() -
810*/ -
811 -
812/*! \fn QJsonArray::iterator QJsonArray::iterator::operator+(int j) const -
813 -
814 Returns an iterator to the item at \a j positions forward from -
815 this iterator. If \a j is negative, the iterator goes backward. -
816 -
817 \sa operator-(), operator+=() -
818*/ -
819 -
820/*! \fn QJsonArray::iterator QJsonArray::iterator::operator-(int j) const -
821 -
822 Returns an iterator to the item at \a j positions backward from -
823 this iterator. If \a j is negative, the iterator goes forward. -
824 -
825 \sa operator+(), operator-=() -
826*/ -
827 -
828/*! \fn int QJsonArray::iterator::operator-(iterator other) const -
829 -
830 Returns the number of items between the item pointed to by \a -
831 other and the item pointed to by this iterator. -
832*/ -
833 -
834/*! \class QJsonArray::const_iterator -
835 \inmodule QtCore -
836 \brief The QJsonArray::const_iterator class provides an STL-style const iterator for QJsonArray. -
837 -
838 QJsonArray::const_iterator allows you to iterate over a -
839 QJsonArray. If you want to modify the QJsonArray as -
840 you iterate over it, use QJsonArray::iterator instead. It is generally a -
841 good practice to use QJsonArray::const_iterator on a non-const QJsonArray -
842 as well, unless you need to change the QJsonArray through the -
843 iterator. Const iterators are slightly faster and improves -
844 code readability. -
845 -
846 The default QJsonArray::const_iterator constructor creates an -
847 uninitialized iterator. You must initialize it using a QJsonArray -
848 function like QJsonArray::constBegin(), QJsonArray::constEnd(), or -
849 QJsonArray::insert() before you can start iterating. -
850 -
851 Most QJsonArray functions accept an integer index rather than an -
852 iterator. For that reason, iterators are rarely useful in -
853 connection with QJsonArray. One place where STL-style iterators do -
854 make sense is as arguments to \l{generic algorithms}. -
855 -
856 Multiple iterators can be used on the same array. However, be -
857 aware that any non-const function call performed on the QJsonArray -
858 will render all existing iterators undefined. -
859 -
860 \sa QJsonArray::iterator -
861*/ -
862 -
863/*! \fn QJsonArray::const_iterator::const_iterator() -
864 -
865 Constructs an uninitialized iterator. -
866 -
867 Functions like operator*() and operator++() should not be called -
868 on an uninitialized iterator. Use operator=() to assign a value -
869 to it before using it. -
870 -
871 \sa QJsonArray::constBegin(), QJsonArray::constEnd() -
872*/ -
873 -
874/*! \fn QJsonArray::const_iterator::const_iterator(const QJsonArray *array, int index) -
875 \internal -
876*/ -
877 -
878/*! \typedef QJsonArray::const_iterator::iterator_category -
879 -
880 A synonym for \e {std::random_access_iterator_tag} indicating -
881 this iterator is a random access iterator. -
882*/ -
883 -
884/*! \typedef QJsonArray::const_iterator::difference_type -
885 -
886 \internal -
887*/ -
888 -
889/*! \typedef QJsonArray::const_iterator::value_type -
890 -
891 \internal -
892*/ -
893 -
894/*! \typedef QJsonArray::const_iterator::reference -
895 -
896 \internal -
897*/ -
898 -
899/*! \fn QJsonArray::const_iterator::const_iterator(const const_iterator &other) -
900 -
901 Constructs a copy of \a other. -
902*/ -
903 -
904/*! \fn QJsonArray::const_iterator::const_iterator(const iterator &other) -
905 -
906 Constructs a copy of \a other. -
907*/ -
908 -
909/*! \fn QJsonValue QJsonArray::const_iterator::operator*() const -
910 -
911 Returns the current item. -
912*/ -
913 -
914/*! \fn QJsonValue QJsonArray::const_iterator::operator[](int j) const -
915 -
916 Returns the item at offset \a j from the item pointed to by this iterator (the item at -
917 position \c{*this + j}). -
918 -
919 This function is provided to make QJsonArray iterators behave like C++ -
920 pointers. -
921 -
922 \sa operator+() -
923*/ -
924 -
925/*! \fn bool QJsonArray::const_iterator::operator==(const const_iterator &other) const -
926 -
927 Returns \c true if \a other points to the same item as this -
928 iterator; otherwise returns \c false. -
929 -
930 \sa operator!=() -
931*/ -
932 -
933/*! \fn bool QJsonArray::const_iterator::operator!=(const const_iterator &other) const -
934 -
935 Returns \c true if \a other points to a different item than this -
936 iterator; otherwise returns \c false. -
937 -
938 \sa operator==() -
939*/ -
940 -
941/*! -
942 \fn bool QJsonArray::const_iterator::operator<(const const_iterator& other) const -
943 -
944 Returns \c true if the item pointed to by this iterator is less than -
945 the item pointed to by the \a other iterator. -
946*/ -
947 -
948/*! -
949 \fn bool QJsonArray::const_iterator::operator<=(const const_iterator& other) const -
950 -
951 Returns \c true if the item pointed to by this iterator is less than -
952 or equal to the item pointed to by the \a other iterator. -
953*/ -
954 -
955/*! -
956 \fn bool QJsonArray::const_iterator::operator>(const const_iterator& other) const -
957 -
958 Returns \c true if the item pointed to by this iterator is greater -
959 than the item pointed to by the \a other iterator. -
960*/ -
961 -
962/*! -
963 \fn bool QJsonArray::const_iterator::operator>=(const const_iterator& other) const -
964 -
965 Returns \c true if the item pointed to by this iterator is greater -
966 than or equal to the item pointed to by the \a other iterator. -
967*/ -
968 -
969/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator++() -
970 -
971 The prefix ++ operator, \c{++it}, advances the iterator to the -
972 next item in the array and returns an iterator to the new current -
973 item. -
974 -
975 Calling this function on QJsonArray::end() leads to undefined results. -
976 -
977 \sa operator--() -
978*/ -
979 -
980/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator++(int) -
981 -
982 \overload -
983 -
984 The postfix ++ operator, \c{it++}, advances the iterator to the -
985 next item in the array and returns an iterator to the previously -
986 current item. -
987*/ -
988 -
989/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator--() -
990 -
991 The prefix -- operator, \c{--it}, makes the preceding item -
992 current and returns an iterator to the new current item. -
993 -
994 Calling this function on QJsonArray::begin() leads to undefined results. -
995 -
996 \sa operator++() -
997*/ -
998 -
999/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator--(int) -
1000 -
1001 \overload -
1002 -
1003 The postfix -- operator, \c{it--}, makes the preceding item -
1004 current and returns an iterator to the previously current item. -
1005*/ -
1006 -
1007/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator+=(int j) -
1008 -
1009 Advances the iterator by \a j items. If \a j is negative, the -
1010 iterator goes backward. -
1011 -
1012 \sa operator-=(), operator+() -
1013*/ -
1014 -
1015/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator-=(int j) -
1016 -
1017 Makes the iterator go back by \a j items. If \a j is negative, -
1018 the iterator goes forward. -
1019 -
1020 \sa operator+=(), operator-() -
1021*/ -
1022 -
1023/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator+(int j) const -
1024 -
1025 Returns an iterator to the item at \a j positions forward from -
1026 this iterator. If \a j is negative, the iterator goes backward. -
1027 -
1028 \sa operator-(), operator+=() -
1029*/ -
1030 -
1031/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator-(int j) const -
1032 -
1033 Returns an iterator to the item at \a j positions backward from -
1034 this iterator. If \a j is negative, the iterator goes forward. -
1035 -
1036 \sa operator+(), operator-=() -
1037*/ -
1038 -
1039/*! \fn int QJsonArray::const_iterator::operator-(const_iterator other) const -
1040 -
1041 Returns the number of items between the item pointed to by \a -
1042 other and the item pointed to by this iterator. -
1043*/ -
1044 -
1045 -
1046/*! -
1047 \internal -
1048 */ -
1049void QJsonArray::detach(uint reserve) -
1050{ -
1051 if (!d) {
evaluated: !d
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:137
29-137
1052 d = new QJsonPrivate::Data(reserve, QJsonValue::Array);
executed (the execution status of this line is deduced): d = new QJsonPrivate::Data(reserve, QJsonValue::Array);
-
1053 a = static_cast<QJsonPrivate::Array *>(d->header->root());
executed (the execution status of this line is deduced): a = static_cast<QJsonPrivate::Array *>(d->header->root());
-
1054 d->ref.ref();
executed (the execution status of this line is deduced): d->ref.ref();
-
1055 return;
executed: return;
Execution Count:29
29
1056 } -
1057 if (reserve == 0 && d->ref.load() == 1)
evaluated: reserve == 0
TRUEFALSE
yes
Evaluation Count:44
yes
Evaluation Count:93
evaluated: d->ref.load() == 1
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:8
8-93
1058 return;
executed: return;
Execution Count:36
36
1059 -
1060 QJsonPrivate::Data *x = d->clone(a, reserve);
executed (the execution status of this line is deduced): QJsonPrivate::Data *x = d->clone(a, reserve);
-
1061 x->ref.ref();
executed (the execution status of this line is deduced): x->ref.ref();
-
1062 if (!d->ref.deref())
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:80
21-80
1063 delete d;
executed: delete d;
Execution Count:21
21
1064 d = x;
executed (the execution status of this line is deduced): d = x;
-
1065 a = static_cast<QJsonPrivate::Array *>(d->header->root());
executed (the execution status of this line is deduced): a = static_cast<QJsonPrivate::Array *>(d->header->root());
-
1066}
executed: }
Execution Count:101
101
1067 -
1068/*! -
1069 \internal -
1070 */ -
1071void QJsonArray::compact() -
1072{ -
1073 if (!d || !d->compactionCounter)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: !d->compactionCounter
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1074 return;
never executed: return;
0
1075 -
1076 detach();
executed (the execution status of this line is deduced): detach();
-
1077 d->compact();
executed (the execution status of this line is deduced): d->compact();
-
1078 a = static_cast<QJsonPrivate::Array *>(d->header->root());
executed (the execution status of this line is deduced): a = static_cast<QJsonPrivate::Array *>(d->header->root());
-
1079}
executed: }
Execution Count:3
3
1080 -
1081 -
1082#ifndef QT_NO_DEBUG_STREAM -
1083QDebug operator<<(QDebug dbg, const QJsonArray &a) -
1084{ -
1085 if (!a.a) {
evaluated: !a.a
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
1086 dbg << "QJsonArray()";
executed (the execution status of this line is deduced): dbg << "QJsonArray()";
-
1087 return dbg;
executed: return dbg;
Execution Count:2
2
1088 } -
1089 QByteArray json;
executed (the execution status of this line is deduced): QByteArray json;
-
1090 QJsonPrivate::Writer::arrayToJson(a.a, json, 0, true);
executed (the execution status of this line is deduced): QJsonPrivate::Writer::arrayToJson(a.a, json, 0, true);
-
1091 dbg.nospace() << "QJsonArray("
executed (the execution status of this line is deduced): dbg.nospace() << "QJsonArray("
-
1092 << json.constData() // print as utf-8 string without extra quotation marks
executed (the execution status of this line is deduced): << json.constData()
-
1093 << ")";
executed (the execution status of this line is deduced): << ")";
-
1094 return dbg.space();
executed: return dbg.space();
Execution Count:2
2
1095} -
1096#endif -
1097 -
1098QT_END_NAMESPACE -
1099 -
1100 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial