Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "qcbormap.h"
5#include "qcborvalue_p.h"
6
8
9using namespace QtCbor;
10
174 : d(nullptr)
175{
176}
177
182 : d(other.d)
183{
184}
185
208
214{
215 d = other.d;
216 return *this;
217}
218
252qsizetype QCborMap::size() const noexcept
253{
254 return d ? d->elements.size() / 2 : 0;
255}
256
263{
264 d.reset();
265}
266
272QList<QCborValue> QCborMap::keys() const
273{
274 QList<QCborValue> result;
275 if (d) {
276 result.reserve(size());
277 for (qsizetype i = 0; i < d->elements.size(); i += 2)
278 result << d->valueAt(i);
279 }
280 return result;
281}
282
396{
398}
399
523
647
764{
765 return QCborContainerPrivate::findOrAddMapKey<const QCborValue &>(*this, key);
766}
767
768template <typename KeyType> inline QCborValueRef
770{
771 QCborValueRef result = findOrAddMapKey<KeyType>(map.d.data(), key);
772 map.d = result.d;
773 return result;
774}
775
796{
797 detach();
798 auto it = constFind(key);
799 return { d.data(), it.item.i };
800}
801
821{
822 detach();
823 auto it = constFind(key);
824 return { d.data(), it.item.i };
825}
826
846{
847 detach();
848 auto it = constFind(key);
849 return { d.data(), it.item.i };
850}
851
871{
872 detach();
873 auto it = constFind(key);
874 return { d.data(), it.item.i };
875}
876
897
918
939
957{
958 return d ? d->findCborMapKey<const QCborValue &>(key) : constEnd();
959}
960
1049{
1050 detach();
1051
1052 // remove both key and value
1053 // ### optimize?
1054 d->removeAt(it.item.i - 1);
1055 d->removeAt(it.item.i - 1);
1056 return it;
1057}
1058
1069{
1070 detach();
1071 QCborValue v = d->extractAt(it.item.i);
1072 // remove both key and value
1073 // ### optimize?
1074 d->removeAt(it.item.i - 1);
1075 d->removeAt(it.item.i - 1);
1076
1077 return v;
1078}
1079
1227void QCborMap::detach(qsizetype reserved)
1228{
1229 d = QCborContainerPrivate::detach(d.data(), reserved ? reserved : size() * 2);
1230}
1231
1746size_t qHash(const QCborMap &map, size_t seed)
1747{
1748 return qHashRange(map.begin(), map.end(), seed);
1749}
1750
1751#if !defined(QT_NO_DEBUG_STREAM)
1753{
1754 QDebugStateSaver saver(dbg);
1755 dbg.nospace() << "QCborMap{";
1756 const char *open = "{";
1757 for (auto pair : m) {
1758 dbg << open << pair.first << ", " << pair.second << '}';
1759 open = ", {";
1760 }
1761 return dbg << '}';
1762}
1763#endif
1764
1765#ifndef QT_NO_DATASTREAM
1766#if QT_CONFIG(cborstreamwriter)
1768{
1769 stream << value.toCborValue().toCbor();
1770 return stream;
1771}
1772#endif
1773
1775{
1777 stream >> buffer;
1778 QCborParserError parseError{};
1779 value = QCborValue::fromCbor(buffer, &parseError).toMap();
1780 if (parseError.error)
1781 stream.setStatus(QDataStream::ReadCorruptData);
1782 return stream;
1783}
1784#endif
1785
\inmodule QtCore
Definition qbytearray.h:57
static QCborContainerPrivate * detach(QCborContainerPrivate *d, qsizetype reserved)
void removeAt(qsizetype idx)
QCborValueConstRef findCborMapKey(KeyType key)
QList< QtCbor::Element > elements
QCborValue extractAt(qsizetype idx)
static QCborValueRef findOrAddMapKey(QCborContainerPrivate *container, KeyType key)
QCborValue valueAt(qsizetype idx) const
\inmodule QtCore
Definition qcbormap.h:137
\inmodule QtCore\reentrant
Definition qcbormap.h:29
\inmodule QtCore\reentrant
Definition qcbormap.h:21
QList< QCborValue > keys() const
Returns a list of all keys in this map.
Definition qcbormap.cpp:272
iterator erase(iterator it)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_iterator constFind(qint64 key) const
Returns a map iterator to the key-value pair whose key is key, if the map contains such a pair.
Definition qcbormap.cpp:893
QCborValue extract(iterator it)
QCborMap & operator=(const QCborMap &other) noexcept
Replaces the contents of this object with a copy of other, then returns a reference to this object.
Definition qcbormap.cpp:213
void clear()
Empties this map.
Definition qcbormap.cpp:262
QCborMap() noexcept
Constructs an empty CBOR Map object.
Definition qcbormap.cpp:173
iterator find(qint64 key)
Definition qcbormap.cpp:795
~QCborMap()
Destroys this QCborMap object and frees any associated resources it owns.
Definition qcbormap.cpp:205
const QCborValue operator[](qint64 key) const
Returns the QCborValue element in this map that corresponds to key key, if there is one.
Definition qcbormap.h:260
const_iterator constEnd() const
Returns a map iterator representing an element just past the last element in the map.
Definition qcbormap.h:319
qsizetype size() const noexcept Q_DECL_PURE_FUNCTION
Returns the number of elements in this map.
Definition qcbormap.cpp:252
\inmodule QtCore\reentrant
Definition qcborvalue.h:47
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
void reset(T *ptr=nullptr) noexcept
T * data() const noexcept
Returns a pointer to the shared data object.
qsizetype size() const noexcept
Definition qlist.h:397
iterator begin()
Definition qmap.h:598
iterator end()
Definition qmap.h:602
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QMap< QString, QString > map
[6]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QCborMap &m)
size_t qHash(const QCborMap &map, size_t seed)
QDataStream & operator>>(QDataStream &stream, QCborMap &value)
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
size_t qHashRange(InputIterator first, InputIterator last, size_t seed=0) noexcept(noexcept(qHash(*first)))
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint buffer
GLuint64EXT * result
[6]
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
file open(QIODevice::ReadOnly)
QSharedPointer< T > other(t)
[5]
\inmodule QtCore\reentrant
Definition qcborvalue.h:37