qjsonarray.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/json/qjsonarray.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <qjsonobject.h>-
41#include <qjsonvalue.h>-
42#include <qjsonarray.h>-
43#include <qstringlist.h>-
44#include <qvariant.h>-
45#include <qdebug.h>-
46-
47#include "qjsonwriter_p.h"-
48#include "qjson_p.h"-
49-
50QT_BEGIN_NAMESPACE-
51-
52/*!-
53 \class QJsonArray-
54 \inmodule QtCore-
55 \ingroup json-
56 \ingroup shared-
57 \reentrant-
58 \since 5.0-
59-
60 \brief The QJsonArray class encapsulates a JSON array.-
61-
62 A JSON array is a list of values. The list can be manipulated by inserting and-
63 removing QJsonValue's from the array.-
64-
65 A QJsonArray can be converted to and from a QVariantList. You can query the-
66 number of entries with size(), insert(), and removeAt() entries from it-
67 and iterate over its content using the standard C++ iterator pattern.-
68-
69 QJsonArray is an implicitly shared class and shares the data with the document-
70 it has been created from as long as it is not being modified.-
71-
72 You can convert the array to and from text based JSON through QJsonDocument.-
73-
74 \sa {JSON Support in Qt}, {JSON Save Game Example}-
75*/-
76-
77/*!-
78 \typedef QJsonArray::Iterator-
79-
80 Qt-style synonym for QJsonArray::iterator.-
81*/-
82-
83/*!-
84 \typedef QJsonArray::ConstIterator-
85-
86 Qt-style synonym for QJsonArray::const_iterator.-
87*/-
88-
89/*!-
90 \typedef QJsonArray::size_type-
91-
92 Typedef for int. Provided for STL compatibility.-
93*/-
94-
95/*!-
96 \typedef QJsonArray::value_type-
97-
98 Typedef for QJsonValue. Provided for STL compatibility.-
99*/-
100-
101/*!-
102 \typedef QJsonArray::difference_type-
103-
104 Typedef for int. Provided for STL compatibility.-
105*/-
106-
107/*!-
108 \typedef QJsonArray::pointer-
109-
110 Typedef for QJsonValue *. Provided for STL compatibility.-
111*/-
112-
113/*!-
114 \typedef QJsonArray::const_pointer-
115-
116 Typedef for const QJsonValue *. Provided for STL compatibility.-
117*/-
118-
119/*!-
120 \typedef QJsonArray::reference-
121-
122 Typedef for QJsonValue &. Provided for STL compatibility.-
123*/-
124-
125/*!-
126 \typedef QJsonArray::const_reference-
127-
128 Typedef for const QJsonValue &. Provided for STL compatibility.-
129*/-
130-
131/*!-
132 Creates an empty array.-
133 */-
134QJsonArray::QJsonArray()-
135 : d(0), a(0)-
136{-
137}
executed 42110 times by 117 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
42110
138-
139/*!-
140 \fn QJsonArray::QJsonArray(std::initializer_list<QJsonValue> args)-
141 \since 5.4-
142 Creates an array initialized from \a args initialization list.-
143-
144 QJsonArray can be constructed in a way similar to JSON notation,-
145 for example:-
146 \code-
147 QJsonArray array = { 1, 2.2, QString() };-
148 \endcode-
149 */-
150-
151/*!-
152 \internal-
153 */-
154QJsonArray::QJsonArray(QJsonPrivate::Data *data, QJsonPrivate::Array *array)-
155 : d(data), a(array)-
156{-
157 Q_ASSERT(data);-
158 Q_ASSERT(array);-
159 d->ref.ref();-
160}
executed 42001 times by 114 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
42001
161-
162/*!-
163 This method replaces part of QJsonArray(std::initializer_list<QJsonValue> args) .-
164 The constructor needs to be inline, but we do not want to leak implementation details-
165 of this class.-
166 \note this method is called for an uninitialized object-
167 \internal-
168 */-
169void QJsonArray::initialize()-
170{-
171 d = 0;-
172 a = 0;-
173}
never executed: end of block
0
174-
175/*!-
176 Deletes the array.-
177 */-
178QJsonArray::~QJsonArray()-
179{-
180 if (d && !d->ref.deref())
dDescription
TRUEevaluated 42449 times by 115 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
FALSEevaluated 42148 times by 117 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
!d->ref.deref()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 42447 times by 115 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
2-42449
181 delete d;
executed 2 times by 1 test: delete d;
Executed by:
  • tst_QMetaType
2
182}
executed 84597 times by 117 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
84597
183-
184/*!-
185 Creates a copy of \a other.-
186-
187 Since QJsonArray is implicitly shared, the copy is shallow-
188 as long as the object doesn't get modified.-
189 */-
190QJsonArray::QJsonArray(const QJsonArray &other)-
191{-
192 d = other.d;-
193 a = other.a;-
194 if (d)
dDescription
TRUEevaluated 441 times by 2 tests
Evaluated by:
  • tst_QMetaType
  • tst_QNetworkCookieJar
FALSEevaluated 45 times by 3 tests
Evaluated by:
  • tst_QFactoryLoader
  • tst_QOpenGlConfig
  • tst_QVariant
45-441
195 d->ref.ref();
executed 441 times by 2 tests: d->ref.ref();
Executed by:
  • tst_QMetaType
  • tst_QNetworkCookieJar
441
196}
executed 486 times by 5 tests: end of block
Executed by:
  • tst_QFactoryLoader
  • tst_QMetaType
  • tst_QNetworkCookieJar
  • tst_QOpenGlConfig
  • tst_QVariant
486
197-
198/*!-
199 Assigns \a other to this array.-
200 */-
201QJsonArray &QJsonArray::operator =(const QJsonArray &other)-
202{-
203 if (d != other.d) {
d != other.dDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QOpenGlConfig
FALSEevaluated 41 times by 2 tests
Evaluated by:
  • tst_QOpenGlConfig
  • tst_QVariant
5-41
204 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QOpenGlConfig
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0-5
205 delete d;
never executed: delete d;
0
206 d = other.d;-
207 if (d)
dDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QOpenGlConfig
FALSEnever evaluated
0-5
208 d->ref.ref();
executed 5 times by 1 test: d->ref.ref();
Executed by:
  • tst_QOpenGlConfig
5
209 }
executed 5 times by 1 test: end of block
Executed by:
  • tst_QOpenGlConfig
5
210 a = other.a;-
211-
212 return *this;
executed 46 times by 2 tests: return *this;
Executed by:
  • tst_QOpenGlConfig
  • tst_QVariant
46
213}-
214-
215/*! \fn QJsonArray &QJsonArray::operator+=(const QJsonValue &value)-
216-
217 Appends \a value to the array, and returns a reference to the array itself.-
218-
219 \since 5.3-
220 \sa append(), operator<<()-
221*/-
222-
223/*! \fn QJsonArray QJsonArray::operator+(const QJsonValue &value) const-
224-
225 Returns an array that contains all the items in this array followed-
226 by the provided \a value.-
227-
228 \since 5.3-
229 \sa operator+=()-
230*/-
231-
232/*! \fn QJsonArray &QJsonArray::operator<<(const QJsonValue &value)-
233-
234 Appends \a value to the array, and returns a reference to the array itself.-
235-
236 \since 5.3-
237 \sa operator+=(), append()-
238*/-
239-
240/*!-
241 Converts the string list \a list to a QJsonArray.-
242-
243 The values in \a list will be converted to JSON values.-
244-
245 \sa toVariantList(), QJsonValue::fromVariant()-
246 */-
247QJsonArray QJsonArray::fromStringList(const QStringList &list)-
248{-
249 QJsonArray array;-
250 for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
it != list.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
251 array.append(QJsonValue(*it));
never executed: array.append(QJsonValue(*it));
0
252 return array;
never executed: return array;
0
253}-
254-
255/*!-
256 Converts the variant list \a list to a QJsonArray.-
257-
258 The QVariant values in \a list will be converted to JSON values.-
259-
260 \sa toVariantList(), QJsonValue::fromVariant()-
261 */-
262QJsonArray QJsonArray::fromVariantList(const QVariantList &list)-
263{-
264 QJsonArray array;-
265 if (list.isEmpty())
list.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
266 return array;
never executed: return array;
0
267-
268 array.detach2(1024);-
269-
270 QVector<QJsonPrivate::Value> values;-
271 values.resize(list.size());-
272 QJsonPrivate::Value *valueData = values.data();-
273 uint currentOffset = sizeof(QJsonPrivate::Base);-
274-
275 for (int i = 0; i < list.size(); ++i) {
i < list.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
276 QJsonValue val = QJsonValue::fromVariant(list.at(i));-
277-
278 bool latinOrIntValue;-
279 int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue);-
280-
281 if (!array.detach2(valueSize))
!array.detach2(valueSize)Description
TRUEnever evaluated
FALSEnever evaluated
0
282 return QJsonArray();
never executed: return QJsonArray();
0
283-
284 QJsonPrivate::Value *v = valueData + i;-
285 v->type = (val.t == QJsonValue::Undefined ? QJsonValue::Null : val.t);
val.t == QJsonValue::UndefinedDescription
TRUEnever evaluated
FALSEnever evaluated
0
286 v->latinOrIntValue = latinOrIntValue;-
287 v->latinKey = false;-
288 v->value = QJsonPrivate::Value::valueToStore(val, currentOffset);-
289 if (valueSize)
valueSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
290 QJsonPrivate::Value::copyData(val, (char *)array.a + currentOffset, latinOrIntValue);
never executed: QJsonPrivate::Value::copyData(val, (char *)array.a + currentOffset, latinOrIntValue);
0
291-
292 currentOffset += valueSize;-
293 array.a->size = currentOffset;-
294 }
never executed: end of block
0
295-
296 // write table-
297 array.a->tableOffset = currentOffset;-
298 if (!array.detach2(sizeof(QJsonPrivate::offset)*values.size()))
!array.detach2...values.size())Description
TRUEnever evaluated
FALSEnever evaluated
0
299 return QJsonArray();
never executed: return QJsonArray();
0
300 memcpy(array.a->table(), values.constData(), values.size()*sizeof(uint));-
301 array.a->length = values.size();-
302 array.a->size = currentOffset + sizeof(QJsonPrivate::offset)*values.size();-
303-
304 return array;
never executed: return array;
0
305}-
306-
307/*!-
308 Converts this object to a QVariantList.-
309-
310 Returns the created map.-
311 */-
312QVariantList QJsonArray::toVariantList() const-
313{-
314 QVariantList list;-
315-
316 if (a) {
aDescription
TRUEnever evaluated
FALSEnever evaluated
0
317 list.reserve(a->length);-
318 for (int i = 0; i < (int)a->length; ++i)
i < (int)a->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
319 list.append(QJsonValue(d, a, a->at(i)).toVariant());
never executed: list.append(QJsonValue(d, a, a->at(i)).toVariant());
0
320 }
never executed: end of block
0
321 return list;
never executed: return list;
0
322}-
323-
324-
325/*!-
326 Returns the number of values stored in the array.-
327 */-
328int QJsonArray::size() const-
329{-
330 if (!d)
!dDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFactoryLoader
FALSEevaluated 42948 times by 114 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
2-42948
331 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • tst_QFactoryLoader
2
332-
333 return (int)a->length;
executed 42948 times by 114 tests: return (int)a->length;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
42948
334}-
335-
336/*!-
337 \fn QJsonArray::count() const-
338-
339 Same as size().-
340-
341 \sa size()-
342*/-
343-
344/*!-
345 Returns \c true if the object is empty. This is the same as size() == 0.-
346-
347 \sa size()-
348 */-
349bool QJsonArray::isEmpty() const-
350{-
351 if (!d)
!dDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_QOpenGlConfig
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QOpenGlConfig
3-18
352 return true;
executed 18 times by 1 test: return true;
Executed by:
  • tst_QOpenGlConfig
18
353-
354 return !a->length;
executed 3 times by 1 test: return !a->length;
Executed by:
  • tst_QOpenGlConfig
3
355}-
356-
357/*!-
358 Returns a QJsonValue representing the value for index \a i.-
359-
360 The returned QJsonValue is \c Undefined, if \a i is out of bounds.-
361-
362 */-
363QJsonValue QJsonArray::at(int i) const-
364{-
365 if (!a || i < 0 || i >= (int)a->length)
!aDescription
TRUEnever evaluated
FALSEevaluated 68845 times by 114 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
i < 0Description
TRUEnever evaluated
FALSEevaluated 68845 times by 114 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
i >= (int)a->lengthDescription
TRUEevaluated 2 times by 2 tests
Evaluated by:
  • tst_QImageReader
  • tst_QImageWriter
FALSEevaluated 68843 times by 114 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
0-68845
366 return QJsonValue(QJsonValue::Undefined);
executed 2 times by 2 tests: return QJsonValue(QJsonValue::Undefined);
Executed by:
  • tst_QImageReader
  • tst_QImageWriter
2
367-
368 return QJsonValue(d, a, a->at(i));
executed 68843 times by 114 tests: return QJsonValue(d, a, a->at(i));
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
68843
369}-
370-
371/*!-
372 Returns the first value stored in the array.-
373-
374 Same as \c at(0).-
375-
376 \sa at()-
377 */-
378QJsonValue QJsonArray::first() const-
379{-
380 return at(0);
never executed: return at(0);
0
381}-
382-
383/*!-
384 Returns the last value stored in the array.-
385-
386 Same as \c{at(size() - 1)}.-
387-
388 \sa at()-
389 */-
390QJsonValue QJsonArray::last() const-
391{-
392 return at(a ? (a->length - 1) : 0);
never executed: return at(a ? (a->length - 1) : 0);
0
393}-
394-
395/*!-
396 Inserts \a value at the beginning of the array.-
397-
398 This is the same as \c{insert(0, value)} and will prepend \a value to the array.-
399-
400 \sa append(), insert()-
401 */-
402void QJsonArray::prepend(const QJsonValue &value)-
403{-
404 insert(0, value);-
405}
never executed: end of block
0
406-
407/*!-
408 Inserts \a value at the end of the array.-
409-
410 \sa prepend(), insert()-
411 */-
412void QJsonArray::append(const QJsonValue &value)-
413{-
414 insert(a ? (int)a->length : 0, value);-
415}
executed 8 times by 1 test: end of block
Executed by:
  • tst_QMetaType
