![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore\reentrant More...
#include <qcborvalue.h>
Public Types | |
enum | EncodingOption { SortKeysInMaps = 0x01 , UseFloat = 0x02 , UseFloat16 = UseFloat | 0x04 , UseIntegers = 0x08 , NoTransformation = 0 } |
This enum is used in the options argument to toCbor(), modifying the behavior of the encoder. More... | |
enum | DiagnosticNotationOption { Compact = 0x00 , LineWrapped = 0x01 , ExtendedFormat = 0x02 } |
This enum is used in the option argument to toDiagnosticNotation(), to modify the output format. More... | |
enum | Type : int { Integer = 0x00 , ByteArray = 0x40 , String = 0x60 , Array = 0x80 , Map = 0xa0 , Tag = 0xc0 , SimpleType = 0x100 , False = SimpleType + int(QCborSimpleType::False) , True = SimpleType + int(QCborSimpleType::True) , Null = SimpleType + int(QCborSimpleType::Null) , Undefined = SimpleType + int(QCborSimpleType::Undefined) , Double = 0x202 , DateTime = 0x10000 , Url = 0x10020 , RegularExpression = 0x10023 , Uuid = 0x10025 , Invalid = -1 } |
This enum represents the QCborValue type. More... | |
Public Member Functions | |
QCborValue () | |
Creates a QCborValue of the \l {Type}{Undefined} type. | |
QCborValue (Type t_) | |
Creates a QCborValue of type t_. | |
QCborValue (std::nullptr_t) | |
Creates a QCborValue of the \l {Type}{Null} type. | |
QCborValue (bool b_) | |
Creates a QCborValue with boolean value b. | |
QCborValue (int i) | |
QCborValue (unsigned u) | |
QCborValue (qint64 i) | |
Creates a QCborValue with integer value i. | |
QCborValue (double v) | |
Creates a QCborValue with floating point value d. | |
QCborValue (QCborSimpleType st) | |
Creates a QCborValue of simple type st. | |
QCborValue (const QByteArray &ba) | |
Creates a QCborValue with byte array value ba. | |
QCborValue (const QString &s) | |
Creates a QCborValue with string value s. | |
QCborValue (QStringView s) | |
Creates a QCborValue with string value s. | |
QCborValue (QLatin1StringView s) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue with the Latin-1 string viewed by s. | |
QT_ASCII_CAST_WARN | QCborValue (const char *s) |
QCborValue (const QCborArray &a) | |
QCborValue (QCborArray &&a) | |
Creates a QCborValue with the array a. | |
QCborValue (const QCborMap &m) | |
QCborValue (QCborMap &&m) | |
Creates a QCborValue with the map m. | |
QCborValue (QCborTag tag, const QCborValue &taggedValue=QCborValue()) | |
QCborValue (QCborKnownTags t_, const QCborValue &tv=QCborValue()) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue for the extended type represented by the tag value tag, tagging value taggedValue. | |
QCborValue (const QDateTime &dt) | |
Creates a QCborValue object of the date/time extended type and containing the value represented by dt. | |
QCborValue (const QUrl &url) | |
Creates a QCborValue object of the URL extended type and containing the value represented by url. | |
QCborValue (const QUuid &uuid) | |
Creates a QCborValue object of the UUID extended type and containing the value represented by uuid. | |
~QCborValue () | |
Disposes of the current QCborValue object and frees any associated resources. | |
QCborValue (const void *)=delete | |
QCborValue (const QCborValue &other) noexcept | |
Copies the contents of other into this object. | |
QCborValue (QCborValue &&other) noexcept | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one. | |
QCborValue & | operator= (const QCborValue &other) noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one. | |
void | swap (QCborValue &other) noexcept |
Swaps the contents of this QCborValue object and other. | |
Type | type () const |
Returns the type of this QCborValue. | |
bool | isInteger () const |
Returns true if this QCborValue is of the integer type. | |
bool | isByteArray () const |
Returns true if this QCborValue is of the byte array type. | |
bool | isString () const |
Returns true if this QCborValue is of the string type. | |
bool | isArray () const |
Returns true if this QCborValue is of the array type. | |
bool | isMap () const |
Returns true if this QCborValue is of the map type. | |
bool | isTag () const |
Returns true if this QCborValue is of the tag type. | |
bool | isFalse () const |
Returns true if this QCborValue is a boolean with false value. | |
bool | isTrue () const |
Returns true if this QCborValue is a boolean with true value. | |
bool | isBool () const |
Returns true if this QCborValue is a boolean. | |
bool | isNull () const |
Returns true if this QCborValue is of the null type. | |
bool | isUndefined () const |
Returns true if this QCborValue is of the undefined type. | |
bool | isDouble () const |
Returns true if this QCborValue is of the floating-point type. | |
bool | isDateTime () const |
Returns true if this QCborValue is of the date/time type. | |
bool | isUrl () const |
Returns true if this QCborValue is of the URL type. | |
bool | isRegularExpression () const |
Returns true if this QCborValue contains a regular expression's pattern. | |
bool | isUuid () const |
Returns true if this QCborValue contains a UUID. | |
bool | isInvalid () const |
Returns true if this QCborValue is not of any valid type. | |
bool | isContainer () const |
This convenience function returns true if the QCborValue is either an array or a map. | |
bool | isSimpleType () const |
Returns true if this QCborValue is of one of the CBOR simple types. | |
bool | isSimpleType (QCborSimpleType st) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if this QCborValue is of a simple type and toSimpleType() would return st, false otherwise. | |
QCborSimpleType | toSimpleType (QCborSimpleType defaultValue=QCborSimpleType::Undefined) const |
Returns the simple type this QCborValue is of, if it is a simple type. | |
qint64 | toInteger (qint64 defaultValue=0) const |
Returns the integer value stored in this QCborValue, if it is of the integer type. | |
bool | toBool (bool defaultValue=false) const |
Returns the boolean value stored in this QCborValue, if it is of a boolean type. | |
double | toDouble (double defaultValue=0) const |
Returns the floating point value stored in this QCborValue, if it is of the Double type. | |
QCborTag | tag (QCborTag defaultValue=QCborTag(-1)) const |
Returns the tag of this extended QCborValue object, if it is of the tag type, defaultValue otherwise. | |
QCborValue | taggedValue (const QCborValue &defaultValue=QCborValue()) const |
Returns the tagged value of this extended QCborValue object, if it is of the tag type, defaultValue otherwise. | |
QByteArray | toByteArray (const QByteArray &defaultValue={}) const |
Returns the byte array value stored in this QCborValue, if it is of the byte array type. | |
QString | toString (const QString &defaultValue={}) const |
Returns the string value stored in this QCborValue, if it is of the string type. | |
QDateTime | toDateTime (const QDateTime &defaultValue={}) const |
Returns the date/time value stored in this QCborValue, if it is of the date/time extended type. | |
QUrl | toUrl (const QUrl &defaultValue={}) const |
Returns the URL value stored in this QCborValue, if it is of the URL extended type. | |
QUuid | toUuid (const QUuid &defaultValue={}) const |
Returns the UUID value stored in this QCborValue, if it is of the UUID extended type. | |
QCborArray | toArray () const |
QCborArray | toArray (const QCborArray &defaultValue) const |
Returns the array value stored in this QCborValue, if it is of the array type. | |
QCborMap | toMap () const |
QCborMap | toMap (const QCborMap &defaultValue) const |
Returns the map value stored in this QCborValue, if it is of the map type. | |
const QCborValue | operator[] (const QString &key) const |
If this QCborValue is a QCborMap, searches elements for the value whose key matches key. | |
const QCborValue | operator[] (QLatin1StringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key. | |
const QCborValue | operator[] (qint64 key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key. | |
QCborValueRef | operator[] (qint64 key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map or array, with the given key. | |
QCborValueRef | operator[] (QLatin1StringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key. | |
QCborValueRef | operator[] (const QString &key) |
Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key. | |
int | compare (const QCborValue &other) const |
Compares this value and other, and returns an integer that indicates whether this value should be sorted prior to (if the result is negative) or after other (if the result is positive). | |
bool | operator== (const QCborValue &other) const noexcept |
Compares this value and other, and returns true if they hold the same contents, false otherwise. | |
bool | operator!= (const QCborValue &other) const noexcept |
Compares this value and other, and returns true if contents differ, false otherwise. | |
bool | operator< (const QCborValue &other) const |
Compares this value and other, and returns true if this value should be sorted before other, false otherwise. | |
QVariant | toVariant () const |
Converts this value to a native Qt type and returns the corresponding QVariant. | |
QJsonValue | toJsonValue () const |
Converts this QCborValue object to an equivalent representation in JSON and returns it as a QJsonValue. | |
QString | toDiagnosticNotation (DiagnosticNotationOptions opts=Compact) const |
Creates the diagnostic notation equivalent of this CBOR object and returns it. | |
Static Public Member Functions | |
static QCborValue | fromVariant (const QVariant &variant) |
Converts the QVariant variant into QCborValue and returns it. | |
static QCborValue | fromJsonValue (const QJsonValue &v) |
Converts the JSON value contained in v into its corresponding CBOR value and returns it. | |
Friends | |
class | QCborValueRef |
class | QCborContainerPrivate |
class | QJsonPrivate::Value |
\inmodule QtCore
\reentrant
The QCborValue class encapsulates a value in CBOR.
This class can be used to hold one of the many types available in CBOR. CBOR is the Concise Binary Object Representation, a very compact form of binary data encoding that is a superset of JSON. It was created by the IETF Constrained RESTful Environments (CoRE) WG, which has used it in many new RFCs. It is meant to be used alongside the \l{RFC 7252}{CoAP protocol}.
CBOR has three groups of built-in types:
\list
Additionally, CBOR supports a form of type extensibility by associating a "tag" to one of the above types to convey more information. For example, a UUID is represented by a tag and a byte array containing the 16 bytes of the UUID content. QCborValue supports creating and decoding several of those extended types directly with Qt classes (like QUuid).
For the complete list, see \l QCborValue::Type. The type of a QCborValue can be queried using type() or one of the "isXxxx" functions.
Definition at line 49 of file qcborvalue.h.
This enum is used in the option argument to toDiagnosticNotation(), to modify the output format.
\value Compact Does not use any line-breaks, producing a compact representation. \value LineWrapped Uses line-breaks, one QCborValue per line. \value ExtendedFormat Uses some different options to represent values, not found in RFC 7049. Those options are subject to change.
Currently, ExtendedFormat
will change how byte arrays are represented. Without it, they are always hex-encoded and without spaces. With it, QCborValue::toCbor() will either use hex with spaces, base64 or base64url encoding, depending on the context.
Enumerator | |
---|---|
Compact | |
LineWrapped | |
ExtendedFormat |
Definition at line 65 of file qcborvalue.h.
This enum is used in the options argument to toCbor(), modifying the behavior of the encoder.
\omitvalue SortKeysInMaps \value NoTransformation (Default) Performs no transformations. \value UseFloat Tells the encoder to use IEEE 754 single-precision floating point (that is, float
) whenever possible. \value UseFloat16 Tells the encoder to use IEEE 754 half-precision floating point (that is, qfloat16
), whenever possible. Implies UseFloat
. \value UseIntegers Tells the encoder to use integers whenever a value of type \l {Type}{Double} contains an integer.
The use of UseFloat16
is required to encode the stream in Canonical Format, but is not otherwise necessary.
Enumerator | |
---|---|
SortKeysInMaps | |
UseFloat | |
UseFloat16 | |
UseIntegers | |
NoTransformation |
Definition at line 53 of file qcborvalue.h.
enum QCborValue::Type : int |
This enum represents the QCborValue type.
It is returned by the type() function.
The CBOR built-in types are:
\value Integer qint64:
An integer value \value ByteArray \l QByteArray: a byte array ("byte string") \value String \l QString: a Unicode string ("text string") \value Array \l QCborArray: an array of QCborValues \value Map \l QCborMap: an associative container of QCborValues \value SimpleType \l QCborSimpleType: one of several simple types/values \value False bool:
the simple type for value false
\value True bool:
the simple type for value true
\value Null std::nullptr_t:
the simple type for the null value \value Undefined (no type) the simple type for the undefined value \value Double double:
a double-precision floating point \value Invalid Not a valid value, this usually indicates a CBOR decoding error
Additionally, QCborValue can represent extended types:
\value Tag An unknown or unrecognized extended type, represented by its tag (a \l QCborTag) and the tagged value (a QCborValue) \value DateTime \l QDateTime: a date and time stamp \value Url \l QUrl: a URL or URI \value RegularExpression \l QRegularExpression: the pattern of a regular expression \value Uuid \l QUuid: a UUID
Enumerator | |
---|---|
Integer | |
ByteArray | |
String | |
Array | |
Map | |
Tag | |
SimpleType | |
False | |
True | |
Null | |
Undefined | |
Double | |
DateTime | |
Url | |
RegularExpression | |
Uuid | |
Invalid |
Definition at line 73 of file qcborvalue.h.
|
inline |
Creates a QCborValue of the \l {Type}{Undefined} type.
CBOR undefined values are used to indicate missing information, usually as a result of a previous operation that did not complete as expected. They are also used by the QCborArray and QCborMap API to indicate the searched item was not found.
Undefined values are represented by the \l {QCborSimpleType}{Undefined simple type}. Because of that, QCborValues with undefined values will also return true for isSimpleType() and {isSimpleType(QCborSimpleType::Undefined)}.
Undefined values are different from null values.
QCborValue objects with undefined values are also different from invalid QCborValue objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.
Definition at line 100 of file qcborvalue.h.
|
inline |
Creates a QCborValue of type t_.
The value associated with such a type (if any) will be default constructed.
Definition at line 101 of file qcborvalue.h.
|
inline |
Creates a QCborValue of the \l {Type}{Null} type.
CBOR null values are used to indicate optional values that were not provided. They are distinct from undefined values, in that null values are usually not the result of an earlier error or problem.
Definition at line 102 of file qcborvalue.h.
|
inline |
Creates a QCborValue with boolean value b.
The value can later be retrieved using toBool().
Internally, CBOR booleans are represented by a pair of types, one for true and one for false. For that reason, boolean QCborValues will return true for isSimpleType() and one of {isSimpleType(QCborSimpleType::False)} or
{isSimpleType(QCborSimpleType::True)}.
Definition at line 103 of file qcborvalue.h.
|
inline |
Definition at line 105 of file qcborvalue.h.
|
inline |
Definition at line 106 of file qcborvalue.h.
|
inline |
Creates a QCborValue with integer value i.
The value can later be retrieved using toInteger().
CBOR integer values are distinct from floating point values. Therefore, QCborValue objects with integers will compare differently to QCborValue objects containing floating-point, even if the values contained in the objects are equivalent.
Definition at line 108 of file qcborvalue.h.
|
inline |
Creates a QCborValue with floating point value d.
The value can later be retrieved using toDouble().
CBOR floating point values are distinct from integer values. Therefore, QCborValue objects with integers will compare differently to QCborValue objects containing floating-point, even if the values contained in the objects are equivalent.
Definition at line 109 of file qcborvalue.h.
|
inline |
Creates a QCborValue of simple type st.
The type can later be retrieved using toSimpleType() as well as isSimpleType(st).
CBOR simple types are types that do not have any associated value, like C++'s {std::nullptr_t} type, whose only possible value is \nullptr.
If st is {QCborSimpleType::Null}, the resulting QCborValue will be of the \l{Type}{Null} type and similarly for
{QCborSimpleType::Undefined}. If st is
{QCborSimpleType::False} or
{QCborSimpleType::True}, the created QCborValue will be a boolean containing a value of false or true, respectively.
This function can be used with simple types not defined in the API. For example, to create a QCborValue with simple type 12, one could write:
Simple types should not be used until a specification for them has been published, since other implementations may not support them properly. Simple type values 24 to 31 are reserved and must not be used.
isSimpleType(), isNull(), isUndefined(), isTrue(), isFalse()
Definition at line 110 of file qcborvalue.h.
QCborValue::QCborValue | ( | const QByteArray & | ba | ) |
Creates a QCborValue with byte array value ba.
The value can later be retrieved using toByteArray().
Definition at line 1715 of file qcborvalue.cpp.
References QCborContainerPrivate::appendByteData(), ba, QByteArray::constData(), QSharedData::ref, QByteArray::size(), and QBasicAtomicInteger< T >::storeRelaxed().
QCborValue::QCborValue | ( | const QString & | s | ) |
Creates a QCborValue with string value s.
The value can later be retrieved using toString().
Definition at line 1728 of file qcborvalue.cpp.
QCborValue::QCborValue | ( | QStringView | s | ) |
Creates a QCborValue with string value s.
The value can later be retrieved using toString().
Definition at line 1736 of file qcborvalue.cpp.
References QCborContainerPrivate::append(), QSharedData::ref, and QBasicAtomicInteger< T >::storeRelaxed().
QCborValue::QCborValue | ( | QLatin1StringView | s | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue with the Latin-1 string viewed by s.
The value can later be retrieved using toString().
Definition at line 1751 of file qcborvalue.cpp.
References QCborContainerPrivate::append(), QSharedData::ref, and QBasicAtomicInteger< T >::storeRelaxed().
|
inline |
Definition at line 117 of file qcborvalue.h.
QCborValue::QCborValue | ( | const QCborArray & | a | ) |
Definition at line 1767 of file qcborvalue.cpp.
References QBasicAtomicInteger< T >::ref(), and QSharedData::ref.
|
inline |
Creates a QCborValue with the array a.
The array can later be retrieved using toArray().
Definition at line 251 of file qcborarray.h.
QCborValue::QCborValue | ( | const QCborMap & | m | ) |
Definition at line 1783 of file qcborvalue.cpp.
References QBasicAtomicInteger< T >::ref(), and QSharedData::ref.
|
inline |
Creates a QCborValue with the map m.
The map can later be retrieved using toMap().
Definition at line 317 of file qcbormap.h.
QCborValue::QCborValue | ( | QCborTag | tag, |
const QCborValue & | taggedValue = QCborValue() |
||
) |
Definition at line 1800 of file qcborvalue.cpp.
References QCborContainerPrivate::append(), convertToExtendedType(), QSharedData::ref, QBasicAtomicInteger< T >::storeRelaxed(), and tag.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue for the extended type represented by the tag value tag, tagging value taggedValue.
Creates a QCborValue for the extended type represented by the tag value tag, tagging value tv.
The tag can later be retrieved using tag() and the tagged value using taggedValue().
Definition at line 124 of file qcborvalue.h.
|
explicit |
Creates a QCborValue object of the date/time extended type and containing the value represented by dt.
The value can later be retrieved using toDateTime().
The CBOR date/time types are extension types using tags: either a string (in ISO date format) tagged as a \l{QCborKnownTags}{DateTime} or a number (of seconds since the start of 1970, UTC) tagged as a \l{QCborKnownTags}{UnixTime_t}. When parsing CBOR streams, QCborValue will convert \l{QCborKnownTags}{UnixTime_t} to the string-based type.
Definition at line 1832 of file qcborvalue.cpp.
References DateTime, QCborContainerPrivate::elements, and String.
|
explicit |
Creates a QCborValue object of the URL extended type and containing the value represented by url.
The value can later be retrieved using toUrl().
The CBOR URL type is an extended type represented by a string tagged as an \l{QCborKnownTags}{Url}.
Definition at line 1850 of file qcborvalue.cpp.
References QCborContainerPrivate::elements, String, and Url.
|
explicit |
Creates a QCborValue object of the UUID extended type and containing the value represented by uuid.
The value can later be retrieved using toUuid().
The CBOR UUID type is an extended type represented by a byte array tagged as an \l{QCborKnownTags}{Uuid}.
Definition at line 1889 of file qcborvalue.cpp.
References Uuid.
|
inline |
Disposes of the current QCborValue object and frees any associated resources.
Definition at line 137 of file qcborvalue.h.
|
delete |
|
noexcept |
Copies the contents of other into this object.
Definition at line 1812 of file qcborvalue.cpp.
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one.
Definition at line 143 of file qcborvalue.h.
int QCborValue::compare | ( | const QCborValue & | other | ) | const |
Compares this value and other, and returns an integer that indicates whether this value should be sorted prior to (if the result is negative) or after other (if the result is positive).
If this function returns 0, the two values are equal and hold the same contents.
If each QCborValue contains an array or map, the comparison is recursive to elements contained in them.
Definition at line 1319 of file qcborvalue.cpp.
References compareElementRecursive(), QCborContainerPrivate::elementFromValue(), and other().
|
static |
Converts the JSON value contained in v into its corresponding CBOR value and returns it.
There is no data loss in converting from JSON to CBOR, as the CBOR type set is richer than JSON's. Additionally, values converted to CBOR using this function can be converted back to JSON using toJsonValue() with no data loss.
The following table lists the mapping of JSON types to CBOR types:
\table \header
\l QJsonValue can also be undefined, indicating a previous operation that failed to complete (for example, searching for a key not present in an object). Undefined values are not JSON types and may not appear in JSON arrays and objects, but this function does return the QCborValue undefined value if the corresponding QJsonValue is undefined.
Definition at line 610 of file qjsoncbor.cpp.
References QJsonValue::Array, QJsonValue::Bool, QJsonValue::Double, QCborArray::fromJsonArray(), QCborMap::fromJsonObject(), Integer, QJsonValue::Null, QJsonValue::Object, QJsonValue::String, and QJsonValue::Undefined.
Referenced by fromJson(), QJsonArray::insert(), QJsonArray::replace(), QJsonDocument::setArray(), and QJsonDocument::setObject().
|
static |
Converts the QVariant variant into QCborValue and returns it.
QVariants may contain a large list of different meta types, many of which have no corresponding representation in CBOR. That includes all user-defined meta types. When preparing transmission using CBOR, it is suggested to encode carefully each value to prevent loss of representation.
The following table lists the conversion this function will apply:
\table \header
bool
std::nullptr_t
short
, ushort
, int
, uint
, \l qint64 float
, double
If QVariant::isNull() returns true, a null QCborValue is returned or inserted into the list or object, regardless of the type carried by QVariant. Note the behavior change in Qt 6.0 affecting QVariant::isNull() also affects this function.
For other types not listed above, a conversion to string will be attempted, usually but not always by calling QVariant::toString(). If the conversion fails the value is replaced by an Undefined CBOR value. Note that QVariant::toString() is also lossy for the majority of types.
Please note that the conversions via QVariant::toString() are subject to change at any time. Both QVariant and QCborValue may be extended in the future to support more types, which will result in a change in how this function performs conversions.
Definition at line 702 of file qjsoncbor.cpp.
References QJsonDocument::array(), QCborArray::fromJsonArray(), QCborMap::fromJsonObject(), QCborArray::fromStringList(), QCborMap::fromVariantHash(), QCborArray::fromVariantList(), QCborMap::fromVariantMap(), QMetaType::id(), QJsonDocument::isArray(), QVariant::isNull(), QVariant::metaType(), QJsonDocument::object(), Q_FALLTHROUGH, QVariant::toBool(), QVariant::toByteArray(), QVariant::toDateTime(), QVariant::toDouble(), QVariant::toHash(), QVariant::toJsonArray(), QVariant::toJsonDocument(), QVariant::toJsonObject(), QVariant::toJsonValue(), QVariant::toList(), QVariant::toLongLong(), QVariant::toMap(), QVariant::toString(), QVariant::toStringList(), QVariant::toULongLong(), QVariant::toUrl(), QVariant::toUuid(), QMetaType::UnknownType, and variant.
Referenced by appendVariant().
|
inline |
Returns true if this QCborValue is of the array type.
The array value can be retrieved using toArray().
Definition at line 161 of file qcborvalue.h.
Referenced by operator[](), MetaTypesJsonProcessor::processTypes(), toArray(), and QmlTypeRegistrar::write().
|
inline |
Returns true if this QCborValue is a boolean.
The value can be retrieved using toBool().
Definition at line 166 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is of the byte array type.
The byte array value can be retrieved using toByteArray().
Definition at line 159 of file qcborvalue.h.
Referenced by toByteArray().
|
inline |
This convenience function returns true if the QCborValue is either an array or a map.
Definition at line 175 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is of the date/time type.
The value can be retrieved using toDateTime(). Date/times are extended types that use the tag \l{QCborKnownTags}{DateTime}.
Additionally, when decoding from a CBOR stream, QCborValue will interpret tags of value \l{QCborKnownTags}{UnixTime_t} and convert them to the equivalent date/time.
Definition at line 170 of file qcborvalue.h.
Referenced by toDateTime().
|
inline |
Returns true if this QCborValue is of the floating-point type.
The value can be retrieved using toDouble().
Definition at line 169 of file qcborvalue.h.
References Double.
|
inline |
Returns true if this QCborValue is a boolean with false value.
This function exists because, internally, CBOR booleans are stored as two separate types, one for true and one for false.
Definition at line 164 of file qcborvalue.h.
References False.
|
inline |
Returns true if this QCborValue is of the integer type.
The integer value can be retrieved using toInteger().
Definition at line 158 of file qcborvalue.h.
References Integer.
|
inline |
Returns true if this QCborValue is not of any valid type.
Invalid QCborValues are distinct from those with undefined values and they usually represent a decoding error.
Definition at line 174 of file qcborvalue.h.
References Invalid.
|
inline |
Returns true if this QCborValue is of the map type.
The map value can be retrieved using toMap().
Definition at line 162 of file qcborvalue.h.
Referenced by QPluginParsedMetaData::parse(), MetaTypesJsonProcessor::processTypes(), and toMap().
|
inline |
Returns true if this QCborValue is of the null type.
CBOR null values are used to indicate optional values that were not provided. They are distinct from undefined values, in that null values are usually not the result of an earlier error or problem.
Null values are distinct from undefined values and from invalid QCborValue objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.
Definition at line 167 of file qcborvalue.h.
References Null.
|
inline |
Returns true if this QCborValue contains a regular expression's pattern.
The pattern can be retrieved using toRegularExpression().
Definition at line 172 of file qcborvalue.h.
References RegularExpression.
|
inline |
Returns true if this QCborValue is of one of the CBOR simple types.
The type itself can later be retrieved using type(), even for types that don't have an enumeration in the API. They can also be checked with the \l{isSimpleType(QCborSimpleType)} overload.
Definition at line 177 of file qcborvalue.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if this QCborValue is of a simple type and toSimpleType() would return st, false otherwise.
This function can be used to check for any CBOR simple type, even those for which there is no enumeration in the API. For example, for the simple type of value 12, you could write:
Definition at line 181 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is of the string type.
The string value can be retrieved using toString().
Definition at line 160 of file qcborvalue.h.
Referenced by toString().
|
inline |
Returns true if this QCborValue is of the tag type.
The tag value can be retrieved using tag() and the tagged value using taggedValue().
This function also returns true for extended types that the API recognizes. For code that handles extended types directly before the Qt API is updated to support them, it is possible to recreate the tag + tagged value pair by using taggedValue().
Definition at line 163 of file qcborvalue.h.
Referenced by tag(), and taggedValue().
|
inline |
Returns true if this QCborValue is a boolean with true value.
This function exists because, internally, CBOR booleans are stored as two separate types, one for false and one for true.
Definition at line 165 of file qcborvalue.h.
References True.
|
inline |
Returns true if this QCborValue is of the undefined type.
CBOR undefined values are used to indicate missing information, usually as a result of a previous operation that did not complete as expected. They are also used by the QCborArray and QCborMap API to indicate the searched item was not found.
Undefined values are distinct from null values.
QCborValue objects with undefined values are also different from invalid QCborValue objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.
Definition at line 168 of file qcborvalue.h.
References Undefined.
|
inline |
Returns true if this QCborValue is of the URL type.
The URL value can be retrieved using toUrl().
Definition at line 171 of file qcborvalue.h.
References Url.
Referenced by toUrl().
|
inline |
Returns true if this QCborValue contains a UUID.
The value can be retrieved using toUuid().
Definition at line 173 of file qcborvalue.h.
References Uuid.
Referenced by toUuid().
|
inlinenoexcept |
Compares this value and other, and returns true if contents differ, false otherwise.
If each QCborValue contains an array or map, the comparison is recursive to elements contained in them.
For more information on CBOR equality in Qt, see, QCborValue::compare().
Definition at line 236 of file qcborvalue.h.
References other().
|
inline |
Compares this value and other, and returns true if this value should be sorted before other, false otherwise.
If each QCborValue contains an array or map, the comparison is recursive to elements contained in them.
For more information on CBOR sorting order, see QCborValue::compare().
Definition at line 238 of file qcborvalue.h.
References compare(), and other().
|
noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one.
Replaces the contents of this QCborObject with a copy of other.
Returns a reference to this object.
Definition at line 1906 of file qcborvalue.cpp.
References assignContainer(), and other().
|
inlinenoexcept |
Compares this value and other, and returns true if they hold the same contents, false otherwise.
If each QCborValue contains an array or map, the comparison is recursive to elements contained in them.
For more information on CBOR equality in Qt, see, compare().
Definition at line 234 of file qcborvalue.h.
References compare(), and other().
QCborValueRef QCborValue::operator[] | ( | const QString & | key | ) |
Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key.
When this QCborValue is a QCborMap, this function is equivalent to the matching operator[] on that map.
Before returning the reference: if this QCborValue was an array, it is first converted to a map (so that {map[i]} is
{array[i]} for each index,
i
, with valid {array[i]}); otherwise, if it was not a map it will be over-written with an empty map.
Definition at line 2325 of file qcborvalue.cpp.
References QCborContainerPrivate::findOrAddMapKey(), and qToStringViewIgnoringNull().
const QCborValue QCborValue::operator[] | ( | const QString & | key | ) | const |
If this QCborValue is a QCborMap, searches elements for the value whose key matches key.
If there's no key matching key in the map or if this QCborValue object is not a map, returns the undefined value.
This function is equivalent to:
Definition at line 2169 of file qcborvalue.cpp.
References QCborContainerPrivate::findCborMapKey(), and qToStringViewIgnoringNull().
QCborValueRef QCborValue::operator[] | ( | qint64 | key | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map or array, with the given key.
When this QCborValue is a QCborMap or, for 0 <= key < 0x10000, a QCborArray, this function is equivalent to the matching operator[] on that map or array.
Before returning the reference: if this QCborValue was an array but the key is out of range, the array is first converted to a map (so that {map[i]} is
{array[i]} for each index,
i
, with valid {array[i]}); otherwise, if it was not a map it will be over-written with an empty map.
Definition at line 2366 of file qcborvalue.cpp.
References QCborContainerPrivate::findOrAddMapKey(), maybeGrow(), and shouldArrayRemainArray().
const QCborValue QCborValue::operator[] | ( | qint64 | key | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key.
If this is a QCborArray, returns the element whose index is key. If there's no matching value in the array or map, or if this QCborValue object is not an array or map, returns the undefined value.
Definition at line 2204 of file qcborvalue.cpp.
References QCborContainerPrivate::elements, QCborContainerPrivate::findCborMapKey(), isArray(), QList< T >::size(), and QCborContainerPrivate::valueAt().
QCborValueRef QCborValue::operator[] | ( | QLatin1StringView | key | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key.
When this QCborValue is a QCborMap, this function is equivalent to the matching operator[] on that map.
Before returning the reference: if this QCborValue was an array, it is first converted to a map (so that {map[i]} is
{array[i]} for each index,
i
, with valid {array[i]}); otherwise, if it was not a map it will be over-written with an empty map.
Definition at line 2345 of file qcborvalue.cpp.
References QCborContainerPrivate::findOrAddMapKey().
const QCborValue QCborValue::operator[] | ( | QLatin1StringView | key | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key.
If there's no key matching key in the map or if this QCborValue object is not a map, returns the undefined value.
This function is equivalent to:
Definition at line 2188 of file qcborvalue.cpp.
References QCborContainerPrivate::findCborMapKey().
|
inlinenoexcept |
Swaps the contents of this QCborValue object and other.
Definition at line 150 of file qcborvalue.h.
References other(), and qt_ptr_swap().
Returns the tag of this extended QCborValue object, if it is of the tag type, defaultValue otherwise.
CBOR represents extended types by associating a number (the tag) with a stored representation. This function returns that number. To retrieve the representation, use taggedValue().
Definition at line 1924 of file qcborvalue.cpp.
References QList< T >::at(), QCborContainerPrivate::elements, isTag(), QList< T >::size(), and QtCbor::Element::value.
QCborValue QCborValue::taggedValue | ( | const QCborValue & | defaultValue = QCborValue() | ) | const |
Returns the tagged value of this extended QCborValue object, if it is of the tag type, defaultValue otherwise.
CBOR represents extended types by associating a number (the tag) with a stored representation. This function returns that representation. To retrieve the tag, use tag().
Definition at line 1940 of file qcborvalue.cpp.
References QCborContainerPrivate::elements, isTag(), QList< T >::size(), and QCborContainerPrivate::valueAt().
Referenced by QCborValueConstRef::taggedValue().
QCborArray QCborValue::toArray | ( | ) | const |
Definition at line 2097 of file qcborvalue.cpp.
References toArray().
Referenced by QImageReaderWriterHelpers::appendImagePluginMimeTypes(), QmlTypesClassDescription::collect(), QmlTypesClassDescription::collectLocalAnonymous(), QGeoServiceProviderPrivate::features(), members(), MetaTypesJsonProcessor::processForeignTypes(), MetaTypesJsonProcessor::processTypes(), QQuickSplitView::restoreState(), toArray(), QCborValueConstRef::toArray(), QCborValueConstRef::toArray(), and QmlTypeRegistrar::write().
QCborArray QCborValue::toArray | ( | const QCborArray & | defaultValue | ) | const |
Returns the array value stored in this QCborValue, if it is of the array type.
Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to QCborArray.
Definition at line 2102 of file qcborvalue.cpp.
References isArray(), and Q_ASSERT.
|
inline |
Returns the boolean value stored in this QCborValue, if it is of a boolean type.
Otherwise, it returns defaultValue.
Definition at line 192 of file qcborvalue.h.
Referenced by QmlTypesClassDescription::collect(), QmlTypesClassDescription::collectLocalAnonymous(), and QLibraryPrivate::updatePluginState().
QByteArray QCborValue::toByteArray | ( | const QByteArray & | defaultValue = {} | ) | const |
Returns the byte array value stored in this QCborValue, if it is of the byte array type.
Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to QByteArray.
Definition at line 1955 of file qcborvalue.cpp.
References QCborContainerPrivate::byteArrayAt(), isByteArray(), and Q_ASSERT.
Returns the date/time value stored in this QCborValue, if it is of the date/time extended type.
Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to QDateTime.
Definition at line 1991 of file qcborvalue.cpp.
References QtCbor::ByteData::asLatin1(), QList< T >::at(), QCborContainerPrivate::byteData(), QCborContainerPrivate::elements, QtCbor::Element::flags, isDateTime(), Qt::ISODateWithMs, Q_ASSERT, QList< T >::size(), and QtCbor::Element::StringIsUtf16.
Creates the diagnostic notation equivalent of this CBOR object and returns it.
The opts parameter controls the dialect of the notation. Diagnostic notation is useful in debugging, to aid the developer in understanding what value is stored in the QCborValue or in a CBOR stream. For that reason, the Qt API provides no support for parsing the diagnostic back into the in-memory format or CBOR stream, though the representation is unique and it would be possible.
CBOR diagnostic notation is specified by \l{RFC 7049, section 6}{section 6} of RFC 7049. It is a text representation of the CBOR stream and it is very similar to JSON, but it supports the CBOR types not found in JSON. The extended format enabled by the \l{DiagnosticNotationOption}{ExtendedFormat} flag is currently in some IETF drafts and its format is subject to change.
This function produces the equivalent representation of the stream that toCbor() would produce, without any transformation option provided there. This also implies this function may not produce a representation of the stream that was used to create the object, if it was created using fromCbor(), as that function may have applied transformations. For a high-fidelity notation of a stream, without transformation, see the cbordump
example.
Definition at line 311 of file qcbordiagnostic.cpp.
|
inline |
Returns the floating point value stored in this QCborValue, if it is of the Double type.
If it is of the Integer type, this function returns the integer value converted to double. In any other case, it returns defaultValue.
Definition at line 194 of file qcborvalue.h.
Referenced by QGeoPositionInfoSourcePrivate::loadFactory(), and QQuickSplitView::restoreState().
Returns the integer value stored in this QCborValue, if it is of the integer type.
If it is of the Double type, this function returns the floating point value converted to integer. In any other case, it returns defaultValue.
Definition at line 190 of file qcborvalue.h.
Referenced by QQmlJS::Dom::ExternalItemInfoBase::lastRevision(), QQmlJS::Dom::ExternalItemInfoBase::lastValidRevision(), QQuickSplitView::restoreState(), and QLibraryPrivate::updatePluginState().
QJsonValue QCborValue::toJsonValue | ( | ) | const |
Converts this QCborValue object to an equivalent representation in JSON and returns it as a QJsonValue.
Please note that CBOR contains a richer and wider type set than JSON, so some information may be lost in this conversion. The following table compares CBOR types to JSON types and indicates whether information may be lost or not.
\table \header
For information on the conversion of CBOR map keys to string, see QCborMap::toJsonObject().
If this QCborValue contains the undefined value, this function will return an undefined QJsonValue too. Note that JSON does not support undefined values and undefined QJsonValues are an extension to the specification. They cannot be held in a QJsonArray or QJsonObject, but can be returned from functions to indicate a failure. For all other intents and purposes, they are the same as null.
Definition at line 349 of file qjsoncbor.cpp.
References Array, ByteArray, DateTime, Double, False, fpToJson(), QJsonPrivate::Value::fromTrustedCbor(), Integer, Invalid, Map, Null, qt_convertToJson(), RegularExpression, SimpleType, simpleTypeString(), String, QJsonValue::String, Tag, True, type(), Undefined, QJsonValue::Undefined, Url, and Uuid.
QCborMap QCborValue::toMap | ( | ) | const |
Definition at line 2140 of file qcborvalue.cpp.
References toMap().
Referenced by isAllowedInMajorVersion(), QPluginParsedMetaData::parse(), MetaTypesJsonProcessor::processTypes(), toMap(), QCborValueConstRef::toMap(), QCborValueConstRef::toMap(), and QmlTypeRegistrar::write().
Returns the map value stored in this QCborValue, if it is of the map type.
Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to QCborMap.
Definition at line 2145 of file qcborvalue.cpp.
References isMap(), and Q_ASSERT.
|
inline |
Returns the simple type this QCborValue is of, if it is a simple type.
If it is not a simple type, it returns defaultValue.
The following types are simple types and this function will return the listed values:
\table \row
Definition at line 185 of file qcborvalue.h.
References isSimpleType().
Returns the string value stored in this QCborValue, if it is of the string type.
Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to QString.
Definition at line 1973 of file qcborvalue.cpp.
References isString(), Q_ASSERT, and QCborContainerPrivate::stringAt().
Referenced by QImageReaderWriterHelpers::appendImagePluginMimeTypes(), QGeoPositionInfoSourcePrivate::createSourceReal(), QGeoSatelliteInfoSourcePrivate::createSourceReal(), QmlLsp::QmlLintSuggestions::diagnose(), and QmlLsp::OpenDocumentSnapshot::dump().
Returns the URL value stored in this QCborValue, if it is of the URL extended type.
Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to QUrl.
Definition at line 2015 of file qcborvalue.cpp.
References QtCbor::ByteData::asByteArrayView(), QCborContainerPrivate::byteData(), QCborContainerPrivate::elements, QUrl::fromEncoded(), isUrl(), Q_ASSERT, and QList< T >::size().
Returns the UUID value stored in this QCborValue, if it is of the UUID extended type.
Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to QUuid.
Definition at line 2057 of file qcborvalue.cpp.
References QtCbor::ByteData::asByteArrayView(), QCborContainerPrivate::byteData(), QCborContainerPrivate::elements, QUuid::fromRfc4122(), isUuid(), Q_ASSERT, and QList< T >::size().
QVariant QCborValue::toVariant | ( | ) | const |
Converts this value to a native Qt type and returns the corresponding QVariant.
The following table lists the mapping performed between \l{Type}{QCborValue types} and \l{QMetaType::Type}{Qt meta types}.
\table \header
double
bool
std::nullptr_t
Note that values in both CBOR Maps and Arrays are converted recursively using this function too and placed in QVariantMap and QVariantList instead. You will not find QCborMap and QCborArray stored inside the QVariants.
QVariantMaps have string keys, unlike CBOR, so the conversion of a QCborMap to QVariantMap will imply a step of "stringification" of the key values. See QCborMap::toJsonObject() for details.
Definition at line 515 of file qjsoncbor.cpp.
References Double, False, QVariant::fromValue(), Integer, Invalid, isSimpleType(), Null, RegularExpression, toDouble(), toMap(), toString(), True, Url, and Uuid.
|
inline |
Returns the type of this QCborValue.
The type can also later be retrieved by one of the "isXxx" functions.
Definition at line 157 of file qcborvalue.h.
Referenced by QQmlJS::Dom::domCompareStrList(), and toJsonValue().
|
friend |
Definition at line 264 of file qcborvalue.h.
|
friend |
Definition at line 263 of file qcborvalue.h.
|
friend |
Definition at line 265 of file qcborvalue.h.