json/qjsonvalue.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4QJsonValue::QJsonValue(Type type) -
5 : ui(0), d(0), t(type) -
6{ -
7}
executed: }
Execution Count:256
256
8 -
9 -
10 -
11 -
12QJsonValue::QJsonValue(QJsonPrivate::Data *data, QJsonPrivate::Base *base, const QJsonPrivate::Value &v) -
13 : d(0) -
14{ -
15 t = (Type)(uint)v.type; -
16 switch (t) { -
17 case Undefined: -
18 case Null: -
19 dbl = 0; -
20 break;
executed: break;
Execution Count:30
30
21 case Bool: -
22 b = v.toBoolean(); -
23 break;
executed: break;
Execution Count:293
293
24 case Double: -
25 dbl = v.toDouble(base); -
26 break;
executed: break;
Execution Count:5710
5710
27 case String: { -
28 QString s = v.toString(base); -
29 stringData = s.data_ptr(); -
30 stringData->ref.ref(); -
31 break;
executed: break;
Execution Count:26803
26803
32 } -
33 case Array: -
34 case Object: -
35 d = data; -
36 this->base = v.base(base); -
37 break;
executed: break;
Execution Count:26898
26898
38 } -
39 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:26898
yes
Evaluation Count:32836
26898-32836
40 d->ref.ref();
executed: d->ref.ref();
Execution Count:26898
26898
41}
executed: }
Execution Count:59734
59734
42 -
43 -
44 -
45 -
46QJsonValue::QJsonValue(bool b) -
47 : d(0), t(Bool) -
48{ -
49 this->b = b; -
50}
executed: }
Execution Count:38
38
51 -
52 -
53 -
54 -
55QJsonValue::QJsonValue(double n) -
56 : d(0), t(Double) -
57{ -
58 this->dbl = n; -
59}
executed: }
Execution Count:101
101
60 -
61 -
62 -
63 -
64 -
65QJsonValue::QJsonValue(int n) -
66 : d(0), t(Double) -
67{ -
68 this->dbl = n; -
69}
executed: }
Execution Count:38
38
70 -
71 -
72 -
73 -
74QJsonValue::QJsonValue(const QString &s) -
75 : d(0), t(String) -
76{ -
77 stringData = *(QStringData **)(&s); -
78 stringData->ref.ref(); -
79}
executed: }
Execution Count:20
20
80 -
81 -
82 -
83 -
84QJsonValue::QJsonValue(QLatin1String s) -
85 : d(0), t(String) -
86{ -
87 -
88 QString str(s); -
89 stringData = *(QStringData **)(&str); -
90 stringData->ref.ref(); -
91}
executed: }
Execution Count:150
150
92 -
93 -
94 -
95 -
96QJsonValue::QJsonValue(const QJsonArray &a) -
97 : d(a.d), t(Array) -
98{ -
99 base = a.a; -
100 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:13
12-13
101 d->ref.ref();
executed: d->ref.ref();
Execution Count:12
12
102}
executed: }
Execution Count:25
25
103 -
104 -
105 -
106 -
107QJsonValue::QJsonValue(const QJsonObject &o) -
108 : d(o.d), t(Object) -
109{ -
110 base = o.o; -
111 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:16
11-16
112 d->ref.ref();
executed: d->ref.ref();
Execution Count:11
11
113}
executed: }
Execution Count:27
27
114 -
115 -
116 -
117 -
118 -
119QJsonValue::~QJsonValue() -
120{ -
121 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
122 free(stringData);
executed: free(stringData);
Execution Count:12659
12659
123 -
124 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
125 delete d;
executed: delete d;
Execution Count:6
6
126}
executed: }
Execution Count:60399
60399
127 -
128 -
129 -
130 -
131QJsonValue::QJsonValue(const QJsonValue &other) -
132{ -
133 t = other.t; -
134 d = other.d; -
135 ui = other.ui; -
136 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
1-9
137 d->ref.ref();
executed: d->ref.ref();
Execution Count:1
1
138 -
139 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
140 stringData->ref.ref();
executed: stringData->ref.ref();
Execution Count:1
1
141}
executed: }
Execution Count:10
10
142 -
143 -
144 -
145 -
146QJsonValue &QJsonValue::operator =(const QJsonValue &other) -
147{ -
148 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
149 free(stringData);
executed: free(stringData);
Execution Count:2
2
150 -
151 t = other.t; -
152 dbl = other.dbl; -
153 -
154 if (d != other.d) {
evaluated: d != other.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:9
2-9
155 -
156 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
157 delete d;
never executed: delete d;
0
158 d = other.d; -
159 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
160 d->ref.ref();
executed: d->ref.ref();
Execution Count:2
2
161 -
162 }
executed: }
Execution Count:2
2
163 -
164 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
165 stringData->ref.ref();
executed: stringData->ref.ref();
Execution Count:2
2
166 -
167 return *this;
executed: return *this;
Execution Count:11
11
168} -
169QJsonValue QJsonValue::fromVariant(const QVariant &variant) -
170{ -
171 switch (variant.type()) { -
172 case QVariant::Bool: -
173 return QJsonValue(variant.toBool());
executed: return QJsonValue(variant.toBool());
Execution Count:1
1
174 case QVariant::Int: -
175 case QVariant::Double: -
176 case QVariant::LongLong: -
177 case QVariant::ULongLong: -
178 case QVariant::UInt: -
179 return QJsonValue(variant.toDouble());
executed: return QJsonValue(variant.toDouble());
Execution Count:1
1
180 case QVariant::String: -
181 return QJsonValue(variant.toString());
executed: return QJsonValue(variant.toString());
Execution Count:5
5
182 case QVariant::StringList: -
183 return QJsonValue(QJsonArray::fromStringList(variant.toStringList()));
never executed: return QJsonValue(QJsonArray::fromStringList(variant.toStringList()));
0
184 case QVariant::List: -
185 return QJsonValue(QJsonArray::fromVariantList(variant.toList()));
executed: return QJsonValue(QJsonArray::fromVariantList(variant.toList()));
Execution Count:1
1
186 case QVariant::Map: -
187 return QJsonValue(QJsonObject::fromVariantMap(variant.toMap()));
never executed: return QJsonValue(QJsonObject::fromVariantMap(variant.toMap()));
0
188 default: -
189 break;
executed: break;
Execution Count:1
1
190 } -
191 QString string = variant.toString(); -
192 if (string.isEmpty())
partially evaluated: string.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
193 return QJsonValue();
executed: return QJsonValue();
Execution Count:1
1
194 return QJsonValue(string);
never executed: return QJsonValue(string);
0
195} -
196QVariant QJsonValue::toVariant() const -
197{ -
198 switch (t) { -
199 case Bool: -
200 return b;
executed: return b;
Execution Count:10
10
201 case Double: -
202 return dbl;
executed: return dbl;
Execution Count:1226
1226
203 case String: -
204 return toString();
executed: return toString();
Execution Count:944
944
205 case Array: -
206 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList();
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList();
Execution Count:100
100
207 case Object: -
208 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap();
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap();
Execution Count:866
866
209 case Null: -
210 case Undefined: -
211 break;
executed: break;
Execution Count:8
8
212 } -
213 return QVariant();
executed: return QVariant();
Execution Count:8
8
214} -
215QJsonValue::Type QJsonValue::type() const -
216{ -
217 return t;
executed: return t;
Execution Count:118
118
218} -
219 -
220 -
221 -
222 -
223 -
224 -
225bool QJsonValue::toBool(bool defaultValue) const -
226{ -
227 if (t != Bool)
evaluated: t != Bool
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:241
4-241
228 return defaultValue;
executed: return defaultValue;
Execution Count:4
4
229 return b;
executed: return b;
Execution Count:241
241
230} -
231 -
232 -
233 -
234 -
235 -
236 -
237double QJsonValue::toDouble(double defaultValue) const -
238{ -
239 if (t != Double)
evaluated: t != Double
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:737
4-737
240 return defaultValue;
executed: return defaultValue;
Execution Count:4
4
241 return dbl;
executed: return dbl;
Execution Count:737
737
242} -
243 -
244 -
245 -
246 -
247 -
248 -
249QString QJsonValue::toString(const QString &defaultValue) const -
250{ -
251 if (t != String)
evaluated: t != String
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:27109
160-27109
252 return defaultValue;
executed: return defaultValue;
Execution Count:160
160
253 stringData->ref.ref(); -
254 QStringDataPtr holder = { stringData }; -
255 return QString(holder);
executed: return QString(holder);
Execution Count:27109
27109
256} -
257 -
258 -
259 -
260 -
261 -
262 -
263QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const -
264{ -
265 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
266 return defaultValue;
executed: return defaultValue;
Execution Count:8
8
267 -
268 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base));
executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base));
Execution Count:11547
11547
269} -
270QJsonArray QJsonValue::toArray() const -
271{ -
272 return toArray(QJsonArray());
executed: return toArray(QJsonArray());
Execution Count:11554
11554
273} -
274 -
275 -
276 -
277 -
278 -
279 -
280QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const -
281{ -
282 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
283 return defaultValue;
executed: return defaultValue;
Execution Count:7
7
284 -
285 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base));
executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base));
Execution Count:11490
11490
286} -
287QJsonObject QJsonValue::toObject() const -
288{ -
289 return toObject(QJsonObject());
executed: return toObject(QJsonObject());
Execution Count:11496
11496
290} -
291 -
292 -
293 -
294 -
295bool QJsonValue::operator==(const QJsonValue &other) const -
296{ -
297 if (t != other.t)
evaluated: t != other.t
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:4796
27-4796
298 return false;
executed: return false;
Execution Count:27
27
299 -
300 switch (t) { -
301 case Undefined: -
302 case Null: -
303 break;
executed: break;
Execution Count:26
26
304 case Bool: -
305 return b == other.b;
executed: return b == other.b;
Execution Count:21
21
306 case Double: -
307 return dbl == other.dbl;
executed: return dbl == other.dbl;
Execution Count:1865
1865
308 case String: -
309 return toString() == other.toString();
executed: return toString() == other.toString();
Execution Count:1433
1433
310 case Array: -
311 if (base == other.base)
evaluated: base == other.base
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:149
1-149
312 return true;
executed: return true;
Execution Count:1
1
313 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
314 return false;
executed: return false;
Execution Count:1
1
315 return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)) 148
316 == 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
317 case Object: -
318 if (base == other.base)
evaluated: base == other.base
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1300
1-1300
319 return true;
executed: return true;
Execution Count:1
1
320 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
321 return false;
executed: return false;
Execution Count:1
1
322 return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)) 1299
323 == 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
324 } -
325 return true;
executed: return true;
Execution Count:26
26
326} -
327 -
328 -
329 -
330 -
331bool QJsonValue::operator!=(const QJsonValue &other) const -
332{ -
333 return !(*this == other);
executed: return !(*this == other);
Execution Count:4775
4775
334} -
335 -
336 -
337 -
338 -
339void QJsonValue::detach() -
340{ -
341 if (!d)
never evaluated: !d
0
342 return;
never executed: return;
0
343 -
344 QJsonPrivate::Data *x = d->clone(base); -
345 x->ref.ref(); -
346 if (!d->ref.deref())
never evaluated: !d->ref.deref()
0
347 delete d;
never executed: delete d;
0
348 d = x; -
349 base = static_cast<QJsonPrivate::Object *>(d->header->root()); -
350}
never executed: }
0
351QJsonValueRef &QJsonValueRef::operator =(const QJsonValue &val) -
352{ -
353 if (is_object)
evaluated: is_object
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:1
1-23
354 o->setValueAt(index, val);
executed: o->setValueAt(index, val);
Execution Count:23
23
355 else -
356 a->replace(index, val);
executed: a->replace(index, val);
Execution Count:1
1
357 -
358 return *this;
executed: return *this;
Execution Count:24
24
359} -
360 -
361QJsonValueRef &QJsonValueRef::operator =(const QJsonValueRef &ref) -
362{ -
363 if (is_object)
partially evaluated: is_object
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
364 o->setValueAt(index, ref);
never executed: o->setValueAt(index, ref);
0
365 else -
366 a->replace(index, ref);
executed: a->replace(index, ref);
Execution Count:2
2
367 -
368 return *this;
executed: return *this;
Execution Count:2
2
369} -
370 -
371QJsonArray QJsonValueRef::toArray() const -
372{ -
373 return toValue().toArray();
never executed: return toValue().toArray();
0
374} -
375 -
376QJsonObject QJsonValueRef::toObject() const -
377{ -
378 return toValue().toObject();
never executed: return toValue().toObject();
0
379} -
380 -
381QJsonValue QJsonValueRef::toValue() const -
382{ -
383 if (!is_object)
evaluated: !is_object
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:21
19-21
384 return a->at(index);
executed: return a->at(index);
Execution Count:19
19
385 return o->valueAt(index);
executed: return o->valueAt(index);
Execution Count:21
21
386} -
387 -
388 -
389QDebug operator<<(QDebug dbg, const QJsonValue &o) -
390{ -
391 switch (o.t) { -
392 case QJsonValue::Undefined: -
393 dbg.nospace() << "QJsonValue(undefined)"; -
394 break;
never executed: break;
0
395 case QJsonValue::Null: -
396 dbg.nospace() << "QJsonValue(null)"; -
397 break;
executed: break;
Execution Count:2
2
398 case QJsonValue::Bool: -
399 dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ")"; -
400 break;
executed: break;
Execution Count:1
1
401 case QJsonValue::Double: -
402 dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ")"; -
403 break;
executed: break;
Execution Count:2
2
404 case QJsonValue::String: -
405 dbg.nospace() << "QJsonValue(string, " << o.toString() << ")"; -
406 break;
executed: break;
Execution Count:1
1
407 case QJsonValue::Array: -
408 dbg.nospace() << "QJsonValue(array, "; -
409 dbg.nospace() << o.toArray(); -
410 dbg.nospace() << ")"; -
411 break;
executed: break;
Execution Count:1
1
412 case QJsonValue::Object: -
413 dbg.nospace() << "QJsonValue(object, "; -
414 dbg.nospace() << o.toObject(); -
415 dbg.nospace() << ")"; -
416 break;
executed: break;
Execution Count:1
1
417 } -
418 return dbg.space();
executed: return dbg.space();
Execution Count:8
8
419} -
420 -
421 -
422 -
423 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial