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

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