Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qcbormap.cpp
Go to the documentation of this file.
1
// Copyright (C) 2018 Intel Corporation.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:critical reason:data-parser
4
5
#
include
"qcbormap.h"
6
#
include
"qcborvalue_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
using
namespace
QtCbor;
11
12
/*!
13
\class QCborMap
14
\inmodule QtCore
15
\ingroup cbor
16
\ingroup qtserialization
17
\reentrant
18
\since 5.12
19
20
\brief The QCborMap class is used to hold an associative container representable in CBOR.
21
22
\compares strong
23
\compareswith strong QCborValue QCborValueConstRef
24
\endcompareswith
25
26
This class can be used to hold an associative container in CBOR, a map
27
between a key and a value type. CBOR is the Concise Binary Object
28
Representation, a very compact form of binary data encoding that is a
29
superset of JSON. It was created by the IETF Constrained RESTful
30
Environments (CoRE) WG, which has used it in many new RFCs. It is meant to
31
be used alongside the \l{RFC 7252}{CoAP
32
protocol}.
33
34
Unlike JSON and \l QVariantMap, CBOR map keys can be of any type, not just
35
strings. For that reason, QCborMap is effectively a map between QCborValue
36
keys to QCborValue value elements.
37
38
However, for all member functions that take a key parameter, QCborMap
39
provides overloads that will work efficiently with integers and strings. In
40
fact, the use of integer keys is encouraged, since they occupy fewer bytes
41
to transmit and are simpler to encode and decode. Newer protocols designed
42
by the IETF CoRE WG to work specifically with CBOR are known to use them.
43
44
QCborMap is not sorted, because of that, searching for keys has linear
45
complexity (O(n)). QCborMap actually keeps the elements in the order that
46
they were inserted, which means that it is possible to make sorted
47
QCborMaps by carefully inserting elements in sorted order. CBOR does not
48
require sorting, but recommends it.
49
50
QCborMap can also be converted to and from QVariantMap and QJsonObject.
51
However, when performing the conversion, any non-string keys will be
52
stringified using a one-way method that the conversion back to QCborMap
53
will not undo.
54
55
\sa QCborArray, QCborValue, QJsonDocument, QVariantMap,
56
{Parsing and displaying CBOR data}, {Serialization Converter},
57
{Saving and Loading a Game}
58
*/
59
60
/*!
61
\typedef QCborMap::value_type
62
63
The value that is stored in this container: a pair of QCborValues
64
*/
65
66
/*!
67
\typedef QCborMap::key_type
68
69
The key type for this map. Since QCborMap keys can be any CBOR type, this
70
is a QCborValue.
71
*/
72
73
/*!
74
\typedef QCborMap::mapped_type
75
76
The type that is mapped to (the value), that is, a QCborValue.
77
*/
78
79
/*!
80
\typedef QCborMap::size_type
81
82
The type that QCborMap uses for sizes.
83
*/
84
85
/*!
86
\typedef QCborMap::iterator
87
88
A synonym for QCborMap::Iterator.
89
*/
90
91
/*!
92
\typedef QCborMap::const_iterator
93
94
A synonym for QCborMap::ConstIterator
95
*/
96
97
/*!
98
\fn QCborMap::iterator QCborMap::begin()
99
100
Returns a map iterator pointing to the first key-value pair of this map. If
101
this map is empty, the returned iterator will be the same as end().
102
103
\sa constBegin(), end()
104
*/
105
106
/*!
107
\fn QCborMap::const_iterator QCborMap::constBegin() const
108
109
Returns a map iterator pointing to the first key-value pair of this map. If
110
this map is empty, the returned iterator will be the same as constEnd().
111
112
\sa begin(), constEnd()
113
*/
114
115
/*!
116
\fn QCborMap::const_iterator QCborMap::begin() const
117
118
Returns a map iterator pointing to the first key-value pair of this map. If
119
this map is empty, the returned iterator will be the same as constEnd().
120
121
\sa cbegin(), constEnd()
122
*/
123
124
/*!
125
\fn QCborMap::const_iterator QCborMap::cbegin() const
126
127
Returns a map iterator pointing to the first key-value pair of this map. If
128
this map is empty, the returned iterator will be the same as constEnd().
129
130
\sa begin(), constEnd()
131
*/
132
133
/*!
134
\fn QCborMap::iterator QCborMap::end()
135
136
Returns a map iterator representing an element just past the last element
137
in the map.
138
139
\sa begin(), constBegin(), find(), constFind()
140
*/
141
142
/*!
143
\fn QCborMap::iterator QCborMap::constEnd() const
144
145
Returns a map iterator representing an element just past the last element
146
in the map.
147
148
\sa begin(), constBegin(), find(), constFind()
149
*/
150
151
/*!
152
\fn QCborMap::iterator QCborMap::end() const
153
154
Returns a map iterator representing an element just past the last element
155
in the map.
156
157
\sa begin(), constBegin(), find(), constFind()
158
*/
159
160
/*!
161
\fn QCborMap::iterator QCborMap::cend() const
162
163
Returns a map iterator representing an element just past the last element
164
in the map.
165
166
\sa begin(), constBegin(), find(), constFind()
167
*/
168
169
/*! \typedef QCborMap::const_key_value_iterator
170
\inmodule QtCore
171
\since 6.10
172
\brief The QCborMap::const_key_value_iterator typedef provides an STL-style iterator for
173
QCborMap.
174
175
QCborMap::const_key_value_iterator is essentially the same as QCborMap::const_iterator
176
but provided for symmetry with other containers like QJsonObject.
177
178
\sa QKeyValueIterator
179
*/
180
181
/*! \typedef QCborMap::key_value_iterator
182
\inmodule QtCore
183
\since 6.10
184
\brief The QCborMap::key_value_iterator typedef provides an STL-style iterator for QCborMap.
185
186
QCborMap::key_value_iterator is essentially the same as QCborMap::iterator
187
but provided for symmetry with other containers like QJsonObject.
188
189
\sa QKeyValueIterator
190
*/
191
192
/*! \fn QCborMap::key_value_iterator QCborMap::keyValueBegin()
193
\since 6.10
194
195
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first entry
196
in the map.
197
198
\sa keyValueEnd()
199
*/
200
201
/*! \fn QCborMap::key_value_iterator QCborMap::keyValueEnd()
202
\since 6.10
203
204
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
205
entry after the last entry in the map.
206
207
\sa keyValueBegin()
208
*/
209
210
/*! \fn QCborMap::const_key_value_iterator QCborMap::keyValueBegin() const
211
\since 6.10
212
213
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry
214
in the map.
215
216
\sa keyValueEnd()
217
*/
218
219
/*! \fn QCborMap::const_key_value_iterator QCborMap::constKeyValueBegin() const
220
\since 6.10
221
222
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry
223
in the map.
224
225
\sa keyValueBegin()
226
*/
227
228
/*! \fn QCborMap::const_key_value_iterator QCborMap::keyValueEnd() const
229
\since 6.10
230
231
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
232
entry after the last entry in the map.
233
234
\sa keyValueBegin()
235
*/
236
237
/*! \fn QCborMap::const_key_value_iterator QCborMap::constKeyValueEnd() const
238
\since 6.10
239
240
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
241
entry after the last entry in the map.
242
243
\sa constKeyValueBegin()
244
*/
245
246
/*! \fn auto QCborMap::asKeyValueRange() &
247
\fn auto QCborMap::asKeyValueRange() const &
248
\fn auto QCborMap::asKeyValueRange() &&
249
\fn auto QCborMap::asKeyValueRange() const &&
250
\since 6.10
251
252
Returns a range object that allows iteration over this map as
253
key/value pairs.
254
255
Note that the values obtained this way are references into the one in the
256
map. Specifically, mutating the value will modify the map itself.
257
258
\sa QKeyValueIterator
259
*/
260
261
/*!
262
Constructs an empty CBOR Map object.
263
264
\sa isEmpty()
265
*/
266
QCborMap::QCborMap()
noexcept
267
: d(
nullptr
)
268
{
269
}
270
271
/*!
272
Creates a QCborMap object that is a copy of \a other.
273
*/
274
QCborMap::QCborMap(
const
QCborMap &other)
noexcept
275
: d(other.d)
276
{
277
}
278
279
/*!
280
\fn QCborMap::QCborMap(QCborMap &&other)
281
\since 6.10
282
283
Move-constructor.
284
285
The moved-from object \a other is placed in the default-constructed state.
286
287
\sa QCborMap::QCborMap()
288
*/
289
290
/*!
291
\fn QCborMap::QCborMap(std::initializer_list<value_type> args)
292
293
Constructs a QCborMap with items from a brace-initialization list found in
294
\a args, as in the following example:
295
296
\code
297
QCborMap map = {
298
{0, "Hello"},
299
{1, "World"},
300
{"foo", nullptr},
301
{"bar", QCborArray{0, 1, 2, 3, 4}}
302
};
303
\endcode
304
*/
305
306
/*!
307
Destroys this QCborMap object and frees any associated resources it owns.
308
*/
309
QCborMap::~QCborMap()
310
{
311
}
312
313
/*!
314
Replaces the contents of this object with a copy of \a other, then returns
315
a reference to this object.
316
*/
317
QCborMap &QCborMap::operator=(
const
QCborMap &other)
noexcept
318
{
319
d = other.d;
320
return
*
this
;
321
}
322
323
/*!
324
\fn QCborMap &QCborMap::operator=(QCborMap &&other)
325
\since 6.10
326
327
Move-assignment operator.
328
329
The moved-from object \a other is placed in a valid, but unspecified state.
330
*/
331
332
/*!
333
\fn void QCborMap::swap(QCborMap &other)
334
\memberswap{map}
335
*/
336
337
/*!
338
\fn QCborValue QCborMap::toCborValue() const
339
340
Explicitly constructs a \l QCborValue object that represents this map.
341
This function is usually not necessary since QCborValue has a constructor
342
for QCborMap, so the conversion is implicit.
343
344
Converting QCborMap to QCborValue allows it to be used in any context where
345
QCborValues can be used, including as keys and mapped types in QCborMap, as
346
well as QCborValue::toCbor().
347
348
\sa QCborValue::QCborValue(const QCborMap &)
349
*/
350
351
/*!
352
\fn bool QCborMap::isEmpty() const
353
354
Returns true if this map is empty (that is, size() is 0).
355
356
\sa size(), clear()
357
*/
358
359
/*!
360
Returns the number of elements in this map.
361
362
\sa isEmpty()
363
*/
364
qsizetype QCborMap::size()
const
noexcept
365
{
366
return
d ? d->elements.size() / 2 : 0;
367
}
368
369
/*!
370
Empties this map.
371
372
\sa isEmpty()
373
*/
374
void
QCborMap::clear()
375
{
376
d.reset();
377
}
378
379
/*!
380
Returns a list of all keys in this map.
381
382
\sa QMap::keys(), QHash::keys()
383
*/
384
QList<QCborValue> QCborMap::keys()
const
385
{
386
QList<QCborValue> result;
387
if
(d) {
388
result.reserve(size());
389
for
(qsizetype i = 0; i < d->elements.size(); i += 2)
390
result << d->valueAt(i);
391
}
392
return
result;
393
}
394
395
/*!
396
\fn QCborValue QCborMap::value(qint64 key) const
397
398
Returns the QCborValue element in this map that corresponds to key \a key,
399
if there is one. CBOR recommends using integer keys, since they occupy less
400
space and are simpler to encode and decode.
401
402
If the map does not contain key \a key, this function returns a QCborValue
403
containing an undefined value. For that reason, it is not possible with
404
this function to tell apart the situation where the key was not present
405
from the situation where the key was mapped to an undefined value.
406
407
If the map contains more than one key equal to \a key, it is undefined
408
which one the return from function will reference. QCborMap does not allow
409
inserting duplicate keys, but it is possible to create such a map by
410
decoding a CBOR stream with them. They are usually not permitted and having
411
duplicate keys is usually an indication of a problem in the sender.
412
413
\sa operator[](qint64), find(qint64), constFind(qint64), remove(qint64), contains(qint64)
414
value(QLatin1StringView), value(const QString &), value(const QCborValue &)
415
*/
416
417
/*!
418
\fn QCborValue QCborMap::operator[](qint64 key) const
419
420
Returns the QCborValue element in this map that corresponds to key \a key,
421
if there is one. CBOR recommends using integer keys, since they occupy less
422
space and are simpler to encode and decode.
423
424
If the map does not contain key \a key, this function returns a QCborValue
425
containing an undefined value. For that reason, it is not possible with
426
this function to tell apart the situation where the key was not present
427
from the situation where the key was mapped to an undefined value.
428
429
If the map contains more than one key equal to \a key, it is undefined
430
which one this function will return. QCborMap does not allow inserting
431
duplicate keys, but it is possible to create such a map by decoding a CBOR
432
stream with them. They are usually not permitted and having duplicate keys
433
is usually an indication of a problem in the sender.
434
435
\sa value(qint64), find(qint64), constFind(qint64), remove(qint64), contains(qint64)
436
operator[](QLatin1StringView), operator[](const QString &),
437
operator[](const QCborOperator[] &)
438
*/
439
440
/*!
441
\fn QCborValue QCborMap::take(qint64 key)
442
443
Removes the key \a key and the corresponding value from the map and returns
444
the value, if it is found. If the map contains no such key, this function does nothing.
445
446
If the map contains more than one key equal to \a key, it is undefined
447
which one this function will remove. QCborMap does not allow inserting
448
duplicate keys, but it is possible to create such a map by decoding a CBOR
449
stream with them. They are usually not permitted and having duplicate keys
450
is usually an indication of a problem in the sender.
451
452
\sa value(qint64), operator[](qint64), find(qint64), contains(qint64),
453
take(QLatin1StringView), take(const QString &), take(const QCborValue &), insert()
454
*/
455
456
/*!
457
\fn void QCborMap::remove(qint64 key)
458
459
Removes the key \a key and the corresponding value from the map, if it is
460
found. If the map contains no such key, this function does nothing.
461
462
If the map contains more than one key equal to \a key, it is undefined
463
which one this function will remove. QCborMap does not allow inserting
464
duplicate keys, but it is possible to create such a map by decoding a CBOR
465
stream with them. They are usually not permitted and having duplicate keys
466
is usually an indication of a problem in the sender.
467
468
\sa value(qint64), operator[](qint64), find(qint64), contains(qint64)
469
remove(QLatin1StringView), remove(const QString &), remove(const QCborValue &)
470
*/
471
472
/*!
473
\fn bool QCborMap::contains(qint64 key) const
474
475
Returns true if this map contains a key-value pair identified by key \a
476
key. CBOR recommends using integer keys, since they occupy less space and
477
are simpler to encode and decode.
478
479
\sa value(qint64), operator[](qint64), find(qint64), remove(qint64),
480
contains(QLatin1StringView), remove(const QString &), remove(const QCborValue &)
481
*/
482
483
/*!
484
Returns a QCborValueRef to the value in this map that corresponds to key \a
485
key. CBOR recommends using integer keys, since they occupy less space and
486
are simpler to encode and decode.
487
488
QCborValueRef has the exact same API as \l QCborValue, with one important
489
difference: if you assign new values to it, this map will be updated with
490
that new value.
491
492
If the map did not have a key equal to \a key, one is inserted and this
493
function returns a reference to the new value, which will be a QCborValue
494
with an undefined value. For that reason, it is not possible with this
495
function to tell apart the situation where the key was not present from the
496
situation where the key was mapped to an undefined value.
497
498
If the map contains more than one key equal to \a key, it is undefined
499
which one the return will reference. QCborMap does not allow inserting
500
duplicate keys, but it is possible to create such a map by decoding a CBOR
501
stream with them. They are usually not permitted and having duplicate keys
502
is usually an indication of a problem in the sender.
503
504
\sa value(qint64), find(qint64), contains(qint64), remove(qint64),
505
operator[](QLatin1StringView), operator[](const QString &), operator[](const QCborValue &)
506
*/
507
QCborValueRef QCborMap::operator[](qint64 key)
508
{
509
return
QCborContainerPrivate::findOrAddMapKey(*
this
, key);
510
}
511
512
/*!
513
\fn QCborValue QCborMap::value(QLatin1StringView key) const
514
\overload
515
516
Returns the QCborValue element in this map that corresponds to key \a key,
517
if there is one.
518
519
If the map does not contain key \a key, this function returns a QCborValue
520
containing an undefined value. For that reason, it is not possible with
521
this function to tell apart the situation where the key was not present
522
from the situation where the key was mapped to an undefined value.
523
524
If the map contains more than one key equal to \a key, it is undefined
525
which one this function will return. QCborMap does not allow inserting
526
duplicate keys, but it is possible to create such a map by decoding a CBOR
527
stream with them. They are usually not permitted and having duplicate keys
528
is usually an indication of a problem in the sender.
529
530
\sa operator[](QLatin1StringView), find(QLatin1StringView), constFind(QLatin1StringView),
531
remove(QLatin1StringView), contains(QLatin1StringView)
532
value(qint64), value(const QString &), value(const QCborValue &)
533
*/
534
535
/*!
536
\fn QCborValue QCborMap::operator[](QLatin1StringView key) const
537
\overload
538
539
Returns the QCborValue element in this map that corresponds to key \a key,
540
if there is one.
541
542
If the map does not contain key \a key, this function returns a QCborValue
543
containing an undefined value. For that reason, it is not possible with
544
this function to tell apart the situation where the key was not present
545
from the situation where the key was mapped to an undefined value.
546
547
If the map contains more than one key equal to \a key, it is undefined
548
which one this function will return. QCborMap does not allow inserting
549
duplicate keys, but it is possible to create such a map by decoding a CBOR
550
stream with them. They are usually not permitted and having duplicate keys
551
is usually an indication of a problem in the sender.
552
553
\sa value(QLatin1StringView), find(QLatin1StringView), constFind(QLatin1StringView),
554
remove(QLatin1StringView), contains(QLatin1StringView)
555
operator[](qint64), operator[](const QString &), operator[](const QCborOperator[] &)
556
*/
557
558
/*!
559
\fn QCborValue QCborMap::take(QLatin1StringView key)
560
561
Removes the key \a key and the corresponding value from the map and returns
562
the value, if it is found. If the map contains no such key, this function does nothing.
563
564
If the map contains more than one key equal to \a key, it is undefined
565
which one this function will remove. QCborMap does not allow inserting
566
duplicate keys, but it is possible to create such a map by decoding a CBOR
567
stream with them. They are usually not permitted and having duplicate keys
568
is usually an indication of a problem in the sender.
569
570
\sa value(QLatin1StringView), operator[](QLatin1StringView), find(QLatin1StringView),
571
contains(QLatin1StringView), take(qint64), take(const QString &),
572
take(const QCborValue &), insert()
573
*/
574
575
/*!
576
\fn void QCborMap::remove(QLatin1StringView key)
577
\overload
578
579
Removes the key \a key and the corresponding value from the map, if it is
580
found. If the map contains no such key, this function does nothing.
581
582
If the map contains more than one key equal to \a key, it is undefined
583
which one this function will remove. QCborMap does not allow inserting
584
duplicate keys, but it is possible to create such a map by decoding a CBOR
585
stream with them. They are usually not permitted and having duplicate keys
586
is usually an indication of a problem in the sender.
587
588
\sa value(QLatin1StringView), operator[](QLatin1StringView), find(QLatin1StringView),
589
contains(QLatin1StringView), remove(qint64), remove(const QString &),
590
remove(const QCborValue &)
591
*/
592
593
/*!
594
\fn bool QCborMap::contains(QLatin1StringView key) const
595
\overload
596
597
Returns true if this map contains a key-value pair identified by key \a
598
key.
599
600
\sa value(QLatin1StringView), operator[](QLatin1StringView), find(QLatin1StringView),
601
remove(QLatin1StringView), contains(qint64), remove(const QString &),
602
remove(const QCborValue &)
603
*/
604
605
/*!
606
\overload
607
608
Returns a QCborValueRef to the value in this map that corresponds to key \a
609
key.
610
611
QCborValueRef has the exact same API as \l QCborValue, with one important
612
difference: if you assign new values to it, this map will be updated with
613
that new value.
614
615
If the map did not have a key equal to \a key, one is inserted and this
616
function returns a reference to the new value, which will be a QCborValue
617
with an undefined value. For that reason, it is not possible with this
618
function to tell apart the situation where the key was not present from the
619
situation where the key was mapped to an undefined value.
620
621
If the map contains more than one key equal to \a key, it is undefined
622
which one the return will reference. QCborMap does not allow inserting
623
duplicate keys, but it is possible to create such a map by decoding a CBOR
624
stream with them. They are usually not permitted and having duplicate keys
625
is usually an indication of a problem in the sender.
626
627
\sa value(QLatin1StringView), find(QLatin1StringView), contains(QLatin1StringView),
628
remove(QLatin1StringView), operator[](qint64), operator[](const QString &),
629
operator[](const QCborValue &)
630
*/
631
QCborValueRef QCborMap::operator[](QLatin1StringView key)
632
{
633
return
QCborContainerPrivate::findOrAddMapKey(*
this
, key);
634
}
635
636
/*!
637
\fn QCborValue QCborMap::value(const QString &key) const
638
\overload
639
640
Returns the QCborValue element in this map that corresponds to key \a key,
641
if there is one.
642
643
If the map does not contain key \a key, this function returns a QCborValue
644
containing an undefined value. For that reason, it is not possible with
645
this function to tell apart the situation where the key was not present
646
from the situation where the key was mapped to an undefined value.
647
648
If the map contains more than one key equal to \a key, it is undefined
649
which one this function will return. QCborMap does not allow inserting
650
duplicate keys, but it is possible to create such a map by decoding a CBOR
651
stream with them. They are usually not permitted and having duplicate keys
652
is usually an indication of a problem in the sender.
653
654
\sa operator[](const QString &), find(const QString &), constFind(const QString &),
655
remove(const QString &), contains(const QString &)
656
value(qint64), value(QLatin1StringView), value(const QCborValue &)
657
*/
658
659
/*!
660
\fn QCborValue QCborMap::operator[](const QString &key) const
661
\overload
662
663
Returns the QCborValue element in this map that corresponds to key \a key,
664
if there is one.
665
666
If the map does not contain key \a key, this function returns a QCborValue
667
containing an undefined value. For that reason, it is not possible with
668
this function to tell apart the situation where the key was not present
669
from the situation where the key was mapped to an undefined value.
670
671
If the map contains more than one key equal to \a key, it is undefined
672
which one this function will return. QCborMap does not allow inserting
673
duplicate keys, but it is possible to create such a map by decoding a CBOR
674
stream with them. They are usually not permitted and having duplicate keys
675
is usually an indication of a problem in the sender.
676
677
\sa value(const QString &), find(const QString &), constFind(const QString &),
678
remove(const QString &), contains(const QString &)
679
operator[](qint64), operator[](QLatin1StringView), operator[](const QCborOperator[] &)
680
*/
681
682
/*!
683
\fn QCborValue QCborMap::take(const QString &key)
684
685
Removes the key \a key and the corresponding value from the map and returns
686
the value, if it is found. If the map contains no such key, this function does nothing.
687
688
If the map contains more than one key equal to \a key, it is undefined
689
which one this function will remove. QCborMap does not allow inserting
690
duplicate keys, but it is possible to create such a map by decoding a CBOR
691
stream with them. They are usually not permitted and having duplicate keys
692
is usually an indication of a problem in the sender.
693
694
\sa value(const QString &), operator[](const QString &), find(const QString &),
695
contains(const QString &), take(QLatin1StringView), take(qint64),
696
take(const QCborValue &), insert()
697
*/
698
699
/*!
700
\fn void QCborMap::remove(const QString &key)
701
\overload
702
703
Removes the key \a key and the corresponding value from the map, if it is
704
found. If the map contains no such key, this function does nothing.
705
706
If the map contains more than one key equal to \a key, it is undefined
707
which one this function will remove. QCborMap does not allow inserting
708
duplicate keys, but it is possible to create such a map by decoding a CBOR
709
stream with them. They are usually not permitted and having duplicate keys
710
is usually an indication of a problem in the sender.
711
712
\sa value(const QString &), operator[](const QString &), find(const QString &),
713
contains(const QString &)
714
remove(qint64), remove(QLatin1StringView), remove(const QCborValue &)
715
*/
716
717
/*!
718
\fn bool QCborMap::contains(const QString &key) const
719
\overload
720
721
Returns true if this map contains a key-value pair identified by key \a
722
key.
723
724
\sa value(const QString &), operator[](const QString &), find(const QString &),
725
remove(const QString &),
726
contains(qint64), remove(QLatin1StringView), remove(const QCborValue &)
727
*/
728
729
/*!
730
\overload
731
732
Returns a QCborValueRef to the value in this map that corresponds to key \a
733
key.
734
735
QCborValueRef has the exact same API as \l QCborValue, with one important
736
difference: if you assign new values to it, this map will be updated with
737
that new value.
738
739
If the map did not have a key equal to \a key, one is inserted and this
740
function returns a reference to the new value, which will be a QCborValue
741
with an undefined value. For that reason, it is not possible with this
742
function to tell apart the situation where the key was not present from the
743
situation where the key was mapped to an undefined value.
744
745
If the map contains more than one key equal to \a key, it is undefined
746
which one the return will reference. QCborMap does not allow inserting
747
duplicate keys, but it is possible to create such a map by decoding a CBOR
748
stream with them. They are usually not permitted and having duplicate keys
749
is usually an indication of a problem in the sender.
750
751
\sa value(const QString &), find(const QString &), contains(const QString &),
752
remove(const QString &), operator[](qint64), operator[](QLatin1StringView),
753
operator[](const QCborValue &)
754
*/
755
QCborValueRef QCborMap::operator[](
const
QString & key)
756
{
757
return
QCborContainerPrivate::findOrAddMapKey(*
this
, qToStringViewIgnoringNull(key));
758
}
759
760
/*!
761
\fn QCborValue QCborMap::value(const QCborValue &key) const
762
763
Returns the QCborValue element in this map that corresponds to key \a key,
764
if there is one.
765
766
If the map does not contain key \a key, this function returns a QCborValue
767
containing an undefined value. For that reason, it is not possible with
768
this function to tell apart the situation where the key was not present
769
from the situation where the key was mapped to an undefined value.
770
771
If the map contains more than one key equal to \a key, it is undefined
772
which one this function will return. QCborMap does not allow inserting
773
duplicate keys, but it is possible to create such a map by decoding a CBOR
774
stream with them. They are usually not permitted and having duplicate keys
775
is usually an indication of a problem in the sender.
776
777
\sa operator[](const QCborValue &), find(const QCborValue &), constFind(const QCborValue &),
778
remove(const QCborValue &), contains(const QCborValue &)
779
value(qint64), value(QLatin1StringView), value(const QString &)
780
*/
781
782
/*!
783
\fn QCborValue QCborMap::operator[](const QCborValue &key) const
784
785
Returns the QCborValue element in this map that corresponds to key \a key,
786
if there is one.
787
788
If the map does not contain key \a key, this function returns a QCborValue
789
containing an undefined value. For that reason, it is not possible with
790
this function to tell apart the situation where the key was not present
791
from the situation where the key was mapped to an undefined value.
792
793
If the map contains more than one key equal to \a key, it is undefined
794
which one this function will return. QCborMap does not allow inserting
795
duplicate keys, but it is possible to create such a map by decoding a CBOR
796
stream with them. They are usually not permitted and having duplicate keys
797
is usually an indication of a problem in the sender.
798
799
\sa value(const QCborValue &), find(const QCborValue &), constFind(const QCborValue &),
800
remove(const QCborValue &), contains(const QCborValue &)
801
operator[](qint64), operator[](QLatin1StringView), operator[](const QCborOperator[] &)
802
*/
803
804
/*!
805
\fn QCborValue QCborMap::take(const QCborValue &key)
806
807
Removes the key \a key and the corresponding value from the map and returns
808
the value, if it is found. If the map contains no such key, this function does nothing.
809
810
If the map contains more than one key equal to \a key, it is undefined
811
which one this function will remove. QCborMap does not allow inserting
812
duplicate keys, but it is possible to create such a map by decoding a CBOR
813
stream with them. They are usually not permitted and having duplicate keys
814
is usually an indication of a problem in the sender.
815
816
\sa value(const QCborValue &), operator[](const QCborValue &), find(const QCborValue &),
817
contains(const QCborValue &), take(QLatin1StringView), take(const QString &),
818
take(qint64), insert()
819
*/
820
821
/*!
822
\fn void QCborMap::remove(const QCborValue &key)
823
824
Removes the key \a key and the corresponding value from the map, if it is
825
found. If the map contains no such key, this function does nothing.
826
827
If the map contains more than one key equal to \a key, it is undefined
828
which one this function will remove. QCborMap does not allow inserting
829
duplicate keys, but it is possible to create such a map by decoding a CBOR
830
stream with them. They are usually not permitted and having duplicate keys
831
is usually an indication of a problem in the sender.
832
833
\sa value(const QCborValue &), operator[](const QCborValue &), find(const QCborValue &),
834
contains(const QCborValue &)
835
remove(qint64), remove(QLatin1StringView), remove(const QString &)
836
*/
837
838
/*!
839
\fn bool QCborMap::contains(const QCborValue &key) const
840
841
Returns true if this map contains a key-value pair identified by key \a
842
key.
843
844
\sa value(const QCborValue &), operator[](const QCborValue &), find(const QCborValue &),
845
remove(const QCborValue &),
846
contains(qint64), remove(QLatin1StringView), remove(const QString &)
847
*/
848
849
/*!
850
\overload
851
852
Returns a QCborValueRef to the value in this map that corresponds to key \a
853
key.
854
855
QCborValueRef has the exact same API as \l QCborValue, with one important
856
difference: if you assign new values to it, this map will be updated with
857
that new value.
858
859
If the map did not have a key equal to \a key, one is inserted and this
860
function returns a reference to the new value, which will be a QCborValue
861
with an undefined value. For that reason, it is not possible with this
862
function to tell apart the situation where the key was not present from the
863
situation where the key was mapped to an undefined value.
864
865
If the map contains more than one key equal to \a key, it is undefined
866
which one the return will reference. QCborMap does not allow inserting
867
duplicate keys, but it is possible to create such a map by decoding a CBOR
868
stream with them. They are usually not permitted and having duplicate keys
869
is usually an indication of a problem in the sender.
870
871
\sa value(const QCborValue &), find(const QCborValue &), contains(const QCborValue &),
872
remove(const QCborValue &), operator[](qint64), operator[](QLatin1StringView),
873
operator[](const QString &)
874
*/
875
QCborValueRef QCborMap::operator[](
const
QCborValue &key)
876
{
877
return
QCborContainerPrivate::findOrAddMapKey<
const
QCborValue &>(*
this
, key);
878
}
879
880
template
<
typename
KeyType>
inline
QCborValueRef
881
QCborContainerPrivate
::
findOrAddMapKey
(QCborMap &map, KeyType key)
882
{
883
QCborValueRef result = findOrAddMapKey<KeyType>(map.d.data(), key);
884
map.d = result.d;
885
return
result;
886
}
887
888
/*!
889
\fn QCborMap::iterator QCborMap::find(qint64 key)
890
\fn QCborMap::const_iterator QCborMap::find(qint64 key) const
891
892
Returns a map iterator to the key-value pair whose key is \a key, if the
893
map contains such a pair. If it doesn't, this function returns end().
894
895
CBOR recommends using integer keys, since they occupy less
896
space and are simpler to encode and decode.
897
898
If the map contains more than one key equal to \a key, it is undefined
899
which one this function will find. QCborMap does not allow inserting
900
duplicate keys, but it is possible to create such a map by decoding a CBOR
901
stream with them. They are usually not permitted and having duplicate keys
902
is usually an indication of a problem in the sender.
903
904
\sa value(qint64), operator[](qint64), constFind(qint64), remove(qint64), contains(qint64),
905
value(QLatin1StringView), value(const QString &), value(const QCborValue &)
906
*/
907
QCborMap::iterator QCborMap::find(qint64 key)
908
{
909
detach();
910
auto
it = constFind(key);
911
return
{ d.data(), it.item.i };
912
}
913
914
/*!
915
\fn QCborMap::iterator QCborMap::find(QLatin1StringView key)
916
\fn QCborMap::const_iterator QCborMap::find(QLatin1StringView key) const
917
\overload
918
919
Returns a map iterator to the key-value pair whose key is \a key, if the
920
map contains such a pair. If it doesn't, this function returns end().
921
922
If the map contains more than one key equal to \a key, it is undefined
923
which one this function will find. QCborMap does not allow inserting
924
duplicate keys, but it is possible to create such a map by decoding a CBOR
925
stream with them. They are usually not permitted and having duplicate keys
926
is usually an indication of a problem in the sender.
927
928
\sa value(QLatin1StringView), operator[](QLatin1StringView), constFind(QLatin1StringView),
929
remove(QLatin1StringView), contains(QLatin1StringView),
930
value(qint64), value(const QString &), value(const QCborValue &)
931
*/
932
QCborMap::iterator QCborMap::find(QLatin1StringView key)
933
{
934
detach();
935
auto
it = constFind(key);
936
return
{ d.data(), it.item.i };
937
}
938
939
/*!
940
\fn QCborMap::iterator QCborMap::find(const QString & key)
941
\fn QCborMap::const_iterator QCborMap::find(const QString & key) const
942
\overload
943
944
Returns a map iterator to the key-value pair whose key is \a key, if the
945
map contains such a pair. If it doesn't, this function returns end().
946
947
If the map contains more than one key equal to \a key, it is undefined
948
which one this function will find. QCborMap does not allow inserting
949
duplicate keys, but it is possible to create such a map by decoding a CBOR
950
stream with them. They are usually not permitted and having duplicate keys
951
is usually an indication of a problem in the sender.
952
953
\sa value(const QString &), operator[](const QString &), constFind(const QString &),
954
remove(const QString &), contains(const QString &),
955
value(qint64), value(QLatin1StringView), value(const QCborValue &)
956
*/
957
QCborMap::iterator QCborMap::find(
const
QString & key)
958
{
959
detach();
960
auto
it = constFind(key);
961
return
{ d.data(), it.item.i };
962
}
963
964
/*!
965
\fn QCborMap::iterator QCborMap::find(const QCborValue &key)
966
\fn QCborMap::const_iterator QCborMap::find(const QCborValue &key) const
967
\overload
968
969
Returns a map iterator to the key-value pair whose key is \a key, if the
970
map contains such a pair. If it doesn't, this function returns end().
971
972
If the map contains more than one key equal to \a key, it is undefined
973
which one this function will find. QCborMap does not allow inserting
974
duplicate keys, but it is possible to create such a map by decoding a CBOR
975
stream with them. They are usually not permitted and having duplicate keys
976
is usually an indication of a problem in the sender.
977
978
\sa value(const QCborValue &), operator[](const QCborValue &), constFind(const QCborValue &),
979
remove(const QCborValue &), contains(const QCborValue &),
980
value(qint64), value(QLatin1StringView), value(const QString &)
981
*/
982
QCborMap::iterator QCborMap::find(
const
QCborValue &key)
983
{
984
detach();
985
auto
it = constFind(key);
986
return
{ d.data(), it.item.i };
987
}
988
989
/*!
990
Returns a map iterator to the key-value pair whose key is \a key, if the
991
map contains such a pair. If it doesn't, this function returns constEnd().
992
993
CBOR recommends using integer keys, since they occupy less
994
space and are simpler to encode and decode.
995
996
If the map contains more than one key equal to \a key, it is undefined
997
which one this function will find. QCborMap does not allow inserting
998
duplicate keys, but it is possible to create such a map by decoding a CBOR
999
stream with them. They are usually not permitted and having duplicate keys
1000
is usually an indication of a problem in the sender.
1001
1002
\sa value(qint64), operator[](qint64), find(qint64), remove(qint64), contains(qint64),
1003
value(QLatin1StringView), value(const QString &), value(const QCborValue &)
1004
*/
1005
QCborMap::const_iterator QCborMap::constFind(qint64 key)
const
1006
{
1007
return
d ? d->findCborMapKey(key) : constEnd();
1008
}
1009
1010
/*!
1011
\overload
1012
1013
Returns a map iterator to the key-value pair whose key is \a key, if the
1014
map contains such a pair. If it doesn't, this function returns constEnd().
1015
1016
If the map contains more than one key equal to \a key, it is undefined
1017
which one this function will find. QCborMap does not allow inserting
1018
duplicate keys, but it is possible to create such a map by decoding a CBOR
1019
stream with them. They are usually not permitted and having duplicate keys
1020
is usually an indication of a problem in the sender.
1021
1022
\sa value(QLatin1StringView), operator[](QLatin1StringView), find(QLatin1StringView),
1023
remove(QLatin1StringView), contains(QLatin1StringView),
1024
value(qint64), value(const QString &), value(const QCborValue &)
1025
*/
1026
QCborMap::const_iterator QCborMap::constFind(QLatin1StringView key)
const
1027
{
1028
return
d ? d->findCborMapKey(key) : constEnd();
1029
}
1030
1031
/*!
1032
\overload
1033
1034
Returns a map iterator to the key-value pair whose key is \a key, if the
1035
map contains such a pair. If it doesn't, this function returns constEnd().
1036
1037
If the map contains more than one key equal to \a key, it is undefined
1038
which one this function will find. QCborMap does not allow inserting
1039
duplicate keys, but it is possible to create such a map by decoding a CBOR
1040
stream with them. They are usually not permitted and having duplicate keys
1041
is usually an indication of a problem in the sender.
1042
1043
\sa value(const QString &), operator[](const QString &), find(const QString &),
1044
remove(const QString &), contains(const QString &),
1045
value(qint64), value(QLatin1StringView), value(const QCborValue &)
1046
*/
1047
QCborMap::const_iterator QCborMap::constFind(
const
QString &key)
const
1048
{
1049
return
d ? d->findCborMapKey(qToStringViewIgnoringNull(key)) : constEnd();
1050
}
1051
1052
/*!
1053
\overload
1054
1055
Returns a map iterator to the key-value pair whose key is \a key, if the
1056
map contains such a pair. If it doesn't, this function returns constEnd().
1057
1058
If the map contains more than one key equal to \a key, it is undefined
1059
which one this function will find. QCborMap does not allow inserting
1060
duplicate keys, but it is possible to create such a map by decoding a CBOR
1061
stream with them. They are usually not permitted and having duplicate keys
1062
is usually an indication of a problem in the sender.
1063
1064
\sa value(const QCborValue &), operator[](const QCborValue &), find(const QCborValue &),
1065
remove(const QCborValue &), contains(const QCborValue &),
1066
value(qint64), value(QLatin1StringView), value(const QString &)
1067
*/
1068
QCborMap::const_iterator QCborMap::constFind(
const
QCborValue &key)
const
1069
{
1070
return
d ? d->findCborMapKey<
const
QCborValue &>(key) : constEnd();
1071
}
1072
1073
/*!
1074
\fn QCborMap::iterator QCborMap::insert(qint64 key, const QCborValue &value)
1075
\overload
1076
1077
Inserts the key \a key and value \a value into this map and returns a map
1078
iterator pointing to the newly inserted pair.
1079
1080
If the map already had a key equal to \a key, its value will be overwritten
1081
by \a value.
1082
1083
\sa erase(), remove(qint64), value(qint64), operator[](qint64), find(qint64),
1084
contains(qint64), take(qint64), extract()
1085
*/
1086
1087
/*!
1088
\fn QCborMap::iterator QCborMap::insert(QLatin1StringView key, const QCborValue &value)
1089
\overload
1090
1091
Inserts the key \a key and value \a value into this map and returns a map
1092
iterator pointing to the newly inserted pair.
1093
1094
If the map already had a key equal to \a key, its value will be overwritten
1095
by \a value.
1096
1097
\sa erase(), remove(QLatin1StringView), value(QLatin1StringView), operator[](QLatin1StringView),
1098
find(QLatin1StringView), contains(QLatin1StringView), take(QLatin1StringView), extract()
1099
*/
1100
1101
/*!
1102
\fn QCborMap::iterator QCborMap::insert(const QString &key, const QCborValue &value)
1103
\overload
1104
1105
Inserts the key \a key and value \a value into this map and returns a map
1106
iterator pointing to the newly inserted pair.
1107
1108
If the map already had a key equal to \a key, its value will be overwritten
1109
by \a value.
1110
1111
\sa erase(), remove(const QString &), value(const QString &), operator[](const QString &),
1112
find(const QString &), contains(const QString &), take(const QString &), extract()
1113
*/
1114
1115
/*!
1116
\fn QCborMap::iterator QCborMap::insert(const QCborValue &key, const QCborValue &value)
1117
\overload
1118
1119
Inserts the key \a key and value \a value into this map and returns a map
1120
iterator pointing to the newly inserted pair.
1121
1122
If the map already had a key equal to \a key, its value will be overwritten
1123
by \a value.
1124
1125
\sa erase(), remove(const QCborValue &), value(const QCborValue &), operator[](const QCborValue &),
1126
find(const QCborValue &), contains(const QCborValue &), take(const QCborValue &), extract()
1127
*/
1128
1129
/*!
1130
\fn QCborMap::iterator QCborMap::insert(value_type v)
1131
\overload
1132
1133
Inserts the key-value pair in \a v into this map and returns a map iterator
1134
pointing to the newly inserted pair.
1135
1136
If the map already had a key equal to \c{v.first}, its value will be
1137
overwritten by \c{v.second}.
1138
1139
\sa operator[], erase(), extract()
1140
*/
1141
1142
1143
/*!
1144
\fn QCborMap::iterator QCborMap::erase(const_iterator it)
1145
1146
Removes the key-value pair pointed to by the map iterator \a it and returns a
1147
pointer to the next element, after removal.
1148
1149
\sa remove(), begin(), end(), insert(), extract()
1150
*/
1151
1152
/*!
1153
\overload
1154
1155
Removes the key-value pair pointed to by the map iterator \a it and returns a
1156
pointer to the next element, after removal.
1157
1158
\sa remove(), begin(), end(), insert()
1159
*/
1160
QCborMap::iterator QCborMap::erase(QCborMap::iterator it)
1161
{
1162
detach();
1163
1164
// remove both key and value
1165
// ### optimize?
1166
d->removeAt(it.item.i - 1);
1167
d->removeAt(it.item.i - 1);
1168
return
it;
1169
}
1170
1171
/*!
1172
\fn QCborValue QCborMap::extract(iterator it)
1173
\fn QCborValue QCborMap::extract(const_iterator it)
1174
1175
Extracts a value from the map at the position indicated by iterator \a it
1176
and returns the value so extracted.
1177
1178
\sa insert(), erase(), take(), remove()
1179
*/
1180
QCborValue QCborMap::extract(iterator it)
1181
{
1182
detach();
1183
QCborValue v = d->extractAt(it.item.i);
1184
// remove both key and value
1185
// ### optimize?
1186
d->removeAt(it.item.i - 1);
1187
d->removeAt(it.item.i - 1);
1188
1189
return
v;
1190
}
1191
1192
/*!
1193
\fn bool QCborMap::empty() const
1194
1195
Synonym for isEmpty(). This function is provided for compatibility with
1196
generic code that uses the Standard Library API.
1197
1198
Returns true if this map is empty (size() == 0).
1199
1200
\sa isEmpty(), size()
1201
*/
1202
1203
/*!
1204
\fn int QCborMap::compare(const QCborMap &other) const
1205
1206
Compares this map and \a other, comparing each element in sequence, and
1207
returns an integer that indicates whether this map should be sorted prior
1208
to (if the result is negative) or after \a other (if the result is
1209
positive). If this function returns 0, the two maps are equal and contain
1210
the same elements.
1211
1212
Note that CBOR maps are unordered, which means that two maps containing the
1213
very same pairs but in different order will still compare differently. To
1214
avoid this, it is recommended to insert elements into the map in a
1215
predictable order, such as by ascending key value. In fact, maps with keys
1216
in sorted order are required for Canonical CBOR representation.
1217
1218
For more information on CBOR sorting order, see QCborValue::compare().
1219
1220
\sa QCborValue::compare(), QCborArray::compare(), operator==()
1221
*/
1222
1223
/*!
1224
\fn bool QCborMap::operator==(const QCborMap &lhs, const QCborMap &rhs)
1225
1226
Compares \a lhs and \a rhs maps, comparing each element in sequence, and
1227
returns true if the two maps contain the same elements in the same order,
1228
false otherwise.
1229
1230
Note that CBOR maps are unordered, which means that two maps containing the
1231
very same pairs but in different order will still compare differently. To
1232
avoid this, it is recommended to insert elements into the map in a
1233
predictable order, such as by ascending key value. In fact, maps with keys
1234
in sorted order are required for Canonical CBOR representation.
1235
1236
For more information on CBOR equality in Qt, see, QCborValue::compare().
1237
1238
\sa compare(), QCborValue::operator==(), operator!=(), operator<()
1239
*/
1240
1241
/*!
1242
\fn bool QCborMap::operator!=(const QCborMap &lhs, const QCborMap &rhs)
1243
1244
Compares \a lhs and \a rhs maps, comparing each element in sequence, and
1245
returns true if the two maps contain any different elements or elements in
1246
different orders, false otherwise.
1247
1248
Note that CBOR maps are unordered, which means that two maps containing the
1249
very same pairs but in different order will still compare differently. To
1250
avoid this, it is recommended to insert elements into the map in a
1251
predictable order, such as by ascending key value. In fact, maps with keys
1252
in sorted order are required for Canonical CBOR representation.
1253
1254
For more information on CBOR equality in Qt, see, QCborValue::compare().
1255
1256
\sa compare(), QCborValue::operator==(), operator==(), operator<()
1257
*/
1258
1259
/*!
1260
\fn bool QCborMap::operator<(const QCborMap &lhs, const QCborMap &rhs)
1261
1262
Compares \a lhs and \a rhs maps, comparing each element in sequence, and
1263
returns true if \a lhs map should be sorted before \a rhs, false
1264
otherwise.
1265
1266
Note that CBOR maps are unordered, which means that two maps containing the
1267
very same pairs but in different order will still compare differently. To
1268
avoid this, it is recommended to insert elements into the map in a
1269
predictable order, such as by ascending key value. In fact, maps with keys
1270
in sorted order are required for Canonical CBOR representation.
1271
1272
For more information on CBOR sorting order, see QCborValue::compare().
1273
1274
\sa compare(), QCborValue::operator==(), QCborMap::operator==(),
1275
operator==(), operator!=()
1276
*/
1277
1278
/*!
1279
\fn bool QCborMap::operator<=(const QCborMap &lhs, const QCborMap &rhs)
1280
1281
Compares \a lhs and \a rhs maps, comparing each element in sequence, and
1282
returns true if \a lhs map should be sorted before \a rhs or
1283
if the two maps contain the same elements in the same order, false
1284
otherwise.
1285
1286
Note that CBOR maps are unordered, which means that two maps containing the
1287
very same pairs but in different order will still compare differently. To
1288
avoid this, it is recommended to insert elements into the map in a
1289
predictable order, such as by ascending key value. In fact, maps with keys
1290
in sorted order are required for Canonical CBOR representation.
1291
1292
For more information on CBOR sorting order, see QCborValue::compare().
1293
1294
\sa compare(), QCborValue::operator==(), QCborMap::operator==(),
1295
operator==(), operator!=()
1296
*/
1297
1298
/*!
1299
\fn bool QCborMap::operator>=(const QCborMap &lhs, const QCborMap &rhs)
1300
1301
Compares \a lhs and \a rhs maps, comparing each element in sequence, and
1302
returns true if \a lhs map should be sorted after \a rhs or
1303
if the two maps contain the same elements in the same order, false
1304
otherwise.
1305
1306
Note that CBOR maps are unordered, which means that two maps containing the
1307
very same pairs but in different order will still compare differently. To
1308
avoid this, it is recommended to insert elements into the map in a
1309
predictable order, such as by ascending key value. In fact, maps with keys
1310
in sorted order are required for Canonical CBOR representation.
1311
1312
For more information on CBOR sorting order, see QCborValue::compare().
1313
1314
\sa compare(), QCborValue::operator==(), QCborMap::operator==(),
1315
operator==(), operator!=()
1316
*/
1317
1318
/*!
1319
\fn bool QCborMap::operator>(const QCborMap &lhs, const QCborMap &rhs)
1320
1321
Compares \a lhs and \a rhs maps, comparing each element in sequence, and
1322
returns true if \a lhs map should be sorted after \a rhs, false
1323
otherwise.
1324
1325
Note that CBOR maps are unordered, which means that two maps containing the
1326
very same pairs but in different order will still compare differently. To
1327
avoid this, it is recommended to insert elements into the map in a
1328
predictable order, such as by ascending key value. In fact, maps with keys
1329
in sorted order are required for Canonical CBOR representation.
1330
1331
For more information on CBOR sorting order, see QCborValue::compare().
1332
1333
\sa compare(), QCborValue::operator==(), QCborMap::operator==(),
1334
operator==(), operator!=()
1335
*/
1336
1337
void
QCborMap::detach(qsizetype reserved)
1338
{
1339
d = QCborContainerPrivate::detach(d.data(), reserved ? reserved : size() * 2);
1340
}
1341
1342
/*!
1343
\class QCborMap::Iterator
1344
\inmodule QtCore
1345
\ingroup cbor
1346
\reentrant
1347
\since 5.12
1348
1349
\brief The QCborMap::Iterator class provides an STL-style non-const iterator for QCborMap.
1350
1351
\compares strong
1352
\compareswith strong ConstIterator
1353
\endcompareswith
1354
1355
QCborMap::Iterator allows you to iterate over a QCborMap and to modify the
1356
value (but not the key) stored under a particular key. If you want to
1357
iterate over a const QCborMap, you should use QCborMap::ConstIterator. It
1358
is generally good practice to use QCborMap::ConstIterator on a non-const
1359
QCborMap as well, unless you need to change the QCborMap through the
1360
iterator. Const iterators are slightly faster, and improve code
1361
readability.
1362
1363
You must initialize the iterator using a QCborMap function like
1364
QCborMap::begin(), QCborMap::end(), or QCborMap::find() before you can
1365
start iterating..
1366
1367
Multiple iterators can be used on the same object. Existing iterators will however
1368
become dangling once the object gets modified.
1369
1370
\sa QCborMap::ConstIterator
1371
*/
1372
1373
/*!
1374
\typedef QCborMap::Iterator::difference_type
1375
\internal
1376
*/
1377
1378
/*!
1379
\typedef QCborMap::Iterator::iterator_category
1380
1381
A synonym for \e {std::random_access_iterator_tag} indicating
1382
this iterator is a random-access iterator.
1383
*/
1384
1385
/*!
1386
\typedef QCborMap::Iterator::reference
1387
\internal
1388
*/
1389
1390
/*!
1391
\typedef QCborMap::Iterator::value_type
1392
\internal
1393
*/
1394
1395
/*!
1396
\typedef QCborMap::Iterator::pointer
1397
\internal
1398
*/
1399
1400
/*!
1401
\fn QCborMap::Iterator::Iterator()
1402
1403
Constructs an uninitialized iterator.
1404
1405
Functions like key(), value(), and operator++() must not be
1406
called on an uninitialized iterator. Use operator=() to assign a
1407
value to it before using it.
1408
1409
\sa QCborMap::begin(), QCborMap::end()
1410
*/
1411
1412
/*!
1413
\fn QCborMap::Iterator::Iterator(const Iterator &other)
1414
1415
Constructs an iterator as a copy of \a other.
1416
*/
1417
1418
/*!
1419
\fn QCborMap::Iterator &QCborMap::Iterator::operator=(const Iterator &other)
1420
1421
Makes this iterator a copy of \a other and returns a reference to this
1422
iterator.
1423
*/
1424
1425
/*!
1426
\fn QCborValue QCborMap::Iterator::key() const
1427
1428
Returns the current item's key.
1429
1430
There is no direct way of changing an item's key through an iterator,
1431
although it can be done by calling QCborMap::erase() followed by
1432
QCborMap::insert().
1433
1434
\sa value()
1435
*/
1436
1437
/*!
1438
\fn QCborValueRef QCborMap::Iterator::value() const
1439
1440
Returns a modifiable reference to the current item's value.
1441
1442
You can change the value for a key by using value() on the left side of an
1443
assignment.
1444
1445
The return value is of type QCborValueRef, a helper class for QCborArray
1446
and QCborMap. When you get an object of type QCborValueRef, you can use it
1447
as if it were a reference to a QCborValue. If you assign to it, the
1448
assignment will apply to the element in the QCborArray or QCborMap from
1449
which you got the reference.
1450
1451
\sa key(), operator*()
1452
*/
1453
1454
/*!
1455
\fn QCborMap::Iterator::value_type QCborMap::Iterator::operator*() const
1456
1457
Returns a pair containing the current item's key and a modifiable reference
1458
to the current item's value.
1459
1460
The second element of the pair is of type QCborValueRef, a helper class for
1461
QCborArray and QCborMap. When you get an object of type QCborValueRef, you
1462
can use it as if it were a reference to a QCborValue. If you assign to it,
1463
the assignment will apply to the element in the QCborArray or QCborMap from
1464
which you got the reference.
1465
1466
\sa key(), value()
1467
*/
1468
1469
/*!
1470
\fn QCborValueRef *QCborMap::Iterator::operator->() const
1471
1472
Returns a pointer to a modifiable reference to the current pair's value.
1473
*/
1474
1475
/*!
1476
\fn bool QCborMap::Iterator::operator==(const Iterator &lhs, const Iterator &rhs)
1477
\fn bool QCborMap::Iterator::operator==(const Iterator &lhs, const ConstIterator &rhs)
1478
1479
Returns \c true if \a lhs points to the same entry in the map as \a rhs
1480
iterator; otherwise returns \c false.
1481
1482
\sa operator!=()
1483
*/
1484
1485
/*!
1486
\fn bool QCborMap::Iterator::operator!=(const Iterator &lhs, const Iterator &rhs)
1487
\fn bool QCborMap::Iterator::operator!=(const Iterator &lhs, const ConstIterator &rhs)
1488
1489
Returns \c true if \a lhs points to a different entry in the map than
1490
\a rhs iterator; otherwise returns \c false.
1491
1492
\sa operator==()
1493
*/
1494
1495
/*!
1496
\fn bool QCborMap::Iterator::operator<(const Iterator &lhs, const Iterator &rhs)
1497
\fn bool QCborMap::Iterator::operator<(const Iterator &lhs, const ConstIterator &rhs)
1498
1499
Returns \c true if the entry in the map pointed to by \a lhs iterator
1500
occurs before the entry pointed to by the \a rhs iterator.
1501
*/
1502
1503
/*!
1504
\fn bool QCborMap::Iterator::operator<=(const Iterator &lhs, const Iterator &rhs)
1505
\fn bool QCborMap::Iterator::operator<=(const Iterator &lhs, const ConstIterator &rhs)
1506
1507
Returns \c true if the entry in the map pointed to by \a lhs iterator
1508
occurs before or is the same entry as is pointed to by the \a rhs
1509
iterator.
1510
*/
1511
1512
/*!
1513
\fn bool QCborMap::Iterator::operator>(const Iterator &lhs, const Iterator &rhs)
1514
\fn bool QCborMap::Iterator::operator>(const Iterator &lhs, const ConstIterator &rhs)
1515
1516
Returns \c true if the entry in the map pointed to by \a lhs iterator
1517
occurs after the entry pointed to by the \a rhs iterator.
1518
*/
1519
1520
/*!
1521
\fn bool QCborMap::Iterator::operator>=(const Iterator &lhs, const Iterator &rhs)
1522
\fn bool QCborMap::Iterator::operator>=(const Iterator &lhs, const ConstIterator &rhs)
1523
1524
Returns \c true if the entry in the map pointed to by \a lhs iterator
1525
occurs after or is the same entry as is pointed to by the \a rhs
1526
iterator.
1527
*/
1528
1529
/*!
1530
\fn QCborMap::Iterator &QCborMap::Iterator::operator++()
1531
1532
The prefix \c{++} operator, \c{++i}, advances the iterator to the next item in
1533
the map and returns this iterator.
1534
1535
Calling this function on QCborMap::end() leads to undefined results.
1536
1537
\sa operator--()
1538
*/
1539
1540
/*!
1541
\fn QCborMap::Iterator QCborMap::Iterator::operator++(int)
1542
\overload
1543
1544
The postfix \c{++} operator, \c{i++}, advances the iterator to the next item in
1545
the map and returns an iterator to the previously current item.
1546
*/
1547
1548
/*!
1549
\fn QCborMap::Iterator QCborMap::Iterator::operator--()
1550
1551
The prefix \c{--} operator, \c{--i}, makes the preceding item current and
1552
returns this iterator.
1553
1554
Calling this function on QCborMap::begin() leads to undefined results.
1555
1556
\sa operator++()
1557
*/
1558
1559
/*!
1560
\fn QCborMap::Iterator QCborMap::Iterator::operator--(int)
1561
\overload
1562
1563
The postfix \c{--} operator, \c{i--}, makes the preceding item current and
1564
returns an iterator pointing to the previously current item.
1565
*/
1566
1567
/*!
1568
\fn QCborMap::Iterator QCborMap::Iterator::operator+(qsizetype j) const
1569
1570
Returns an iterator to the item at \a j positions forward from this
1571
iterator. If \a j is negative, the iterator goes backward.
1572
1573
\sa operator-()
1574
*/
1575
1576
/*!
1577
\fn QCborMap::Iterator QCborMap::Iterator::operator-(qsizetype j) const
1578
1579
Returns an iterator to the item at \a j positions backward from this
1580
iterator. If \a j is negative, the iterator goes forward.
1581
1582
\sa operator+()
1583
*/
1584
1585
/*!
1586
\fn qsizetype QCborMap::Iterator::operator-(QCborMap::Iterator j) const
1587
1588
Returns the position of the item at iterator \a j relative to the item
1589
at this iterator. If the item at \a j is forward of this time, the returned
1590
value is negative.
1591
1592
\sa operator+()
1593
*/
1594
1595
/*!
1596
\fn QCborMap::Iterator &QCborMap::Iterator::operator+=(qsizetype j)
1597
1598
Advances the iterator by \a j items. If \a j is negative, the iterator goes
1599
backward. Returns a reference to this iterator.
1600
1601
\sa operator-=(), operator+()
1602
*/
1603
1604
/*!
1605
\fn QCborMap::Iterator &QCborMap::Iterator::operator-=(qsizetype j)
1606
1607
Makes the iterator go back by \a j items. If \a j is negative, the iterator
1608
goes forward. Returns a reference to this iterator.
1609
1610
\sa operator+=(), operator-()
1611
*/
1612
1613
/*!
1614
\class QCborMap::ConstIterator
1615
\inmodule QtCore
1616
\ingroup cbor
1617
\since 5.12
1618
1619
\brief The QCborMap::ConstIterator class provides an STL-style const iterator for QCborMap.
1620
1621
\compares strong
1622
\compareswith strong Iterator
1623
\endcompareswith
1624
1625
QCborMap::ConstIterator allows you to iterate over a QCborMap. If you want
1626
to modify the QCborMap as you iterate over it, you must use
1627
QCborMap::Iterator instead. It is generally good practice to use
1628
QCborMap::ConstIterator, even on a non-const QCborMap, when you don't need
1629
to change the QCborMap through the iterator. Const iterators are slightly
1630
faster and improve code readability.
1631
1632
You must initialize the iterator using a QCborMap function like
1633
QCborMap::begin(), QCborMap::end(), or QCborMap::find() before you can
1634
start iterating..
1635
1636
Multiple iterators can be used on the same object. Existing iterators
1637
will however become dangling if the object gets modified.
1638
1639
\sa QCborMap::Iterator
1640
*/
1641
1642
/*!
1643
\typedef QCborMap::ConstIterator::difference_type
1644
\internal
1645
*/
1646
1647
/*!
1648
\typedef QCborMap::ConstIterator::iterator_category
1649
1650
A synonym for \e {std::random_access_iterator_tag} indicating
1651
this iterator is a random-access iterator.
1652
*/
1653
1654
/*!
1655
\typedef QCborMap::ConstIterator::reference
1656
\internal
1657
*/
1658
1659
/*!
1660
\typedef QCborMap::ConstIterator::value_type
1661
\internal
1662
*/
1663
1664
/*!
1665
\typedef QCborMap::ConstIterator::pointer
1666
\internal
1667
*/
1668
1669
/*!
1670
\fn QCborMap::ConstIterator::ConstIterator()
1671
1672
Constructs an uninitialized iterator.
1673
1674
Functions like key(), value(), and operator++() must not be
1675
called on an uninitialized iterator. Use operator=() to assign a
1676
value to it before using it.
1677
1678
\sa QCborMap::constBegin(), QCborMap::constEnd()
1679
*/
1680
1681
/*!
1682
\fn QCborMap::ConstIterator::ConstIterator(const ConstIterator &other)
1683
1684
Constructs an iterator as a copy of \a other.
1685
*/
1686
1687
/*!
1688
\fn QCborMap::ConstIterator &QCborMap::ConstIterator::operator=(const ConstIterator &other)
1689
1690
Makes this iterator a copy of \a other and returns a reference to this
1691
iterator.
1692
*/
1693
1694
/*!
1695
\fn QString QCborMap::ConstIterator::key() const
1696
1697
Returns the current item's key.
1698
1699
\sa value()
1700
*/
1701
1702
/*!
1703
\fn QCborValue QCborMap::ConstIterator::value() const
1704
1705
Returns the current item's value.
1706
1707
\sa key(), operator*()
1708
*/
1709
1710
/*!
1711
\fn QCborMap::ConstIterator::value_type QCborMap::ConstIterator::operator*() const
1712
1713
Returns a pair containing the current item's key and value.
1714
1715
\sa key(), value()
1716
*/
1717
1718
/*!
1719
\fn const QCborValueRef *QCborMap::ConstIterator::operator->() const
1720
1721
Returns a pointer to the current pair's value.
1722
*/
1723
1724
/*!
1725
\fn bool QCborMap::ConstIterator::operator==(const ConstIterator &lhs, const ConstIterator &rhs)
1726
1727
Returns \c true if \a lhs points to the same entry in the map as \a rhs
1728
iterator; otherwise returns \c false.
1729
1730
\sa operator!=()
1731
*/
1732
1733
/*!
1734
\fn bool QCborMap::ConstIterator::operator!=(const ConstIterator &lhs, const ConstIterator &rhs)
1735
1736
Returns \c true if \a lhs points to a different entry in the map than
1737
\a rhs iterator; otherwise returns \c false.
1738
1739
\sa operator==()
1740
*/
1741
1742
/*!
1743
\fn bool QCborMap::ConstIterator::operator<(const ConstIterator &lhs, const ConstIterator &rhs)
1744
1745
Returns \c true if the entry in the map pointed to by \a lhs iterator
1746
occurs before the entry pointed to by the \a rhs iterator.
1747
*/
1748
1749
/*!
1750
\fn bool QCborMap::ConstIterator::operator<=(const ConstIterator &lhs, const ConstIterator &rhs)
1751
1752
Returns \c true if the entry in the map pointed to by \a lhs iterator
1753
occurs before or is the same entry as is pointed to by the \a rhs
1754
iterator.
1755
*/
1756
1757
/*!
1758
\fn bool QCborMap::ConstIterator::operator>(const ConstIterator &lhs, const ConstIterator &rhs)
1759
1760
Returns \c true if the entry in the map pointed to by \a lhs iterator
1761
occurs after the entry pointed to by the \a rhs iterator.
1762
*/
1763
1764
/*!
1765
\fn bool QCborMap::ConstIterator::operator>=(const ConstIterator &lhs, const ConstIterator &rhs)
1766
1767
Returns \c true if the entry in the map pointed to by \a lhs iterator
1768
occurs after or is the same entry as is pointed to by the \a rhs
1769
iterator.
1770
*/
1771
1772
/*!
1773
\fn QCborMap::ConstIterator &QCborMap::ConstIterator::operator++()
1774
1775
The prefix \c{++} operator, \c{++i}, advances the iterator to the next item in
1776
the map and returns this iterator.
1777
1778
Calling this function on QCborMap::end() leads to undefined results.
1779
1780
\sa operator--()
1781
*/
1782
1783
/*!
1784
\fn QCborMap::ConstIterator QCborMap::ConstIterator::operator++(int)
1785
\overload
1786
1787
The postfix \c{++} operator, \c{i++}, advances the iterator to the next item in
1788
the map and returns an iterator to the previously current item.
1789
*/
1790
1791
/*!
1792
\fn QCborMap::ConstIterator &QCborMap::ConstIterator::operator--()
1793
1794
The prefix \c{--} operator, \c{--i}, makes the preceding item current and
1795
returns this iterator.
1796
1797
Calling this function on QCborMap::begin() leads to undefined results.
1798
1799
\sa operator++()
1800
*/
1801
1802
/*!
1803
\fn QCborMap::ConstIterator QCborMap::ConstIterator::operator--(int)
1804
\overload
1805
1806
The postfix \c{--} operator, \c{i--}, makes the preceding item current and
1807
returns an iterator pointing to the previously current item.
1808
*/
1809
1810
/*!
1811
\fn QCborMap::ConstIterator QCborMap::ConstIterator::operator+(qsizetype j) const
1812
1813
Returns an iterator to the item at \a j positions forward from this
1814
iterator. If \a j is negative, the iterator goes backward.
1815
1816
\sa operator-()
1817
*/
1818
1819
/*!
1820
\fn QCborMap::ConstIterator QCborMap::ConstIterator::operator-(qsizetype j) const
1821
1822
Returns an iterator to the item at \a j positions backward from this
1823
iterator. If \a j is negative, the iterator goes forward.
1824
1825
\sa operator+()
1826
*/
1827
1828
/*!
1829
\fn qsizetype QCborMap::ConstIterator::operator-(QCborMap::ConstIterator j) const
1830
1831
Returns the position of the item at iterator \a j relative to the item
1832
at this iterator. If the item at \a j is forward of this time, the returned
1833
value is negative.
1834
1835
\sa operator+()
1836
*/
1837
1838
/*!
1839
\fn QCborMap::ConstIterator &QCborMap::ConstIterator::operator+=(qsizetype j)
1840
1841
Advances the iterator by \a j items. If \a j is negative, the iterator goes
1842
backward. Returns a reference to this iterator.
1843
1844
\sa operator-=(), operator+()
1845
*/
1846
1847
/*!
1848
\fn QCborMap::ConstIterator &QCborMap::ConstIterator::operator-=(qsizetype j)
1849
1850
Makes the iterator go back by \a j items. If \a j is negative, the iterator
1851
goes forward. Returns a reference to this iterator.
1852
1853
\sa operator+=(), operator-()
1854
*/
1855
1856
size_t
qHash
(
const
QCborMap &map, size_t seed)
1857
{
1858
return
qHashRange(map.begin(), map.end(), seed);
1859
}
1860
1861
#
if
!
defined
(
QT_NO_DEBUG_STREAM
)
1862
QDebug
operator
<<(QDebug dbg,
const
QCborMap &m)
1863
{
1864
QDebugStateSaver saver(dbg);
1865
dbg.nospace() <<
"QCborMap{"
;
1866
const
char
*open =
"{"
;
1867
for
(
auto
pair : m) {
1868
dbg << open << pair.first <<
", "
<< pair.second <<
'}'
;
1869
open =
", {"
;
1870
}
1871
return
dbg <<
'}'
;
1872
}
1873
#
endif
1874
1875
#
ifndef
QT_NO_DATASTREAM
1876
#
if
QT_CONFIG
(
cborstreamwriter
)
1877
QDataStream &operator<<(QDataStream &stream,
const
QCborMap &value)
1878
{
1879
stream << value.toCborValue().toCbor();
1880
return
stream;
1881
}
1882
#
endif
1883
1884
QDataStream &
operator
>>(QDataStream &stream, QCborMap &value)
1885
{
1886
QByteArray buffer;
1887
stream >> buffer;
1888
QCborParserError
parseError{};
1889
value = QCborValue::fromCbor(buffer, &parseError).toMap();
1890
if
(parseError.error)
1891
stream.setStatus(QDataStream::ReadCorruptData);
1892
return
stream;
1893
}
1894
#
endif
1895
1896
QT_END_NAMESPACE
QCborContainerPrivate
Definition
qcborvalue_p.h:101
QCborContainerPrivate::findOrAddMapKey
static QCborValueRef findOrAddMapKey(QCborMap &map, KeyType key)
Definition
qcbormap.cpp:881
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
operator<<
QDebug operator<<(QDebug dbg, const QCborMap &m)
Definition
qcbormap.cpp:1862
qHash
size_t qHash(const QCborMap &map, size_t seed)
Definition
qcbormap.cpp:1856
operator>>
QDataStream & operator>>(QDataStream &stream, QCborMap &value)
Definition
qcbormap.cpp:1884
QCborParserError
\inmodule QtCore\reentrant
Definition
qcborvalue.h:38
qtbase
src
corelib
serialization
qcbormap.cpp
Generated on
for Qt by
1.18.0