QCborMap Class
The QCborMap class is used to hold an associative container representable in CBOR. More…
| Header | #include <QCborMap> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Since | 5.12 |
List of all members, including inherited members
Public Types
| typedef | value_type |
| typedef | key_type |
| typedef | mapped_type |
| typedef | size_type |
| typedef | iterator |
| typedef | const_iterator |
Public Functions
Static Public Members
| QCborMap | fromVariantMap(const QVariantMap &map) |
| QCborMap | fromVariantHash(const QVariantHash &hash) |
| QCborMap | fromJsonObject(const QJsonObject &o) |
Detailed Description
A QCborMap holds pairs of a key and a value, both QCborValue. Keys are usually strings or integers but may be of any type. The pairs keep the order in which they were added, and a key is found by going through them, so a map is meant for the small objects of a data format and not as a large dictionary.
QCborMap map{{u"name"_s, u"Nt"_s}, {1, true}};
map[u"version"_s] = 6;
for (auto [key, value] : map)
qDebug() << key.toDiagnosticNotation() << value.toDiagnosticNotation();
Reading a key that the map does not have gives undefined; the operator[] that is not const adds it.
See also QCborArray and QCborValue.
Differences from Qt
Copies are deep: a copy of a map copies its pairs, which share their own strings and containers. Keys are compared with QCborValue::compare(), so the integer 1 and the floating-point number 1.0 are different keys. There is no QDebug operator, and no QDataStream operators.
Member Type Documentation
typedef QCborMap::const_iterator
The same as ConstIterator.
typedef QCborMap::iterator
The same as Iterator.
typedef QCborMap::key_type
The type of the keys.
typedef QCborMap::mapped_type
The type of the values.
typedef QCborMap::size_type
The type of a size.
typedef QCborMap::value_type
A pair of a key and a value.
Member Function Documentation
QCborMap::QCborMap()
Constructs an empty map.
QCborMap::QCborMap(std::initializer_list<value_type> args)
Constructs a map of the pairs in args. A key that comes twice keeps the value of the first pair.
QCborMap::QCborMap(const QCborMap &other)
Constructs a copy of other.
QCborMap::QCborMap(QCborMap &&other)
Move-constructs a map from other, which becomes empty.
QCborMap::~QCborMap()
Destroys the map.
Iterator QCborMap::begin()
Returns an iterator to the first pair.
ConstIterator QCborMap::begin() const
This is an overloaded function.
ConstIterator QCborMap::cbegin() const
Same as constBegin().
ConstIterator QCborMap::cend() const
Same as constEnd().
void QCborMap::clear()
Removes all pairs.
int QCborMap::compare(const QCborMap &other) const
Compares this map with other: a smaller map comes first, and maps of the same size are compared pair by pair, key and then value. Returns a negative number, 0 or a positive number.
See also QCborValue::compare().
ConstIterator QCborMap::constBegin() const
Returns a const iterator to the first pair.
ConstIterator QCborMap::constEnd() const
Returns a const iterator past the last pair.
ConstIterator QCborMap::constFind(qint64 key) const
Returns a const iterator to the pair of key, or constEnd() if the map has no such key.
ConstIterator QCborMap::constFind(QLatin1StringView key) const
This is an overloaded function.
Returns a const iterator to the pair of key, or constEnd().
ConstIterator QCborMap::constFind(const QString &key) const
This is an overloaded function.
Returns a const iterator to the pair of key, or constEnd().
ConstIterator QCborMap::constFind(const QCborValue &key) const
This is an overloaded function.
Returns a const iterator to the pair of key, or constEnd().
bool QCborMap::contains(qint64 key) const
Returns true if the map has key.
bool QCborMap::contains(QLatin1StringView key) const
This is an overloaded function.
Returns true if the map has key.
bool QCborMap::contains(const QString &key) const
This is an overloaded function.
Returns true if the map has key.
bool QCborMap::contains(const QCborValue &key) const
This is an overloaded function.
Returns true if the map has key.
bool QCborMap::empty() const
Returns true if the map has no pairs.
Iterator QCborMap::end()
Returns an iterator past the last pair.
ConstIterator QCborMap::end() const
This is an overloaded function.
Iterator QCborMap::erase(Iterator it)
Removes the pair at it and returns an iterator to the pair after it.
Iterator QCborMap::erase(ConstIterator it)
This is an overloaded function.
Removes the pair at it and returns an iterator to the pair after it.
QCborValue QCborMap::extract(Iterator it)
Removes the pair at it and returns its value.
QCborValue QCborMap::extract(ConstIterator it)
This is an overloaded function.
Removes the pair at it and returns its value.
Iterator QCborMap::find(qint64 key)
Returns an iterator to the pair of key, or end() if the map has no such key.
Iterator QCborMap::find(QLatin1StringView key)
This is an overloaded function.
Returns an iterator to the pair of key, or end().
Iterator QCborMap::find(const QString &key)
This is an overloaded function.
Returns an iterator to the pair of key, or end().
Iterator QCborMap::find(const QCborValue &key)
This is an overloaded function.
Returns an iterator to the pair of key, or end().
ConstIterator QCborMap::find(qint64 key) const
This is an overloaded function.
Returns a const iterator to the pair of key, or end().
ConstIterator QCborMap::find(QLatin1StringView key) const
This is an overloaded function.
Returns a const iterator to the pair of key, or end().
ConstIterator QCborMap::find(const QString &key) const
This is an overloaded function.
Returns a const iterator to the pair of key, or end().
ConstIterator QCborMap::find(const QCborValue &key) const
This is an overloaded function.
Returns a const iterator to the pair of key, or end().
QCborMap QCborMap::fromJsonObject(const QJsonObject &o)
Returns a map of the pairs in o, with the values converted by QCborValue::fromJsonValue().
QCborMap QCborMap::fromVariantHash(const QVariantHash &hash)
Returns a map of the pairs in hash, with the values converted by QCborValue::fromVariant(). The order of the pairs is that of the hash.
QCborMap QCborMap::fromVariantMap(const QVariantMap &map)
Returns a map of the pairs in map, with the values converted by QCborValue::fromVariant().
Iterator QCborMap::insert(qint64 key, const QCborValue &value)
Sets the value of key to value, adding the key if the map has none, and returns an iterator to the pair.
Iterator QCborMap::insert(QLatin1StringView key, const QCborValue &value)
This is an overloaded function.
Sets the value of key to value and returns an iterator to the pair.
Iterator QCborMap::insert(const QString &key, const QCborValue &value)
This is an overloaded function.
Sets the value of key to value and returns an iterator to the pair.
Iterator QCborMap::insert(const QCborValue &key, const QCborValue &value)
This is an overloaded function.
Sets the value of key to value and returns an iterator to the pair.
Iterator QCborMap::insert(const value_type &v)
This is an overloaded function.
Adds the pair v, or sets the value of its key if the map has the key, and returns an iterator to the pair.
bool QCborMap::isEmpty() const
Returns true if the map has no pairs.
QList<QCborValue> QCborMap::keys() const
Returns the keys, in the order of the pairs.
QCborMap & QCborMap::operator=(const QCborMap &other)
Assigns other to this map and returns a reference to it.
QCborMap & QCborMap::operator=(QCborMap &&other)
Move-assigns other to this map and returns a reference to it.
const QCborValue QCborMap::operator[](qint64 key) const
Returns the value of key, or undefined if the map has no such key.
const QCborValue QCborMap::operator[](QLatin1StringView key) const
This is an overloaded function.
Returns the value of key, or undefined.
const QCborValue QCborMap::operator[](const QString &key) const
This is an overloaded function.
Returns the value of key, or undefined.
const QCborValue QCborMap::operator[](const QCborValue &key) const
This is an overloaded function.
Returns the value of key, or undefined.
QCborValueRef QCborMap::operator[](qint64 key)
Returns a reference to the value of key. If the map has no such key, it is added with an undefined value.
QCborValueRef QCborMap::operator[](QLatin1StringView key)
This is an overloaded function.
Returns a reference to the value of key, which is added if the map has none.
QCborValueRef QCborMap::operator[](const QString &key)
This is an overloaded function.
Returns a reference to the value of key, which is added if the map has none.
QCborValueRef QCborMap::operator[](const QCborValue &key)
This is an overloaded function.
Returns a reference to the value of key, which is added if the map has none.
void QCborMap::remove(qint64 key)
Removes key and its value, if the map has the key.
void QCborMap::remove(QLatin1StringView key)
This is an overloaded function.
Removes key and its value.
void QCborMap::remove(const QString &key)
This is an overloaded function.
Removes key and its value.
void QCborMap::remove(const QCborValue &key)
This is an overloaded function.
Removes key and its value.
qsizetype QCborMap::size() const
Returns the number of pairs.
void QCborMap::swap(QCborMap &other)
Exchanges this map with other.
QCborValue QCborMap::take(qint64 key)
Removes key and returns its value, or returns undefined if the map has no such key.
QCborValue QCborMap::take(QLatin1StringView key)
This is an overloaded function.
Removes key and returns its value.
QCborValue QCborMap::take(const QString &key)
This is an overloaded function.
Removes key and returns its value.
QCborValue QCborMap::take(const QCborValue &key)
This is an overloaded function.
Removes key and returns its value.
QCborValue QCborMap::toCborValue() const
Returns the map as a QCborValue.
QJsonObject QCborMap::toJsonObject() const
Returns the pairs as a QJsonObject, with the values converted by QCborValue::toJsonValue() and the keys converted to text as toVariantMap() does.
QVariantHash QCborMap::toVariantHash() const
Returns the pairs as a QVariantHash, converted as toVariantMap() does.
QVariantMap QCborMap::toVariantMap() const
Returns the pairs as a QVariantMap, with the values converted by QCborValue::toVariant() and keys that are not strings converted to text: an integer in decimal, a byte array in Base64url, and anything else in the diagnostic notation. Of keys that give the same text the last one counts.
QCborValue QCborMap::value(qint64 key) const
Returns the value of key, or undefined if the map has no such key.
QCborValue QCborMap::value(QLatin1StringView key) const
This is an overloaded function.
Returns the value of key, or undefined.
QCborValue QCborMap::value(const QString &key) const
This is an overloaded function.
Returns the value of key, or undefined.
QCborValue QCborMap::value(const QCborValue &key) const
This is an overloaded function.
Returns the value of key, or undefined.