8
416-
417/*!-
418 Removes the value at index position \a i. \a i must be a valid-
419 index position in the array (i.e., \c{0 <= i < size()}).-
420-
421 \sa insert(), replace()-
422 */-
423void QJsonArray::removeAt(int i)-
424{-
425 if (!a || i < 0 || i >= (int)a->length)
!aDescription
TRUEnever evaluated
FALSEnever evaluated
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
i >= (int)a->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
426 return;
never executed: return;
0
427-
428 detach2();-
429 a->removeItems(i, 1);-
430 ++d->compactionCounter;-
431 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
d->compactionCounter > 32uDescription
TRUEnever evaluated
FALSEnever evaluated
d->compactionC...->length) / 2uDescription
TRUEnever evaluated
FALSEnever evaluated
0
432 compact();
never executed: compact();
0
433}
never executed: end of block
0
434-
435/*! \fn void QJsonArray::removeFirst()-
436-
437 Removes the first item in the array. Calling this function is-
438 equivalent to calling \c{removeAt(0)}. The array must not be empty. If-
439 the array can be empty, call isEmpty() before calling this-
440 function.-
441-
442 \sa removeAt(), removeLast()-
443*/-
444-
445/*! \fn void QJsonArray::removeLast()-
446-
447 Removes the last item in the array. Calling this function is-
448 equivalent to calling \c{removeAt(size() - 1)}. The array must not be-
449 empty. If the array can be empty, call isEmpty() before calling-
450 this function.-
451-
452 \sa removeAt(), removeFirst()-
453*/-
454-
455/*!-
456 Removes the item at index position \a i and returns it. \a i must-
457 be a valid index position in the array (i.e., \c{0 <= i < size()}).-
458-
459 If you don't use the return value, removeAt() is more efficient.-
460-
461 \sa removeAt()-
462 */-
463QJsonValue QJsonArray::takeAt(int i)-
464{-
465 if (!a || i < 0 || i >= (int)a->length)
!aDescription
TRUEnever evaluated
FALSEnever evaluated
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
i >= (int)a->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
466 return QJsonValue(QJsonValue::Undefined);
never executed: return QJsonValue(QJsonValue::Undefined);
0
467-
468 QJsonValue v(d, a, a->at(i));-
469 removeAt(i); // detaches-
470 return v;
never executed: return v;
0
471}-
472-
473/*!-
474 Inserts \a value at index position \a i in the array. If \a i-
475 is \c 0, the value is prepended to the array. If \a i is size(), the-
476 value is appended to the array.-
477-
478 \sa append(), prepend(), replace(), removeAt()-
479 */-
480void QJsonArray::insert(int i, const QJsonValue &value)-
481{-
482 Q_ASSERT (i >= 0 && i <= (a ? (int)a->length : 0));-
483 QJsonValue val = value;-
484-
485 bool compressed;-
486 int valueSize = QJsonPrivate::Value::requiredStorage(val, &compressed);-
487-
488 if (!detach2(valueSize + sizeof(QJsonPrivate::Value)))
!detach2(value...ivate::Value))Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
0-8
489 return;
never executed: return;
0
490-
491 if (!a->length)
!a->lengthDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
2-6
492 a->tableOffset = sizeof(QJsonPrivate::Array);
executed 2 times by 1 test: a->tableOffset = sizeof(QJsonPrivate::Array);
Executed by:
  • tst_QMetaType
2
493-
494 int valueOffset = a->reserveSpace(valueSize, i, 1, false);-
495 if (!valueOffset)
!valueOffsetDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
0-8
496 return;
never executed: return;
0
497-
498 QJsonPrivate::Value &v = (*a)[i];-
499 v.type = (val.t == QJsonValue::Undefined ? QJsonValue::Null : val.t);
val.t == QJsonValue::UndefinedDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
0-8
500 v.latinOrIntValue = compressed;-
501 v.latinKey = false;-
502 v.value = QJsonPrivate::Value::valueToStore(val, valueOffset);-
503 if (valueSize)
valueSizeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
2-6
504 QJsonPrivate::Value::copyData(val, (char *)a + valueOffset, compressed);
executed 2 times by 1 test: QJsonPrivate::Value::copyData(val, (char *)a + valueOffset, compressed);
Executed by:
  • tst_QMetaType
2
505}
executed 8 times by 1 test: end of block
Executed by:
  • tst_QMetaType
8
506-
507/*!-
508 \fn QJsonArray::iterator QJsonArray::insert(iterator before, const QJsonValue &value)-
509-
510 Inserts \a value before the position pointed to by \a before, and returns an iterator-
511 pointing to the newly inserted item.-
512-
513 \sa erase(), insert()-
514*/-
515-
516/*!-
517 \fn QJsonArray::iterator QJsonArray::erase(iterator it)-
518-
519 Removes the item pointed to by \a it, and returns an iterator pointing to the-
520 next item.-
521-
522 \sa removeAt()-
523*/-
524-
525/*!-
526 Replaces the item at index position \a i with \a value. \a i must-
527 be a valid index position in the array (i.e., \c{0 <= i < size()}).-
528-
529 \sa operator[](), removeAt()-
530 */-
531void QJsonArray::replace(int i, const QJsonValue &value)-
532{-
533 Q_ASSERT (a && i >= 0 && i < (int)(a->length));-
534 QJsonValue val = value;-
535-
536 bool compressed;-
537 int valueSize = QJsonPrivate::Value::requiredStorage(val, &compressed);-
538-
539 if (!detach2(valueSize))
!detach2(valueSize)Description
TRUEnever evaluated
FALSEnever evaluated
0
540 return;
never executed: return;
0
541-
542 if (!a->length)
!a->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
543 a->tableOffset = sizeof(QJsonPrivate::Array);
never executed: a->tableOffset = sizeof(QJsonPrivate::Array);
0
544-
545 int valueOffset = a->reserveSpace(valueSize, i, 1, true);-
546 if (!valueOffset)
!valueOffsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
547 return;
never executed: return;
0
548-
549 QJsonPrivate::Value &v = (*a)[i];-
550 v.type = (val.t == QJsonValue::Undefined ? QJsonValue::Null : val.t);
val.t == QJsonValue::UndefinedDescription
TRUEnever evaluated
FALSEnever evaluated
0
551 v.latinOrIntValue = compressed;-
552 v.latinKey = false;-
553 v.value = QJsonPrivate::Value::valueToStore(val, valueOffset);-
554 if (valueSize)
valueSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
555 QJsonPrivate::Value::copyData(val, (char *)a + valueOffset, compressed);
never executed: QJsonPrivate::Value::copyData(val, (char *)a + valueOffset, compressed);
0
556-
557 ++d->compactionCounter;-
558 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
d->compactionCounter > 32uDescription
TRUEnever evaluated
FALSEnever evaluated
d->compactionC...->length) / 2uDescription
TRUEnever evaluated
FALSEnever evaluated
0
559 compact();
never executed: compact();
0
560}
never executed: end of block
0
561-
562/*!-
563 Returns \c true if the array contains an occurrence of \a value, otherwise \c false.-
564-
565 \sa count()-
566 */-
567bool QJsonArray::contains(const QJsonValue &value) const-
568{-
569 for (int i = 0; i < size(); i++) {
i < size()Description
TRUEnever evaluated
FALSEnever evaluated
0
570 if (at(i) == value)
at(i) == valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
571 return true;
never executed: return true;
0
572 }
never executed: end of block
0
573 return false;
never executed: return false;
0
574}-
575-
576/*!-
577 Returns the value at index position \a i as a modifiable reference.-
578 \a i must be a valid index position in the array (i.e., \c{0 <= i <-
579 size()}).-
580-
581 The return value is of type QJsonValueRef, a helper class for QJsonArray-
582 and QJsonObject. When you get an object of type QJsonValueRef, you can-
583 use it as if it were a reference to a QJsonValue. If you assign to it,-
584 the assignment will apply to the character in the QJsonArray of QJsonObject-
585 from which you got the reference.-
586-
587 \sa at()-
588 */-
589QJsonValueRef QJsonArray::operator [](int i)-
590{-
591 Q_ASSERT(a && i >= 0 && i < (int)a->length);-
592 return QJsonValueRef(this, i);
never executed: return QJsonValueRef(this, i);
0
593}-
594-
595/*!-
596 \overload-
597-
598 Same as at().-
599 */-
600QJsonValue QJsonArray::operator[](int i) const-
601{-
602 return at(i);
never executed: return at(i);
0
603}-
604-
605/*!-
606 Returns \c true if this array is equal to \a other.-
607 */-
608bool QJsonArray::operator==(const QJsonArray &other) const-
609{-
610 if (a == other.a)
a == other.aDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEnever evaluated
0-8
611 return true;
executed 8 times by 1 test: return true;
Executed by:
  • tst_QMetaType
8
612-
613 if (!a)
!aDescription
TRUEnever evaluated
FALSEnever evaluated
0
614 return !other.a->length;
never executed: return !other.a->length;
0
615 if (!other.a)
!other.aDescription
TRUEnever evaluated
FALSEnever evaluated
0
616 return !a->length;
never executed: return !a->length;
0
617 if (a->length != other.a->length)
a->length != other.a->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
618 return false;
never executed: return false;
0
619-
620 for (int i = 0; i < (int)a->length; ++i) {
i < (int)a->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
621 if (QJsonValue(d, a, a->at(i)) != QJsonValue(other.d, other.a, other.a->at(i)))
QJsonValue(d, ...ther.a->at(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
622 return false;
never executed: return false;
0
623 }
never executed: end of block
0
624 return true;
never executed: return true;
0
625}-
626-
627/*!-
628 Returns \c true if this array is not equal to \a other.-
629 */-
630bool QJsonArray::operator!=(const QJsonArray &other) const-
631{-
632 return !(*this == other);
never executed: return !(*this == other);
0
633}-
634-
635/*! \fn QJsonArray::iterator QJsonArray::begin()-
636-
637 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in-
638 the array.-
639-
640 \sa constBegin(), end()-
641*/-
642-
643/*! \fn QJsonArray::const_iterator QJsonArray::begin() const-
644-
645 \overload-
646*/-
647-
648/*! \fn QJsonArray::const_iterator QJsonArray::constBegin() const-
649-
650 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item-
651 in the array.-
652-
653 \sa begin(), constEnd()-
654*/-
655-
656/*! \fn QJsonArray::iterator QJsonArray::end()-
657-
658 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item-
659 after the last item in the array.-
660-
661 \sa begin(), constEnd()-
662*/-
663-
664/*! \fn const_iterator QJsonArray::end() const-
665-
666 \overload-
667*/-
668-
669/*! \fn QJsonArray::const_iterator QJsonArray::constEnd() const-
670-
671 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary-
672 item after the last item in the array.-
673-
674 \sa constBegin(), end()-
675*/-
676-
677/*! \fn void QJsonArray::push_back(const QJsonValue &value)-
678-
679 This function is provided for STL compatibility. It is equivalent-
680 to \l{QJsonArray::append()}{append(value)} and will append \a value to the array.-
681*/-
682-
683/*! \fn void QJsonArray::push_front(const QJsonValue &value)-
684-
685 This function is provided for STL compatibility. It is equivalent-
686 to \l{QJsonArray::prepend()}{prepend(value)} and will prepend \a value to the array.-
687*/-
688-
689/*! \fn void QJsonArray::pop_front()-
690-
691 This function is provided for STL compatibility. It is equivalent-
692 to removeFirst(). The array must not be empty. If the array can be-
693 empty, call isEmpty() before calling this function.-
694*/-
695-
696/*! \fn void QJsonArray::pop_back()-
697-
698 This function is provided for STL compatibility. It is equivalent-
699 to removeLast(). The array must not be empty. If the array can be-
700 empty, call isEmpty() before calling this function.-
701*/-
702-
703/*! \fn bool QJsonArray::empty() const-
704-
705 This function is provided for STL compatibility. It is equivalent-
706 to isEmpty() and returns \c true if the array is empty.-
707*/-
708-
709/*! \class QJsonArray::iterator-
710 \inmodule QtCore-
711 \brief The QJsonArray::iterator class provides an STL-style non-const iterator for QJsonArray.-
712-
713 QJsonArray::iterator allows you to iterate over a QJsonArray-
714 and to modify the array item associated with the-
715 iterator. If you want to iterate over a const QJsonArray, use-
716 QJsonArray::const_iterator instead. It is generally a good practice to-
717 use QJsonArray::const_iterator on a non-const QJsonArray as well, unless-
718 you need to change the QJsonArray through the iterator. Const-
719 iterators are slightly faster and improves code readability.-
720-
721 The default QJsonArray::iterator constructor creates an uninitialized-
722 iterator. You must initialize it using a QJsonArray function like-
723 QJsonArray::begin(), QJsonArray::end(), or QJsonArray::insert() before you can-
724 start iterating.-
725-
726 Most QJsonArray functions accept an integer index rather than an-
727 iterator. For that reason, iterators are rarely useful in-
728 connection with QJsonArray. One place where STL-style iterators do-
729 make sense is as arguments to \l{generic algorithms}.-
730-
731 Multiple iterators can be used on the same array. However, be-
732 aware that any non-const function call performed on the QJsonArray-
733 will render all existing iterators undefined.-
734-
735 \sa QJsonArray::const_iterator-
736*/-
737-
738/*! \typedef QJsonArray::iterator::iterator_category-
739-
740 A synonym for \e {std::random_access_iterator_tag} indicating-
741 this iterator is a random access iterator.-
742*/-
743-
744/*! \typedef QJsonArray::iterator::difference_type-
745-
746 \internal-
747*/-
748-
749/*! \typedef QJsonArray::iterator::value_type-
750-
751 \internal-
752*/-
753-
754/*! \typedef QJsonArray::iterator::reference-
755-
756 \internal-
757*/-
758-
759/*! \typedef QJsonArray::iterator::pointer-
760-
761 \internal-
762*/-
763-
764/*! \fn QJsonArray::iterator::iterator()-
765-
766 Constructs an uninitialized iterator.-
767-
768 Functions like operator*() and operator++() should not be called-
769 on an uninitialized iterator. Use operator=() to assign a value-
770 to it before using it.-
771-
772 \sa QJsonArray::begin(), QJsonArray::end()-
773*/-
774-
775/*! \fn QJsonArray::iterator::iterator(QJsonArray *array, int index)-
776 \internal-
777*/-
778-
779/*! \fn QJsonValueRef QJsonArray::iterator::operator*() const-
780-
781-
782 Returns a modifiable reference to the current item.-
783-
784 You can change the value of an item by using operator*() on the-
785 left side of an assignment.-
786-
787 The return value is of type QJsonValueRef, a helper class for QJsonArray-
788 and QJsonObject. When you get an object of type QJsonValueRef, you can-
789 use it as if it were a reference to a QJsonValue. If you assign to it,-
790 the assignment will apply to the character in the QJsonArray of QJsonObject-
791 from which you got the reference.-
792*/-
793-
794/*! \fn QJsonValueRef *QJsonArray::iterator::operator->() const-
795-
796 Returns a pointer to a modifiable reference to the current item.-
797*/-
798-
799/*! \fn QJsonValueRef QJsonArray::iterator::operator[](int j) const-
800-
801 Returns a modifiable reference to the item at offset \a j from the-
802 item pointed to by this iterator (the item at position \c{*this + j}).-
803-
804 This function is provided to make QJsonArray iterators behave like C++-
805 pointers.-
806-
807 The return value is of type QJsonValueRef, a helper class for QJsonArray-
808 and QJsonObject. When you get an object of type QJsonValueRef, you can-
809 use it as if it were a reference to a QJsonValue. If you assign to it,-
810 the assignment will apply to the character in the QJsonArray of QJsonObject-
811 from which you got the reference.-
812-
813 \sa operator+()-
814*/-
815-
816/*!-
817 \fn bool QJsonArray::iterator::operator==(const iterator &other) const-
818 \fn bool QJsonArray::iterator::operator==(const const_iterator &other) const-
819-
820 Returns \c true if \a other points to the same item as this-
821 iterator; otherwise returns \c false.-
822-
823 \sa operator!=()-
824*/-
825-
826/*!-
827 \fn bool QJsonArray::iterator::operator!=(const iterator &other) const-
828 \fn bool QJsonArray::iterator::operator!=(const const_iterator &other) const-
829-
830 Returns \c true if \a other points to a different item than this-
831 iterator; otherwise returns \c false.-
832-
833 \sa operator==()-
834*/-
835-
836/*!-
837 \fn bool QJsonArray::iterator::operator<(const iterator& other) const-
838 \fn bool QJsonArray::iterator::operator<(const const_iterator& other) const-
839-
840 Returns \c true if the item pointed to by this iterator is less than-
841 the item pointed to by the \a other iterator.-
842*/-
843-
844/*!-
845 \fn bool QJsonArray::iterator::operator<=(const iterator& other) const-
846 \fn bool QJsonArray::iterator::operator<=(const const_iterator& other) const-
847-
848 Returns \c true if the item pointed to by this iterator is less than-
849 or equal to the item pointed to by the \a other iterator.-
850*/-
851-
852/*!-
853 \fn bool QJsonArray::iterator::operator>(const iterator& other) const-
854 \fn bool QJsonArray::iterator::operator>(const const_iterator& other) const-
855-
856 Returns \c true if the item pointed to by this iterator is greater-
857 than the item pointed to by the \a other iterator.-
858*/-
859-
860/*!-
861 \fn bool QJsonArray::iterator::operator>=(const iterator& other) const-
862 \fn bool QJsonArray::iterator::operator>=(const const_iterator& other) const-
863-
864 Returns \c true if the item pointed to by this iterator is greater-
865 than or equal to the item pointed to by the \a other iterator.-
866*/-
867-
868/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator++()-
869-
870 The prefix ++ operator, \c{++it}, advances the iterator to the-
871 next item in the array and returns an iterator to the new current-
872 item.-
873-
874 Calling this function on QJsonArray::end() leads to undefined results.-
875-
876 \sa operator--()-
877*/-
878-
879/*! \fn QJsonArray::iterator QJsonArray::iterator::operator++(int)-
880-
881 \overload-
882-
883 The postfix ++ operator, \c{it++}, advances the iterator to the-
884 next item in the array and returns an iterator to the previously-
885 current item.-
886*/-
887-
888/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator--()-
889-
890 The prefix -- operator, \c{--it}, makes the preceding item-
891 current and returns an iterator to the new current item.-
892-
893 Calling this function on QJsonArray::begin() leads to undefined results.-
894-
895 \sa operator++()-
896*/-
897-
898/*! \fn QJsonArray::iterator QJsonArray::iterator::operator--(int)-
899-
900 \overload-
901-
902 The postfix -- operator, \c{it--}, makes the preceding item-
903 current and returns an iterator to the previously current item.-
904*/-
905-
906/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator+=(int j)-
907-
908 Advances the iterator by \a j items. If \a j is negative, the-
909 iterator goes backward.-
910-
911 \sa operator-=(), operator+()-
912*/-
913-
914/*! \fn QJsonArray::iterator &QJsonArray::iterator::operator-=(int j)-
915-
916 Makes the iterator go back by \a j items. If \a j is negative,-
917 the iterator goes forward.-
918-
919 \sa operator+=(), operator-()-
920*/-
921-
922/*! \fn QJsonArray::iterator QJsonArray::iterator::operator+(int j) const-
923-
924 Returns an iterator to the item at \a j positions forward from-
925 this iterator. If \a j is negative, the iterator goes backward.-
926-
927 \sa operator-(), operator+=()-
928*/-
929-
930/*! \fn QJsonArray::iterator QJsonArray::iterator::operator-(int j) const-
931-
932 Returns an iterator to the item at \a j positions backward from-
933 this iterator. If \a j is negative, the iterator goes forward.-
934-
935 \sa operator+(), operator-=()-
936*/-
937-
938/*! \fn int QJsonArray::iterator::operator-(iterator other) const-
939-
940 Returns the number of items between the item pointed to by \a-
941 other and the item pointed to by this iterator.-
942*/-
943-
944/*! \class QJsonArray::const_iterator-
945 \inmodule QtCore-
946 \brief The QJsonArray::const_iterator class provides an STL-style const iterator for QJsonArray.-
947-
948 QJsonArray::const_iterator allows you to iterate over a-
949 QJsonArray. If you want to modify the QJsonArray as-
950 you iterate over it, use QJsonArray::iterator instead. It is generally a-
951 good practice to use QJsonArray::const_iterator on a non-const QJsonArray-
952 as well, unless you need to change the QJsonArray through the-
953 iterator. Const iterators are slightly faster and improves-
954 code readability.-
955-
956 The default QJsonArray::const_iterator constructor creates an-
957 uninitialized iterator. You must initialize it using a QJsonArray-
958 function like QJsonArray::constBegin(), QJsonArray::constEnd(), or-
959 QJsonArray::insert() before you can start iterating.-
960-
961 Most QJsonArray functions accept an integer index rather than an-
962 iterator. For that reason, iterators are rarely useful in-
963 connection with QJsonArray. One place where STL-style iterators do-
964 make sense is as arguments to \l{generic algorithms}.-
965-
966 Multiple iterators can be used on the same array. However, be-
967 aware that any non-const function call performed on the QJsonArray-
968 will render all existing iterators undefined.-
969-
970 \sa QJsonArray::iterator-
971*/-
972-
973/*! \fn QJsonArray::const_iterator::const_iterator()-
974-
975 Constructs an uninitialized iterator.-
976-
977 Functions like operator*() and operator++() should not be called-
978 on an uninitialized iterator. Use operator=() to assign a value-
979 to it before using it.-
980-
981 \sa QJsonArray::constBegin(), QJsonArray::constEnd()-
982*/-
983-
984/*! \fn QJsonArray::const_iterator::const_iterator(const QJsonArray *array, int index)-
985 \internal-
986*/-
987-
988/*! \typedef QJsonArray::const_iterator::iterator_category-
989-
990 A synonym for \e {std::random_access_iterator_tag} indicating-
991 this iterator is a random access iterator.-
992*/-
993-
994/*! \typedef QJsonArray::const_iterator::difference_type-
995-
996 \internal-
997*/-
998-
999/*! \typedef QJsonArray::const_iterator::value_type-
1000-
1001 \internal-
1002*/-
1003-
1004/*! \typedef QJsonArray::const_iterator::reference-
1005-
1006 \internal-
1007*/-
1008-
1009/*! \typedef QJsonArray::const_iterator::pointer-
1010-
1011 \internal-
1012*/-
1013-
1014/*! \fn QJsonArray::const_iterator::const_iterator(const const_iterator &other)-
1015-
1016 Constructs a copy of \a other.-
1017*/-
1018-
1019/*! \fn QJsonArray::const_iterator::const_iterator(const iterator &other)-
1020-
1021 Constructs a copy of \a other.-
1022*/-
1023-
1024/*! \fn QJsonValue QJsonArray::const_iterator::operator*() const-
1025-
1026 Returns the current item.-
1027*/-
1028-
1029/*! \fn QJsonValue *QJsonArray::const_iterator::operator->() const-
1030-
1031 Returns a pointer to the current item.-
1032*/-
1033-
1034/*! \fn QJsonValue QJsonArray::const_iterator::operator[](int j) const-
1035-
1036 Returns the item at offset \a j from the item pointed to by this iterator (the item at-
1037 position \c{*this + j}).-
1038-
1039 This function is provided to make QJsonArray iterators behave like C++-
1040 pointers.-
1041-
1042 \sa operator+()-
1043*/-
1044-
1045/*! \fn bool QJsonArray::const_iterator::operator==(const const_iterator &other) const-
1046-
1047 Returns \c true if \a other points to the same item as this-
1048 iterator; otherwise returns \c false.-
1049-
1050 \sa operator!=()-
1051*/-
1052-
1053/*! \fn bool QJsonArray::const_iterator::operator!=(const const_iterator &other) const-
1054-
1055 Returns \c true if \a other points to a different item than this-
1056 iterator; otherwise returns \c false.-
1057-
1058 \sa operator==()-
1059*/-
1060-
1061/*!-
1062 \fn bool QJsonArray::const_iterator::operator<(const const_iterator& other) const-
1063-
1064 Returns \c true if the item pointed to by this iterator is less than-
1065 the item pointed to by the \a other iterator.-
1066*/-
1067-
1068/*!-
1069 \fn bool QJsonArray::const_iterator::operator<=(const const_iterator& other) const-
1070-
1071 Returns \c true if the item pointed to by this iterator is less than-
1072 or equal to the item pointed to by the \a other iterator.-
1073*/-
1074-
1075/*!-
1076 \fn bool QJsonArray::const_iterator::operator>(const const_iterator& other) const-
1077-
1078 Returns \c true if the item pointed to by this iterator is greater-
1079 than the item pointed to by the \a other iterator.-
1080*/-
1081-
1082/*!-
1083 \fn bool QJsonArray::const_iterator::operator>=(const const_iterator& other) const-
1084-
1085 Returns \c true if the item pointed to by this iterator is greater-
1086 than or equal to the item pointed to by the \a other iterator.-
1087*/-
1088-
1089/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator++()-
1090-
1091 The prefix ++ operator, \c{++it}, advances the iterator to the-
1092 next item in the array and returns an iterator to the new current-
1093 item.-
1094-
1095 Calling this function on QJsonArray::end() leads to undefined results.-
1096-
1097 \sa operator--()-
1098*/-
1099-
1100/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator++(int)-
1101-
1102 \overload-
1103-
1104 The postfix ++ operator, \c{it++}, advances the iterator to the-
1105 next item in the array and returns an iterator to the previously-
1106 current item.-
1107*/-
1108-
1109/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator--()-
1110-
1111 The prefix -- operator, \c{--it}, makes the preceding item-
1112 current and returns an iterator to the new current item.-
1113-
1114 Calling this function on QJsonArray::begin() leads to undefined results.-
1115-
1116 \sa operator++()-
1117*/-
1118-
1119/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator--(int)-
1120-
1121 \overload-
1122-
1123 The postfix -- operator, \c{it--}, makes the preceding item-
1124 current and returns an iterator to the previously current item.-
1125*/-
1126-
1127/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator+=(int j)-
1128-
1129 Advances the iterator by \a j items. If \a j is negative, the-
1130 iterator goes backward.-
1131-
1132 \sa operator-=(), operator+()-
1133*/-
1134-
1135/*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator-=(int j)-
1136-
1137 Makes the iterator go back by \a j items. If \a j is negative,-
1138 the iterator goes forward.-
1139-
1140 \sa operator+=(), operator-()-
1141*/-
1142-
1143/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator+(int j) const-
1144-
1145 Returns an iterator to the item at \a j positions forward from-
1146 this iterator. If \a j is negative, the iterator goes backward.-
1147-
1148 \sa operator-(), operator+=()-
1149*/-
1150-
1151/*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator-(int j) const-
1152-
1153 Returns an iterator to the item at \a j positions backward from-
1154 this iterator. If \a j is negative, the iterator goes forward.-
1155-
1156 \sa operator+(), operator-=()-
1157*/-
1158-
1159/*! \fn int QJsonArray::const_iterator::operator-(const_iterator other) const-
1160-
1161 Returns the number of items between the item pointed to by \a-
1162 other and the item pointed to by this iterator.-
1163*/-
1164-
1165-
1166/*!-
1167 \internal-
1168 */-
1169void QJsonArray::detach(uint reserve)-
1170{-
1171 Q_UNUSED(reserve)-
1172 Q_ASSERT(!reserve);-
1173 detach2(0);-
1174}
never executed: end of block
0
1175-
1176/*!-
1177 \internal-
1178 */-
1179bool QJsonArray::detach2(uint reserve)-
1180{-
1181 if (!d) {
!dDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
2-6
1182 if (reserve >= QJsonPrivate::Value::MaxSize) {
reserve >= QJs...Value::MaxSizeDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
0-2
1183 qWarning("QJson: Document too large to store in data structure");-
1184 return false;
never executed: return false;
0
1185 }-
1186 d = new QJsonPrivate::Data(reserve, QJsonValue::Array);-
1187 a = static_cast<QJsonPrivate::Array *>(d->header->root());-
1188 d->ref.ref();-
1189 return true;
executed 2 times by 1 test: return true;
Executed by:
  • tst_QMetaType
2
1190 }-
1191 if (reserve == 0 && d->ref.load() == 1)
reserve == 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
d->ref.load() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0-6
1192 return true;
never executed: return true;
0
1193-
1194 QJsonPrivate::Data *x = d->clone(a, reserve);-
1195 if (!x)
!xDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
0-6
1196 return false;
never executed: return false;
0
1197 x->ref.ref();-
1198 if (!d->ref.deref())
!d->ref.deref()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QMetaType
2-4
1199 delete d;
executed 2 times by 1 test: delete d;
Executed by:
  • tst_QMetaType
2
1200 d = x;-
1201 a = static_cast<QJsonPrivate::Array *>(d->header->root());-
1202 return true;
executed 6 times by 1 test: return true;
Executed by:
  • tst_QMetaType
6
1203}-
1204-
1205/*!-
1206 \internal-
1207 */-
1208void QJsonArray::compact()-
1209{-
1210 if (!d || !d->compactionCounter)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->compactionCounterDescription
TRUEnever evaluated
FALSEnever evaluated
0
1211 return;
never executed: return;
0
1212-
1213 detach2();-
1214 d->compact();-
1215 a = static_cast<QJsonPrivate::Array *>(d->header->root());-
1216}
never executed: end of block
0
1217-
1218-
1219#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)-
1220QDebug operator<<(QDebug dbg, const QJsonArray &a)-
1221{-
1222 QDebugStateSaver saver(dbg);-
1223 if (!a.a) {
!a.aDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QVariant
FALSEnever evaluated
0-1
1224 dbg << "QJsonArray()";-
1225 return dbg;
executed 1 time by 1 test: return dbg;
Executed by:
  • tst_QVariant
1
1226 }-
1227 QByteArray json;-
1228 QJsonPrivate::Writer::arrayToJson(a.a, json, 0, true);-
1229 dbg.nospace() << "QJsonArray("-
1230 << json.constData() // print as utf-8 string without extra quotation marks-
1231 << ")";-
1232 return dbg;
never executed: return dbg;
0
1233}-
1234#endif-
1235-
1236QT_END_NAMESPACE-
1237-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9