| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/json/qjsonobject.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | QJsonObject::QJsonObject() | - | ||||||||||||||||||
| 4 | : d(0), o(0) | - | ||||||||||||||||||
| 5 | { | - | ||||||||||||||||||
| 6 | } executed 43570 times by 142 tests: end of blockExecuted by:
| 43570 | ||||||||||||||||||
| 7 | QJsonObject::QJsonObject(QJsonPrivate::Data *data, QJsonPrivate::Object *object) | - | ||||||||||||||||||
| 8 | : d(data), o(object) | - | ||||||||||||||||||
| 9 | { | - | ||||||||||||||||||
| 10 | ((!(d)) ? qt_assert("d",__FILE__,137) : qt_noop()); | - | ||||||||||||||||||
| 11 | ((!(o)) ? qt_assert("o",__FILE__,138) : qt_noop()); | - | ||||||||||||||||||
| 12 | d->ref.ref(); | - | ||||||||||||||||||
| 13 | } executed 42729 times by 117 tests: end of blockExecuted by:
| 42729 | ||||||||||||||||||
| 14 | void QJsonObject::initialize() | - | ||||||||||||||||||
| 15 | { | - | ||||||||||||||||||
| 16 | d = 0; | - | ||||||||||||||||||
| 17 | o = 0; | - | ||||||||||||||||||
| 18 | } never executed: end of block | 0 | ||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | - | |||||||||||||||||||
| 23 | QJsonObject::~QJsonObject() | - | ||||||||||||||||||
| 24 | { | - | ||||||||||||||||||
| 25 | if (d
| 2835-86679 | ||||||||||||||||||
| 26 | delete d; executed 2835 times by 248 tests: delete d;Executed by:
| 2835 | ||||||||||||||||||
| 27 | } executed 129478 times by 362 tests: end of blockExecuted by:
| 129478 | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | - | |||||||||||||||||||
| 32 | - | |||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | QJsonObject::QJsonObject(const QJsonObject &other) | - | ||||||||||||||||||
| 36 | { | - | ||||||||||||||||||
| 37 | d = other.d; | - | ||||||||||||||||||
| 38 | o = other.o; | - | ||||||||||||||||||
| 39 | if (d
| 3-41141 | ||||||||||||||||||
| 40 | d->ref.ref(); executed 41141 times by 112 tests: d->ref.ref();Executed by:
| 41141 | ||||||||||||||||||
| 41 | } executed 41144 times by 113 tests: end of blockExecuted by:
| 41144 | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | QJsonObject &QJsonObject::operator =(const QJsonObject &other) | - | ||||||||||||||||||
| 47 | { | - | ||||||||||||||||||
| 48 | if (d != other.d
| 1-678 | ||||||||||||||||||
| 49 | if (d
| 0-678 | ||||||||||||||||||
| 50 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
| 51 | d = other.d; | - | ||||||||||||||||||
| 52 | if (d
| 0-678 | ||||||||||||||||||
| 53 | d->ref.ref(); executed 678 times by 111 tests: d->ref.ref();Executed by:
| 678 | ||||||||||||||||||
| 54 | } executed 678 times by 111 tests: end of blockExecuted by:
| 678 | ||||||||||||||||||
| 55 | o = other.o; | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | return executed 679 times by 112 tests: *this;return *this;Executed by:
executed 679 times by 112 tests: return *this;Executed by:
| 679 | ||||||||||||||||||
| 58 | } | - | ||||||||||||||||||
| 59 | QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map) | - | ||||||||||||||||||
| 60 | { | - | ||||||||||||||||||
| 61 | QJsonObject object; | - | ||||||||||||||||||
| 62 | if (map.isEmpty()
| 0 | ||||||||||||||||||
| 63 | return never executed: object;return object;never executed: return object; | 0 | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | object.detach2(1024); | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | QVector<QJsonPrivate::offset> offsets; | - | ||||||||||||||||||
| 68 | QJsonPrivate::offset currentOffset; | - | ||||||||||||||||||
| 69 | currentOffset = sizeof(QJsonPrivate::Base); | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | for (QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd()
| 0 | ||||||||||||||||||
| 74 | QString key = it.key(); | - | ||||||||||||||||||
| 75 | QJsonValue val = QJsonValue::fromVariant(it.value()); | - | ||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | bool latinOrIntValue; | - | ||||||||||||||||||
| 78 | int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue); | - | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | bool latinKey = QJsonPrivate::useCompressed(key); | - | ||||||||||||||||||
| 81 | int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey); | - | ||||||||||||||||||
| 82 | int requiredSize = valueOffset + valueSize; | - | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | if (!object.detach2(requiredSize + sizeof(QJsonPrivate::offset))
| 0 | ||||||||||||||||||
| 85 | return never executed: QJsonObject();return QJsonObject();never executed: return QJsonObject(); | 0 | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | QJsonPrivate::Entry *e = reinterpret_cast<QJsonPrivate::Entry *>(reinterpret_cast<char *>(object.o) + currentOffset); | - | ||||||||||||||||||
| 88 | e->value.type = val.t; | - | ||||||||||||||||||
| 89 | e->value.latinKey = latinKey; | - | ||||||||||||||||||
| 90 | e->value.latinOrIntValue = latinOrIntValue; | - | ||||||||||||||||||
| 91 | e->value.value = QJsonPrivate::Value::valueToStore(val, (char *)e - (char *)object.o + valueOffset); | - | ||||||||||||||||||
| 92 | QJsonPrivate::copyString((char *)(e + 1), key, latinKey); | - | ||||||||||||||||||
| 93 | if (valueSize
| 0 | ||||||||||||||||||
| 94 | QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue); never executed: QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue); | 0 | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | offsets << currentOffset; | - | ||||||||||||||||||
| 97 | currentOffset += requiredSize; | - | ||||||||||||||||||
| 98 | object.o->size = currentOffset; | - | ||||||||||||||||||
| 99 | } never executed: end of block | 0 | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | object.o->tableOffset = currentOffset; | - | ||||||||||||||||||
| 103 | if (!object.detach2(sizeof(QJsonPrivate::offset)*offsets.size())
| 0 | ||||||||||||||||||
| 104 | return never executed: QJsonObject();return QJsonObject();never executed: return QJsonObject(); | 0 | ||||||||||||||||||
| 105 | memcpy(object.o->table(), offsets.constData(), offsets.size()*sizeof(uint)); | - | ||||||||||||||||||
| 106 | object.o->length = offsets.size(); | - | ||||||||||||||||||
| 107 | object.o->size = currentOffset + sizeof(QJsonPrivate::offset)*offsets.size(); | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | return never executed: object;return object;never executed: return object; | 0 | ||||||||||||||||||
| 110 | } | - | ||||||||||||||||||
| 111 | QVariantMap QJsonObject::toVariantMap() const | - | ||||||||||||||||||
| 112 | { | - | ||||||||||||||||||
| 113 | QVariantMap map; | - | ||||||||||||||||||
| 114 | if (o
| 0 | ||||||||||||||||||
| 115 | for (uint i = 0; i < o->length
| 0 | ||||||||||||||||||
| 116 | QJsonPrivate::Entry *e = o->entryAt(i); | - | ||||||||||||||||||
| 117 | map.insert(e->key(), QJsonValue(d, o, e->value).toVariant()); | - | ||||||||||||||||||
| 118 | } never executed: end of block | 0 | ||||||||||||||||||
| 119 | } never executed: end of block | 0 | ||||||||||||||||||
| 120 | return never executed: map;return map;never executed: return map; | 0 | ||||||||||||||||||
| 121 | } | - | ||||||||||||||||||
| 122 | QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash) | - | ||||||||||||||||||
| 123 | { | - | ||||||||||||||||||
| 124 | - | |||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | QJsonObject object; | - | ||||||||||||||||||
| 127 | for (QVariantHash::const_iterator it = hash.constBegin(); it != hash.constEnd()
| 0 | ||||||||||||||||||
| 128 | object.insert(it.key(), QJsonValue::fromVariant(it.value())); never executed: object.insert(it.key(), QJsonValue::fromVariant(it.value())); | 0 | ||||||||||||||||||
| 129 | return never executed: object;return object;never executed: return object; | 0 | ||||||||||||||||||
| 130 | } | - | ||||||||||||||||||
| 131 | QVariantHash QJsonObject::toVariantHash() const | - | ||||||||||||||||||
| 132 | { | - | ||||||||||||||||||
| 133 | QVariantHash hash; | - | ||||||||||||||||||
| 134 | if (o
| 0 | ||||||||||||||||||
| 135 | hash.reserve(o->length); | - | ||||||||||||||||||
| 136 | for (uint i = 0; i < o->length
| 0 | ||||||||||||||||||
| 137 | QJsonPrivate::Entry *e = o->entryAt(i); | - | ||||||||||||||||||
| 138 | hash.insert(e->key(), QJsonValue(d, o, e->value).toVariant()); | - | ||||||||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||||||||
| 140 | } never executed: end of block | 0 | ||||||||||||||||||
| 141 | return never executed: hash;return hash;never executed: return hash; | 0 | ||||||||||||||||||
| 142 | } | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | QStringList QJsonObject::keys() const | - | ||||||||||||||||||
| 150 | { | - | ||||||||||||||||||
| 151 | QStringList keys; | - | ||||||||||||||||||
| 152 | if (o
| 0 | ||||||||||||||||||
| 153 | keys.reserve(o->length); | - | ||||||||||||||||||
| 154 | for (uint i = 0; i < o->length
| 0 | ||||||||||||||||||
| 155 | QJsonPrivate::Entry *e = o->entryAt(i); | - | ||||||||||||||||||
| 156 | keys.append(e->key()); | - | ||||||||||||||||||
| 157 | } never executed: end of block | 0 | ||||||||||||||||||
| 158 | } never executed: end of block | 0 | ||||||||||||||||||
| 159 | return never executed: keys;return keys;never executed: return keys; | 0 | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | int QJsonObject::size() const | - | ||||||||||||||||||
| 166 | { | - | ||||||||||||||||||
| 167 | if (!d
| 0-4 | ||||||||||||||||||
| 168 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | return executed 4 times by 1 test: o->length;return o->length;Executed by:
executed 4 times by 1 test: return o->length;Executed by:
| 4 | ||||||||||||||||||
| 171 | } | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | bool QJsonObject::isEmpty() const | - | ||||||||||||||||||
| 179 | { | - | ||||||||||||||||||
| 180 | if (!d
| 0 | ||||||||||||||||||
| 181 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | return never executed: !o->length;return !o->length;never executed: return !o->length; | 0 | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | QJsonValue QJsonObject::value(const QString &key) const | - | ||||||||||||||||||
| 186 | { | - | ||||||||||||||||||
| 187 | if (!d
| 0-1180 | ||||||||||||||||||
| 188 | return never executed: QJsonValue(QJsonValue::Undefined);return QJsonValue(QJsonValue::Undefined);never executed: return QJsonValue(QJsonValue::Undefined); | 0 | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | bool keyExists; | - | ||||||||||||||||||
| 191 | int i = o->indexOf(key, &keyExists); | - | ||||||||||||||||||
| 192 | if (!keyExists
| 155-1025 | ||||||||||||||||||
| 193 | return executed 155 times by 1 test: QJsonValue(QJsonValue::Undefined);return QJsonValue(QJsonValue::Undefined);Executed by:
executed 155 times by 1 test: return QJsonValue(QJsonValue::Undefined);Executed by:
| 155 | ||||||||||||||||||
| 194 | return executed 1025 times by 1 test: QJsonValue(d, o, o->entryAt(i)->value);return QJsonValue(d, o, o->entryAt(i)->value);Executed by:
executed 1025 times by 1 test: return QJsonValue(d, o, o->entryAt(i)->value);Executed by:
| 1025 | ||||||||||||||||||
| 195 | } | - | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | QJsonValue QJsonObject::value(QLatin1String key) const | - | ||||||||||||||||||
| 202 | { | - | ||||||||||||||||||
| 203 | if (!d
| 0-86427 | ||||||||||||||||||
| 204 | return never executed: QJsonValue(QJsonValue::Undefined);return QJsonValue(QJsonValue::Undefined);never executed: return QJsonValue(QJsonValue::Undefined); | 0 | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | bool keyExists; | - | ||||||||||||||||||
| 207 | int i = o->indexOf(key, &keyExists); | - | ||||||||||||||||||
| 208 | if (!keyExists
| 147-86280 | ||||||||||||||||||
| 209 | return executed 147 times by 2 tests: QJsonValue(QJsonValue::Undefined);return QJsonValue(QJsonValue::Undefined);Executed by:
executed 147 times by 2 tests: return QJsonValue(QJsonValue::Undefined);Executed by:
| 147 | ||||||||||||||||||
| 210 | return executed 86280 times by 115 tests: QJsonValue(d, o, o->entryAt(i)->value);return QJsonValue(d, o, o->entryAt(i)->value);Executed by:
executed 86280 times by 115 tests: return QJsonValue(d, o, o->entryAt(i)->value);Executed by:
| 86280 | ||||||||||||||||||
| 211 | } | - | ||||||||||||||||||
| 212 | QJsonValue QJsonObject::operator [](const QString &key) const | - | ||||||||||||||||||
| 213 | { | - | ||||||||||||||||||
| 214 | return never executed: value(key);return value(key);never executed: return value(key); | 0 | ||||||||||||||||||
| 215 | } | - | ||||||||||||||||||
| 216 | QJsonValueRef QJsonObject::operator [](const QString &key) | - | ||||||||||||||||||
| 217 | { | - | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | bool keyExists = false; | - | ||||||||||||||||||
| 220 | int index = o
| 0 | ||||||||||||||||||
| 221 | if (!keyExists
| 0 | ||||||||||||||||||
| 222 | iterator i = insert(key, QJsonValue()); | - | ||||||||||||||||||
| 223 | index = i.i; | - | ||||||||||||||||||
| 224 | } never executed: end of block | 0 | ||||||||||||||||||
| 225 | return never executed: QJsonValueRef(this, index);return QJsonValueRef(this, index);never executed: return QJsonValueRef(this, index); | 0 | ||||||||||||||||||
| 226 | } | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | QJsonValueRef QJsonObject::operator [](QLatin1String key) | - | ||||||||||||||||||
| 233 | { | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | return never executed: operator[](QString(key));return operator[](QString(key));never executed: return operator[](QString(key)); | 0 | ||||||||||||||||||
| 236 | } | - | ||||||||||||||||||
| 237 | QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value) | - | ||||||||||||||||||
| 238 | { | - | ||||||||||||||||||
| 239 | if (value.t == QJsonValue::Undefined
| 0-8 | ||||||||||||||||||
| 240 | remove(key); | - | ||||||||||||||||||
| 241 | return never executed: end();return end();never executed: return end(); | 0 | ||||||||||||||||||
| 242 | } | - | ||||||||||||||||||
| 243 | QJsonValue val = value; | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | bool latinOrIntValue; | - | ||||||||||||||||||
| 246 | int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue); | - | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | bool latinKey = QJsonPrivate::useCompressed(key); | - | ||||||||||||||||||
| 249 | int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey); | - | ||||||||||||||||||
| 250 | int requiredSize = valueOffset + valueSize; | - | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | if (!detach2(requiredSize + sizeof(QJsonPrivate::offset))
| 0-8 | ||||||||||||||||||
| 253 | return never executed: iterator();return iterator();never executed: return iterator(); | 0 | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | if (!o->length
| 2-6 | ||||||||||||||||||
| 256 | o->tableOffset = sizeof(QJsonPrivate::Object); executed 2 times by 1 test: o->tableOffset = sizeof(QJsonPrivate::Object);Executed by:
| 2 | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | bool keyExists = false; | - | ||||||||||||||||||
| 259 | int pos = o->indexOf(key, &keyExists); | - | ||||||||||||||||||
| 260 | if (keyExists
| 0-8 | ||||||||||||||||||
| 261 | ++ never executed: d->compactionCounter;++d->compactionCounter;never executed: ++d->compactionCounter; | 0 | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | uint off = o->reserveSpace(requiredSize, pos, 1, keyExists); | - | ||||||||||||||||||
| 264 | if (!off
| 0-8 | ||||||||||||||||||
| 265 | return never executed: end();return end();never executed: return end(); | 0 | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | QJsonPrivate::Entry *e = o->entryAt(pos); | - | ||||||||||||||||||
| 268 | e->value.type = val.t; | - | ||||||||||||||||||
| 269 | e->value.latinKey = latinKey; | - | ||||||||||||||||||
| 270 | e->value.latinOrIntValue = latinOrIntValue; | - | ||||||||||||||||||
| 271 | e->value.value = QJsonPrivate::Value::valueToStore(val, (char *)e - (char *)o + valueOffset); | - | ||||||||||||||||||
| 272 | QJsonPrivate::copyString((char *)(e + 1), key, latinKey); | - | ||||||||||||||||||
| 273 | if (valueSize
| 2-6 | ||||||||||||||||||
| 274 | QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue); executed 2 times by 1 test: QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);Executed by:
| 2 | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | if (d->compactionCounter > 32u
| 0-8 | ||||||||||||||||||
| 277 | compact(); never executed: compact(); | 0 | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | return executed 8 times by 1 test: iterator(this, pos);return iterator(this, pos);Executed by:
executed 8 times by 1 test: return iterator(this, pos);Executed by:
| 8 | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | void QJsonObject::remove(const QString &key) | - | ||||||||||||||||||
| 288 | { | - | ||||||||||||||||||
| 289 | if (!d
| 0 | ||||||||||||||||||
| 290 | return; never executed: return; | 0 | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | bool keyExists; | - | ||||||||||||||||||
| 293 | int index = o->indexOf(key, &keyExists); | - | ||||||||||||||||||
| 294 | if (!keyExists
| 0 | ||||||||||||||||||
| 295 | return; never executed: return; | 0 | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | detach2(); | - | ||||||||||||||||||
| 298 | o->removeItems(index, 1); | - | ||||||||||||||||||
| 299 | ++d->compactionCounter; | - | ||||||||||||||||||
| 300 | if (d->compactionCounter > 32u
| 0 | ||||||||||||||||||
| 301 | compact(); never executed: compact(); | 0 | ||||||||||||||||||
| 302 | } never executed: end of block | 0 | ||||||||||||||||||
| 303 | QJsonValue QJsonObject::take(const QString &key) | - | ||||||||||||||||||
| 304 | { | - | ||||||||||||||||||
| 305 | if (!o
| 0 | ||||||||||||||||||
| 306 | return never executed: QJsonValue(QJsonValue::Undefined);return QJsonValue(QJsonValue::Undefined);never executed: return QJsonValue(QJsonValue::Undefined); | 0 | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | bool keyExists; | - | ||||||||||||||||||
| 309 | int index = o->indexOf(key, &keyExists); | - | ||||||||||||||||||
| 310 | if (!keyExists
| 0 | ||||||||||||||||||
| 311 | return never executed: QJsonValue(QJsonValue::Undefined);return QJsonValue(QJsonValue::Undefined);never executed: return QJsonValue(QJsonValue::Undefined); | 0 | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | QJsonValue v(d, o, o->entryAt(index)->value); | - | ||||||||||||||||||
| 314 | detach2(); | - | ||||||||||||||||||
| 315 | o->removeItems(index, 1); | - | ||||||||||||||||||
| 316 | ++d->compactionCounter; | - | ||||||||||||||||||
| 317 | if (d->compactionCounter > 32u
| 0 | ||||||||||||||||||
| 318 | compact(); never executed: compact(); | 0 | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | return never executed: v;return v;never executed: return v; | 0 | ||||||||||||||||||
| 321 | } | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | bool QJsonObject::contains(const QString &key) const | - | ||||||||||||||||||
| 329 | { | - | ||||||||||||||||||
| 330 | if (!o
| 0 | ||||||||||||||||||
| 331 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | bool keyExists; | - | ||||||||||||||||||
| 334 | o->indexOf(key, &keyExists); | - | ||||||||||||||||||
| 335 | return never executed: keyExists;return keyExists;never executed: return keyExists; | 0 | ||||||||||||||||||
| 336 | } | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | bool QJsonObject::contains(QLatin1String key) const | - | ||||||||||||||||||
| 343 | { | - | ||||||||||||||||||
| 344 | if (!o
| 0-12 | ||||||||||||||||||
| 345 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 346 | - | |||||||||||||||||||
| 347 | bool keyExists; | - | ||||||||||||||||||
| 348 | o->indexOf(key, &keyExists); | - | ||||||||||||||||||
| 349 | return executed 12 times by 1 test: keyExists;return keyExists;Executed by:
executed 12 times by 1 test: return keyExists;Executed by:
| 12 | ||||||||||||||||||
| 350 | } | - | ||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | bool QJsonObject::operator==(const QJsonObject &other) const | - | ||||||||||||||||||
| 356 | { | - | ||||||||||||||||||
| 357 | if (o == other.o
| 0-8 | ||||||||||||||||||
| 358 | return executed 8 times by 1 test: true;return true;Executed by:
executed 8 times by 1 test: return true;Executed by:
| 8 | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | if (!o
| 0 | ||||||||||||||||||
| 361 | return never executed: !other.o->length;return !other.o->length;never executed: return !other.o->length; | 0 | ||||||||||||||||||
| 362 | if (!other.o
| 0 | ||||||||||||||||||
| 363 | return never executed: !o->length;return !o->length;never executed: return !o->length; | 0 | ||||||||||||||||||
| 364 | if (o->length != other.o->length
| 0 | ||||||||||||||||||
| 365 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | for (uint i = 0; i < o->length
| 0 | ||||||||||||||||||
| 368 | QJsonPrivate::Entry *e = o->entryAt(i); | - | ||||||||||||||||||
| 369 | QJsonValue v(d, o, e->value); | - | ||||||||||||||||||
| 370 | if (other.value(e->key()) != v
| 0 | ||||||||||||||||||
| 371 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 372 | } never executed: end of block | 0 | ||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 375 | } | - | ||||||||||||||||||
| 376 | - | |||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | bool QJsonObject::operator!=(const QJsonObject &other) const | - | ||||||||||||||||||
| 381 | { | - | ||||||||||||||||||
| 382 | return never executed: !(*this == other);return !(*this == other);never executed: return !(*this == other); | 0 | ||||||||||||||||||
| 383 | } | - | ||||||||||||||||||
| 384 | QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it) | - | ||||||||||||||||||
| 385 | { | - | ||||||||||||||||||
| 386 | ((!(d && d->ref.load() == 1)) ? qt_assert("d && d->ref.load() == 1",__FILE__,627) : qt_noop()); | - | ||||||||||||||||||
| 387 | if (it.o != this
| 0 | ||||||||||||||||||
| 388 | return never executed: iterator(this, o->length);return iterator(this, o->length);never executed: return iterator(this, o->length); | 0 | ||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | int index = it.i; | - | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | o->removeItems(index, 1); | - | ||||||||||||||||||
| 393 | ++d->compactionCounter; | - | ||||||||||||||||||
| 394 | if (d->compactionCounter > 32u
| 0 | ||||||||||||||||||
| 395 | compact(); never executed: compact(); | 0 | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | return never executed: it;return it;never executed: return it; | 0 | ||||||||||||||||||
| 399 | } | - | ||||||||||||||||||
| 400 | QJsonObject::iterator QJsonObject::find(const QString &key) | - | ||||||||||||||||||
| 401 | { | - | ||||||||||||||||||
| 402 | bool keyExists = false; | - | ||||||||||||||||||
| 403 | int index = o
| 0 | ||||||||||||||||||
| 404 | if (!keyExists
| 0 | ||||||||||||||||||
| 405 | return never executed: end();return end();never executed: return end(); | 0 | ||||||||||||||||||
| 406 | detach2(); | - | ||||||||||||||||||
| 407 | return never executed: iterator(this, index);return iterator(this, index);never executed: return iterator(this, index); | 0 | ||||||||||||||||||
| 408 | } | - | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | - | |||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | - | |||||||||||||||||||
| 414 | QJsonObject::iterator QJsonObject::find(QLatin1String key) | - | ||||||||||||||||||
| 415 | { | - | ||||||||||||||||||
| 416 | bool keyExists = false; | - | ||||||||||||||||||
| 417 | int index = o
| 0 | ||||||||||||||||||
| 418 | if (!keyExists
| 0 | ||||||||||||||||||
| 419 | return never executed: end();return end();never executed: return end(); | 0 | ||||||||||||||||||
| 420 | detach2(); | - | ||||||||||||||||||
| 421 | return never executed: iterator(this, index);return iterator(this, index);never executed: return iterator(this, index); | 0 | ||||||||||||||||||
| 422 | } | - | ||||||||||||||||||
| 423 | QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const | - | ||||||||||||||||||
| 424 | { | - | ||||||||||||||||||
| 425 | bool keyExists = false; | - | ||||||||||||||||||
| 426 | int index = o
| 0 | ||||||||||||||||||
| 427 | if (!keyExists
| 0 | ||||||||||||||||||
| 428 | return never executed: end();return end();never executed: return end(); | 0 | ||||||||||||||||||
| 429 | return never executed: const_iterator(this, index);return const_iterator(this, index);never executed: return const_iterator(this, index); | 0 | ||||||||||||||||||
| 430 | } | - | ||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | - | |||||||||||||||||||
| 436 | QJsonObject::const_iterator QJsonObject::constFind(QLatin1String key) const | - | ||||||||||||||||||
| 437 | { | - | ||||||||||||||||||
| 438 | bool keyExists = false; | - | ||||||||||||||||||
| 439 | int index = o
| 0 | ||||||||||||||||||
| 440 | if (!keyExists
| 0 | ||||||||||||||||||
| 441 | return never executed: end();return end();never executed: return end(); | 0 | ||||||||||||||||||
| 442 | return never executed: const_iterator(this, index);return const_iterator(this, index);never executed: return const_iterator(this, index); | 0 | ||||||||||||||||||
| 443 | } | - | ||||||||||||||||||
| 444 | void QJsonObject::detach(uint reserve) | - | ||||||||||||||||||
| 445 | { | - | ||||||||||||||||||
| 446 | (void)reserve; | - | ||||||||||||||||||
| 447 | ((!(!reserve)) ? qt_assert("!reserve",__FILE__,1196) : qt_noop()); | - | ||||||||||||||||||
| 448 | detach2(reserve); | - | ||||||||||||||||||
| 449 | } never executed: end of block | 0 | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | bool QJsonObject::detach2(uint reserve) | - | ||||||||||||||||||
| 452 | { | - | ||||||||||||||||||
| 453 | if (!d
| 2-6 | ||||||||||||||||||
| 454 | if (reserve >= QJsonPrivate::Value::MaxSize
| 0-2 | ||||||||||||||||||
| 455 | QMessageLogger(__FILE__, 1204, __PRETTY_FUNCTION__).warning("QJson: Document too large to store in data structure"); | - | ||||||||||||||||||
| 456 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 457 | } | - | ||||||||||||||||||
| 458 | d = new QJsonPrivate::Data(reserve, QJsonValue::Object); | - | ||||||||||||||||||
| 459 | o = static_cast<QJsonPrivate::Object *>(d->header->root()); | - | ||||||||||||||||||
| 460 | d->ref.ref(); | - | ||||||||||||||||||
| 461 | return executed 2 times by 1 test: true;return true;Executed by:
executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||||||||
| 462 | } | - | ||||||||||||||||||
| 463 | if (reserve == 0
| 0-6 | ||||||||||||||||||
| 464 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | QJsonPrivate::Data *x = d->clone(o, reserve); | - | ||||||||||||||||||
| 467 | if (!x
| 0-6 | ||||||||||||||||||
| 468 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 469 | x->ref.ref(); | - | ||||||||||||||||||
| 470 | if (!d->ref.deref()
| 2-4 | ||||||||||||||||||
| 471 | delete d; executed 2 times by 1 test: delete d;Executed by:
| 2 | ||||||||||||||||||
| 472 | d = x; | - | ||||||||||||||||||
| 473 | o = static_cast<QJsonPrivate::Object *>(d->header->root()); | - | ||||||||||||||||||
| 474 | return executed 6 times by 1 test: true;return true;Executed by:
executed 6 times by 1 test: return true;Executed by:
| 6 | ||||||||||||||||||
| 475 | } | - | ||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | void QJsonObject::compact() | - | ||||||||||||||||||
| 481 | { | - | ||||||||||||||||||
| 482 | if (!d
| 0 | ||||||||||||||||||
| 483 | return; never executed: return; | 0 | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | detach2(); | - | ||||||||||||||||||
| 486 | d->compact(); | - | ||||||||||||||||||
| 487 | o = static_cast<QJsonPrivate::Object *>(d->header->root()); | - | ||||||||||||||||||
| 488 | } never executed: end of block | 0 | ||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | - | |||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | QString QJsonObject::keyAt(int i) const | - | ||||||||||||||||||
| 494 | { | - | ||||||||||||||||||
| 495 | ((!(o && i >= 0 && i < (int)o->length)) ? qt_assert("o && i >= 0 && i < (int)o->length",__FILE__,1244) : qt_noop()); | - | ||||||||||||||||||
| 496 | - | |||||||||||||||||||
| 497 | QJsonPrivate::Entry *e = o->entryAt(i); | - | ||||||||||||||||||
| 498 | return executed 9 times by 1 test: e->key();return e->key();Executed by:
executed 9 times by 1 test: return e->key();Executed by:
| 9 | ||||||||||||||||||
| 499 | } | - | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | - | |||||||||||||||||||
| 504 | QJsonValue QJsonObject::valueAt(int i) const | - | ||||||||||||||||||
| 505 | { | - | ||||||||||||||||||
| 506 | if (!o
| 0-9 | ||||||||||||||||||
| 507 | return never executed: QJsonValue(QJsonValue::Undefined);return QJsonValue(QJsonValue::Undefined);never executed: return QJsonValue(QJsonValue::Undefined); | 0 | ||||||||||||||||||
| 508 | - | |||||||||||||||||||
| 509 | QJsonPrivate::Entry *e = o->entryAt(i); | - | ||||||||||||||||||
| 510 | return executed 9 times by 1 test: QJsonValue(d, o, e->value);return QJsonValue(d, o, e->value);Executed by:
executed 9 times by 1 test: return QJsonValue(d, o, e->value);Executed by:
| 9 | ||||||||||||||||||
| 511 | } | - | ||||||||||||||||||
| 512 | - | |||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | void QJsonObject::setValueAt(int i, const QJsonValue &val) | - | ||||||||||||||||||
| 517 | { | - | ||||||||||||||||||
| 518 | ((!(o && i >= 0 && i < (int)o->length)) ? qt_assert("o && i >= 0 && i < (int)o->length",__FILE__,1267) : qt_noop()); | - | ||||||||||||||||||
| 519 | - | |||||||||||||||||||
| 520 | QJsonPrivate::Entry *e = o->entryAt(i); | - | ||||||||||||||||||
| 521 | insert(e->key(), val); | - | ||||||||||||||||||
| 522 | } never executed: end of block | 0 | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | QDebug operator<<(QDebug dbg, const QJsonObject &o) | - | ||||||||||||||||||
| 526 | { | - | ||||||||||||||||||
| 527 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
| 528 | if (!o.o
| 0-1 | ||||||||||||||||||
| 529 | dbg << "QJsonObject()"; | - | ||||||||||||||||||
| 530 | return executed 1 time by 1 test: dbg;return dbg;Executed by:
executed 1 time by 1 test: return dbg;Executed by:
| 1 | ||||||||||||||||||
| 531 | } | - | ||||||||||||||||||
| 532 | QByteArray json; | - | ||||||||||||||||||
| 533 | QJsonPrivate::Writer::objectToJson(o.o, json, 0, true); | - | ||||||||||||||||||
| 534 | dbg.nospace() << "QJsonObject(" | - | ||||||||||||||||||
| 535 | << json.constData() | - | ||||||||||||||||||
| 536 | << ")"; | - | ||||||||||||||||||
| 537 | return never executed: dbg;return dbg;never executed: return dbg; | 0 | ||||||||||||||||||
| 538 | } | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | - | |||||||||||||||||||
| 541 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |