json/qjsonvalue.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include <qjsonobject.h> -
43#include <qjsonvalue.h> -
44#include <qjsonarray.h> -
45#include <qvariant.h> -
46#include <qstringlist.h> -
47#include <qdebug.h> -
48 -
49#include "qjson_p.h" -
50 -
51QT_BEGIN_NAMESPACE -
52 -
53/*! -
54 \class QJsonValue -
55 \inmodule QtCore -
56 \ingroup json -
57 \reentrant -
58 \since 5.0 -
59 -
60 \brief The QJsonValue class encapsulates a value in JSON. -
61 -
62 A value in JSON can be one of 6 basic types: -
63 -
64 JSON is a format to store structured data. It has 6 basic data types: -
65 -
66 \list -
67 \li bool QJsonValue::Bool -
68 \li double QJsonValue::Double -
69 \li string QJsonValue::String -
70 \li array QJsonValue::Array -
71 \li object QJsonValue::Object -
72 \li null QJsonValue::Null -
73 \endlist -
74 -
75 A value can represent any of the above data types. In addition, QJsonValue has one special -
76 flag to represent undefined values. This can be queried with isUndefined(). -
77 -
78 The type of the value can be queried with type() or accessors like isBool(), isString(), and so on. -
79 Likewise, the value can be converted to the type stored in it using the toBool(), toString() and so on. -
80 -
81 Values are strictly typed internally and contrary to QVariant will not attempt to do any implicit type -
82 conversions. This implies that converting to a type that is not stored in the value will return a default -
83 constructed return value. -
84*/ -
85 -
86/*! -
87 Creates a QJsonValue of type \a type. -
88 -
89 The default is to create a Null value. -
90 */ -
91QJsonValue::QJsonValue(Type type) -
92 : ui(0), d(0), t(type) -
93{ -
94}
executed: }
Execution Count:256
256
95 -
96/*! -
97 \internal -
98 */ -
99QJsonValue::QJsonValue(QJsonPrivate::Data *data, QJsonPrivate::Base *base, const QJsonPrivate::Value &v) -
100 : d(0) -
101{ -
102 t = (Type)(uint)v.type;
executed (the execution status of this line is deduced): t = (Type)(uint)v.type;
-
103 switch (t) { -
104 case Undefined: -
105 case Null: -
106 dbl = 0;
executed (the execution status of this line is deduced): dbl = 0;
-
107 break;
executed: break;
Execution Count:30
30
108 case Bool: -
109 b = v.toBoolean();
executed (the execution status of this line is deduced): b = v.toBoolean();
-
110 break;
executed: break;
Execution Count:293
293
111 case Double: -
112 dbl = v.toDouble(base);
executed (the execution status of this line is deduced): dbl = v.toDouble(base);
-
113 break;
executed: break;
Execution Count:5710
5710
114 case String: { -
115 QString s = v.toString(base);
executed (the execution status of this line is deduced): QString s = v.toString(base);
-
116 stringData = s.data_ptr();
executed (the execution status of this line is deduced): stringData = s.data_ptr();
-
117 stringData->ref.ref();
executed (the execution status of this line is deduced): stringData->ref.ref();
-
118 break;
executed: break;
Execution Count:26803
26803
119 } -
120 case Array: -
121 case Object: -
122 d = data;
executed (the execution status of this line is deduced): d = data;
-
123 this->base = v.base(base);
executed (the execution status of this line is deduced): this->base = v.base(base);
-
124 break;
executed: break;
Execution Count:26898
26898
125 } -
126 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:26898
yes
Evaluation Count:32836
26898-32836
127 d->ref.ref();
executed: d->ref.ref();
Execution Count:26898
26898
128}
executed: }
Execution Count:59734
59734
129 -
130/*! -
131 Creates a value of type Bool, with value \a b. -
132 */ -
133QJsonValue::QJsonValue(bool b) -
134 : d(0), t(Bool) -
135{ -
136 this->b = b;
executed (the execution status of this line is deduced): this->b = b;
-
137}
executed: }
Execution Count:38
38
138 -
139/*! -
140 Creates a value of type Double, with value \a n. -
141 */ -
142QJsonValue::QJsonValue(double n) -
143 : d(0), t(Double) -
144{ -
145 this->dbl = n;
executed (the execution status of this line is deduced): this->dbl = n;
-
146}
executed: }
Execution Count:101
101
147 -
148/*! -
149 \overload -
150 Creates a value of type Double, with value \a n. -
151 */ -
152QJsonValue::QJsonValue(int n) -
153 : d(0), t(Double) -
154{ -
155 this->dbl = n;
executed (the execution status of this line is deduced): this->dbl = n;
-
156}
executed: }
Execution Count:38
38
157 -
158/*! -
159 Creates a value of type String, with value \a s. -
160 */ -
161QJsonValue::QJsonValue(const QString &s) -
162 : d(0), t(String) -
163{ -
164 stringData = *(QStringData **)(&s);
executed (the execution status of this line is deduced): stringData = *(QStringData **)(&s);
-
165 stringData->ref.ref();
executed (the execution status of this line is deduced): stringData->ref.ref();
-
166}
executed: }
Execution Count:20
20
167 -
168/*! -
169 Creates a value of type String, with value \a s. -
170 */ -
171QJsonValue::QJsonValue(QLatin1String s) -
172 : d(0), t(String) -
173{ -
174 // ### FIXME: Avoid creating the temp QString below -
175 QString str(s);
executed (the execution status of this line is deduced): QString str(s);
-
176 stringData = *(QStringData **)(&str);
executed (the execution status of this line is deduced): stringData = *(QStringData **)(&str);
-
177 stringData->ref.ref();
executed (the execution status of this line is deduced): stringData->ref.ref();
-
178}
executed: }
Execution Count:150
150
179 -
180/*! -
181 Creates a value of type Array, with value \a a. -
182 */ -
183QJsonValue::QJsonValue(const QJsonArray &a) -
184 : d(a.d), t(Array) -
185{ -
186 base = a.a;
executed (the execution status of this line is deduced): base = a.a;
-
187 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:13
12-13
188 d->ref.ref();
executed: d->ref.ref();
Execution Count:12
12
189}
executed: }
Execution Count:25
25
190 -
191/*! -
192 Creates a value of type Object, with value \a o. -
193 */ -
194QJsonValue::QJsonValue(const QJsonObject &o) -
195 : d(o.d), t(Object) -
196{ -
197 base = o.o;
executed (the execution status of this line is deduced): base = o.o;
-
198 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:16
11-16
199 d->ref.ref();
executed: d->ref.ref();
Execution Count:11
11
200}
executed: }
Execution Count:27
27
201 -
202 -
203/*! -
204 Destroys the value. -
205 */ -
206QJsonValue::~QJsonValue() -
207{ -
208 if (t == String && stringData && !stringData->ref.deref())
evaluated: t == String
TRUEFALSE
yes
Evaluation Count:26974
yes
Evaluation Count:33425
partially evaluated: stringData
TRUEFALSE
yes
Evaluation Count:26974
no
Evaluation Count:0
evaluated: !stringData->ref.deref()
TRUEFALSE
yes
Evaluation Count:12659
yes
Evaluation Count:14315
0-33425
209 free(stringData);
executed: free(stringData);
Execution Count:12659
12659
210 -
211 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:26923
yes
Evaluation Count:33476
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:26917
6-33476
212 delete d;
executed: delete d;
Execution Count:6
6
213}
executed: }
Execution Count:60399
60399
214 -
215/*! -
216 Creates a copy of \a other. -
217 */ -
218QJsonValue::QJsonValue(const QJsonValue &other) -
219{ -
220 t = other.t;
executed (the execution status of this line is deduced): t = other.t;
-
221 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
222 ui = other.ui;
executed (the execution status of this line is deduced): ui = other.ui;
-
223 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
1-9
224 d->ref.ref();
executed: d->ref.ref();
Execution Count:1
1
225 -
226 if (t == String && stringData)
evaluated: t == String
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
partially evaluated: stringData
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-9
227 stringData->ref.ref();
executed: stringData->ref.ref();
Execution Count:1
1
228}
executed: }
Execution Count:10
10
229 -
230/*! -
231 Assigns the value stored in \a other to this object. -
232 */ -
233QJsonValue &QJsonValue::operator =(const QJsonValue &other) -
234{ -
235 if (t == String && stringData && !stringData->ref.deref())
evaluated: t == String
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:9
partially evaluated: stringData
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
partially evaluated: !stringData->ref.deref()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-9
236 free(stringData);
executed: free(stringData);
Execution Count:2
2
237 -
238 t = other.t;
executed (the execution status of this line is deduced): t = other.t;
-
239 dbl = other.dbl;
executed (the execution status of this line is deduced): dbl = other.dbl;
-
240 -
241 if (d != other.d) {
evaluated: d != other.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:9
2-9
242 -
243 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
partially evaluated: !d->ref.deref()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
244 delete d;
never executed: delete d;
0
245 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
246 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
247 d->ref.ref();
executed: d->ref.ref();
Execution Count:2
2
248 -
249 }
executed: }
Execution Count:2
2
250 -
251 if (t == String && stringData)
evaluated: t == String
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:9
partially evaluated: stringData
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-9
252 stringData->ref.ref();
executed: stringData->ref.ref();
Execution Count:2
2
253 -
254 return *this;
executed: return *this;
Execution Count:11
11
255} -
256 -
257/*! -
258 \fn bool QJsonValue::isNull() const -
259 -
260 Returns true if the value is null. -
261*/ -
262 -
263/*! -
264 \fn bool QJsonValue::isBool() const -
265 -
266 Returns true if the value contains a boolean. -
267 -
268 \sa toBool() -
269 */ -
270 -
271/*! -
272 \fn bool QJsonValue::isDouble() const -
273 -
274 Returns true if the value contains a double. -
275 -
276 \sa toDouble() -
277 */ -
278 -
279/*! -
280 \fn bool QJsonValue::isString() const -
281 -
282 Returns true if the value contains a string. -
283 -
284 \sa toString() -
285 */ -
286 -
287/*! -
288 \fn bool QJsonValue::isArray() const -
289 -
290 Returns true if the value contains an array. -
291 -
292 \sa toArray() -
293 */ -
294 -
295/*! -
296 \fn bool QJsonValue::isObject() const -
297 -
298 Returns true if the value contains an object. -
299 -
300 \sa toObject() -
301 */ -
302 -
303/*! -
304 \fn bool QJsonValue::isUndefined() const -
305 -
306 Returns true if the value is undefined. This can happen in certain -
307 error cases as e.g. accessing a non existing key in a QJsonObject. -
308 */ -
309 -
310 -
311/*! -
312 Converts \a variant to a QJsonValue and returns it. -
313 -
314 The conversion will convert QVariant types as follows: -
315 -
316 \list -
317 \li QVariant::Bool to Bool -
318 \li QVariant::Int -
319 \li QVariant::Double -
320 \li QVariant::LongLong -
321 \li QVariant::ULongLong -
322 \li QVariant::UInt to Double -
323 \li QVariant::String to String -
324 \li QVariant::StringList -
325 \li QVariant::VariantList to Array -
326 \li QVariant::VariantMap to Object -
327 \endlist -
328 -
329 For all other QVariant types a conversion to a QString will be attempted. If the returned string -
330 is empty, a Null QJsonValue will be stored, otherwise a String value using the returned QString. -
331 -
332 \sa toVariant() -
333 */ -
334QJsonValue QJsonValue::fromVariant(const QVariant &variant) -
335{ -
336 switch (variant.type()) { -
337 case QVariant::Bool: -
338 return QJsonValue(variant.toBool());
executed: return QJsonValue(variant.toBool());
Execution Count:1
1
339 case QVariant::Int: -
340 case QVariant::Double: -
341 case QVariant::LongLong: -
342 case QVariant::ULongLong: -
343 case QVariant::UInt: -
344 return QJsonValue(variant.toDouble());
executed: return QJsonValue(variant.toDouble());
Execution Count:1
1
345 case QVariant::String: -
346 return QJsonValue(variant.toString());
executed: return QJsonValue(variant.toString());
Execution Count:5
5
347 case QVariant::StringList: -
348 return QJsonValue(QJsonArray::fromStringList(variant.toStringList()));
never executed: return QJsonValue(QJsonArray::fromStringList(variant.toStringList()));
0
349 case QVariant::List: -
350 return QJsonValue(QJsonArray::fromVariantList(variant.toList()));
executed: return QJsonValue(QJsonArray::fromVariantList(variant.toList()));
Execution Count:1
1
351 case QVariant::Map: -
352 return QJsonValue(QJsonObject::fromVariantMap(variant.toMap()));
never executed: return QJsonValue(QJsonObject::fromVariantMap(variant.toMap()));
0
353 default: -
354 break;
executed: break;
Execution Count:1
1
355 } -
356 QString string = variant.toString();
executed (the execution status of this line is deduced): QString string = variant.toString();
-
357 if (string.isEmpty())
partially evaluated: string.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
358 return QJsonValue();
executed: return QJsonValue();
Execution Count:1
1
359 return QJsonValue(string);
never executed: return QJsonValue(string);
0
360} -
361 -
362/*! -
363 Converts the value to a QVariant. -
364 -
365 The QJsonValue types will be converted as follows: -
366 -
367 \value Null QVariant() -
368 \value Bool QVariant::Bool -
369 \value Double QVariant::Double -
370 \value String QVariant::String -
371 \value Array QVariantList -
372 \value Object QVariantMap -
373 \value Undefined QVariant() -
374 -
375 \sa fromVariant() -
376 */ -
377QVariant QJsonValue::toVariant() const -
378{ -
379 switch (t) { -
380 case Bool: -
381 return b;
executed: return b;
Execution Count:10
10
382 case Double: -
383 return dbl;
executed: return dbl;
Execution Count:1226
1226
384 case String: -
385 return toString();
executed: return toString();
Execution Count:944
944
386 case Array: -
387 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList();
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList();
Execution Count:100
100
388 case Object: -
389 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap();
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap();
Execution Count:866
866
390 case Null: -
391 case Undefined: -
392 break;
executed: break;
Execution Count:8
8
393 } -
394 return QVariant();
executed: return QVariant();
Execution Count:8
8
395} -
396 -
397/*! -
398 \enum QJsonValue::Type -
399 -
400 This enum describes the type of the JSON value. -
401 -
402 \value Null A Null value -
403 \value Bool A boolean value. Use toBool() to convert to a bool. -
404 \value Double A double. Use toDouble() to convert to a double. -
405 \value String A string. Use toString() to convert to a QString. -
406 \value Array An array. Use toArray() to convert to a QJsonArray. -
407 \value Object An object. Use toObject() to convert to a QJsonObject. -
408 \value Undefined The value is undefined. This is usually returned as an -
409 error condition, when trying to read an out of bounds value -
410 in an array or a non existent key in an object. -
411*/ -
412 -
413/*! -
414 Returns the type of the value. -
415 -
416 \sa QJsonValue::Type -
417 */ -
418QJsonValue::Type QJsonValue::type() const -
419{ -
420 return t;
executed: return t;
Execution Count:118
118
421} -
422 -
423/*! -
424 Converts the value to a bool and returns it. -
425 -
426 If type() is not bool, the \a defaultValue will be returned. -
427 */ -
428bool QJsonValue::toBool(bool defaultValue) const -
429{ -
430 if (t != Bool)
evaluated: t != Bool
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:241
4-241
431 return defaultValue;
executed: return defaultValue;
Execution Count:4
4
432 return b;
executed: return b;
Execution Count:241
241
433} -
434 -
435/*! -
436 Converts the value to a double and returns it. -
437 -
438 If type() is not Double, the \a defaultValue will be returned. -
439 */ -
440double QJsonValue::toDouble(double defaultValue) const -
441{ -
442 if (t != Double)
evaluated: t != Double
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:737
4-737
443 return defaultValue;
executed: return defaultValue;
Execution Count:4
4
444 return dbl;
executed: return dbl;
Execution Count:737
737
445} -
446 -
447/*! -
448 Converts the value to a QString and returns it. -
449 -
450 If type() is not String, the \a defaultValue will be returned. -
451 */ -
452QString QJsonValue::toString(const QString &defaultValue) const -
453{ -
454 if (t != String)
evaluated: t != String
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:27109
160-27109
455 return defaultValue;
executed: return defaultValue;
Execution Count:160
160
456 stringData->ref.ref(); // the constructor below doesn't add a ref.
executed (the execution status of this line is deduced): stringData->ref.ref();
-
457 QStringDataPtr holder = { stringData };
executed (the execution status of this line is deduced): QStringDataPtr holder = { stringData };
-
458 return QString(holder);
executed: return QString(holder);
Execution Count:27109
27109
459} -
460 -
461/*! -
462 Converts the value to an array and returns it. -
463 -
464 If type() is not Array, the \a defaultValue will be returned. -
465 */ -
466QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const -
467{ -
468 if (!d || t != Array)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:11547
partially evaluated: t != Array
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:11547
0-11547
469 return defaultValue;
executed: return defaultValue;
Execution Count:8
8
470 -
471 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base));
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base));
Execution Count:11547
11547
472} -
473 -
474/*! -
475 \overload -
476 -
477 Converts the value to an array and returns it. -
478 -
479 If type() is not Array, a QJsonArray() will be returned. -
480 */ -
481QJsonArray QJsonValue::toArray() const -
482{ -
483 return toArray(QJsonArray());
executed: return toArray(QJsonArray());
Execution Count:11554
11554
484} -
485 -
486/*! -
487 Converts the value to an object and returns it. -
488 -
489 If type() is not Object, the \a defaultValue will be returned. -
490 */ -
491QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const -
492{ -
493 if (!d || t != Object)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:11490
partially evaluated: t != Object
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:11490
0-11490
494 return defaultValue;
executed: return defaultValue;
Execution Count:7
7
495 -
496 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base));
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base));
Execution Count:11490
11490
497} -
498 -
499/*! -
500 \overload -
501 -
502 Converts the value to an object and returns it. -
503 -
504 If type() is not Object, the QJsonObject() will be returned. -
505 */ -
506QJsonObject QJsonValue::toObject() const -
507{ -
508 return toObject(QJsonObject());
executed: return toObject(QJsonObject());
Execution Count:11496
11496
509} -
510 -
511/*! -
512 Returns true if the value is equal to \a other. -
513 */ -
514bool QJsonValue::operator==(const QJsonValue &other) const -
515{ -
516 if (t != other.t)
evaluated: t != other.t
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:4796
27-4796
517 return false;
executed: return false;
Execution Count:27
27
518 -
519 switch (t) { -
520 case Undefined: -
521 case Null: -
522 break;
executed: break;
Execution Count:26
26
523 case Bool: -
524 return b == other.b;
executed: return b == other.b;
Execution Count:21
21
525 case Double: -
526 return dbl == other.dbl;
executed: return dbl == other.dbl;
Execution Count:1865
1865
527 case String: -
528 return toString() == other.toString();
executed: return toString() == other.toString();
Execution Count:1433
1433
529 case Array: -
530 if (base == other.base)
evaluated: base == other.base
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:149
1-149
531 return true;
executed: return true;
Execution Count:1
1
532 if (!base || !other.base)
evaluated: !base
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:148
partially evaluated: !other.base
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:148
0-148
533 return false;
executed: return false;
Execution Count:1
1
534 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base))
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)) == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.base));
Execution Count:148
148
535 == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.base));
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)) == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.base));
Execution Count:148
148
536 case Object: -
537 if (base == other.base)
evaluated: base == other.base
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1300
1-1300
538 return true;
executed: return true;
Execution Count:1
1
539 if (!base || !other.base)
evaluated: !base
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1299
partially evaluated: !other.base
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1299
0-1299
540 return false;
executed: return false;
Execution Count:1
1
541 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base))
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)) == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base));
Execution Count:1299
1299
542 == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base));
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)) == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base));
Execution Count:1299
1299
543 } -
544 return true;
executed: return true;
Execution Count:26
26
545} -
546 -
547/*! -
548 Returns true if the value is not equal to \a other. -
549 */ -
550bool QJsonValue::operator!=(const QJsonValue &other) const -
551{ -
552 return !(*this == other);
executed: return !(*this == other);
Execution Count:4775
4775
553} -
554 -
555/*! -
556 \internal -
557 */ -
558void QJsonValue::detach() -
559{ -
560 if (!d)
never evaluated: !d
0
561 return;
never executed: return;
0
562 -
563 QJsonPrivate::Data *x = d->clone(base);
never executed (the execution status of this line is deduced): QJsonPrivate::Data *x = d->clone(base);
-
564 x->ref.ref();
never executed (the execution status of this line is deduced): x->ref.ref();
-
565 if (!d->ref.deref())
never evaluated: !d->ref.deref()
0
566 delete d;
never executed: delete d;
0
567 d = x;
never executed (the execution status of this line is deduced): d = x;
-
568 base = static_cast<QJsonPrivate::Object *>(d->header->root());
never executed (the execution status of this line is deduced): base = static_cast<QJsonPrivate::Object *>(d->header->root());
-
569}
never executed: }
0
570 -
571 -
572/*! -
573 \class QJsonValueRef -
574 \inmodule QtCore -
575 \reentrant -
576 \brief The QJsonValueRef class is a helper class for QJsonValue. -
577 -
578 \internal -
579 -
580 \ingroup json -
581 -
582 When you get an object of type QJsonValueRef, if you can assign to it, -
583 the assignment will apply to the character in the string from -
584 which you got the reference. That is its whole purpose in life. -
585 -
586 You can use it exactly in the same way as a reference to a QJsonValue. -
587 -
588 The QJsonValueRef becomes invalid once modifications are made to the -
589 string: if you want to keep the character, copy it into a QJsonValue. -
590 -
591 Most of the QJsonValue member functions also exist in QJsonValueRef. -
592 However, they are not explicitly documented here. -
593*/ -
594 -
595 -
596QJsonValueRef &QJsonValueRef::operator =(const QJsonValue &val) -
597{ -
598 if (is_object)
evaluated: is_object
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:1
1-23
599 o->setValueAt(index, val);
executed: o->setValueAt(index, val);
Execution Count:23
23
600 else -
601 a->replace(index, val);
executed: a->replace(index, val);
Execution Count:1
1
602 -
603 return *this;
executed: return *this;
Execution Count:24
24
604} -
605 -
606QJsonValueRef &QJsonValueRef::operator =(const QJsonValueRef &ref) -
607{ -
608 if (is_object)
partially evaluated: is_object
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
609 o->setValueAt(index, ref);
never executed: o->setValueAt(index, ref);
0
610 else -
611 a->replace(index, ref);
executed: a->replace(index, ref);
Execution Count:2
2
612 -
613 return *this;
executed: return *this;
Execution Count:2
2
614} -
615 -
616QJsonArray QJsonValueRef::toArray() const -
617{ -
618 return toValue().toArray();
never executed: return toValue().toArray();
0
619} -
620 -
621QJsonObject QJsonValueRef::toObject() const -
622{ -
623 return toValue().toObject();
never executed: return toValue().toObject();
0
624} -
625 -
626QJsonValue QJsonValueRef::toValue() const -
627{ -
628 if (!is_object)
evaluated: !is_object
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:21
19-21
629 return a->at(index);
executed: return a->at(index);
Execution Count:19
19
630 return o->valueAt(index);
executed: return o->valueAt(index);
Execution Count:21
21
631} -
632 -
633#ifndef QT_NO_DEBUG_STREAM -
634QDebug operator<<(QDebug dbg, const QJsonValue &o) -
635{ -
636 switch (o.t) { -
637 case QJsonValue::Undefined: -
638 dbg.nospace() << "QJsonValue(undefined)";
never executed (the execution status of this line is deduced): dbg.nospace() << "QJsonValue(undefined)";
-
639 break;
never executed: break;
0
640 case QJsonValue::Null: -
641 dbg.nospace() << "QJsonValue(null)";
executed (the execution status of this line is deduced): dbg.nospace() << "QJsonValue(null)";
-
642 break;
executed: break;
Execution Count:2
2
643 case QJsonValue::Bool: -
644 dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ")";
executed (the execution status of this line is deduced): dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ")";
-
645 break;
executed: break;
Execution Count:1
1
646 case QJsonValue::Double: -
647 dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ")";
executed (the execution status of this line is deduced): dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ")";
-
648 break;
executed: break;
Execution Count:2
2
649 case QJsonValue::String: -
650 dbg.nospace() << "QJsonValue(string, " << o.toString() << ")";
executed (the execution status of this line is deduced): dbg.nospace() << "QJsonValue(string, " << o.toString() << ")";
-
651 break;
executed: break;
Execution Count:1
1
652 case QJsonValue::Array: -
653 dbg.nospace() << "QJsonValue(array, ";
executed (the execution status of this line is deduced): dbg.nospace() << "QJsonValue(array, ";
-
654 dbg.nospace() << o.toArray();
executed (the execution status of this line is deduced): dbg.nospace() << o.toArray();
-
655 dbg.nospace() << ")";
executed (the execution status of this line is deduced): dbg.nospace() << ")";
-
656 break;
executed: break;
Execution Count:1
1
657 case QJsonValue::Object: -
658 dbg.nospace() << "QJsonValue(object, ";
executed (the execution status of this line is deduced): dbg.nospace() << "QJsonValue(object, ";
-
659 dbg.nospace() << o.toObject();
executed (the execution status of this line is deduced): dbg.nospace() << o.toObject();
-
660 dbg.nospace() << ")";
executed (the execution status of this line is deduced): dbg.nospace() << ")";
-
661 break;
executed: break;
Execution Count:1
1
662 } -
663 return dbg.space();
executed: return dbg.space();
Execution Count:8
8
664} -
665#endif -
666 -
667QT_END_NAMESPACE -
668 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial