![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\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 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 |
\memberswap{value} | |
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. | |
QAnyStringView | toStringView (QAnyStringView defaultValue={}) const |
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). | |
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 | QCborArray |
class | QCborMap |
class | QCborValueConstRef |
class | QCborValueRef |
class | QCborContainerPrivate |
class | QJsonPrivate::Value |
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool | comparesEqual (const QCborValue &lhs, const QCborValue &rhs) |
Qt::strong_ordering | compareThreeWay (const QCborValue &lhs, const QCborValue &rhs) noexcept |
\inmodule QtCore
\reentrant
The QCborValue class encapsulates a value in CBOR.
\compares strong
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 46 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 62 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 50 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 70 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 97 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 98 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 99 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 100 of file qcborvalue.h.
|
inline |
Definition at line 102 of file qcborvalue.h.
|
inline |
Definition at line 103 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 105 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 106 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 107 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 1940 of file qcborvalue.cpp.
QCborValue::QCborValue | ( | const QString & | s | ) |
Creates a QCborValue with string value s.
The value can later be retrieved using toString().
Definition at line 1953 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 1961 of file qcborvalue.cpp.
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 1976 of file qcborvalue.cpp.
|
inline |
Definition at line 114 of file qcborvalue.h.
QCborValue::QCborValue | ( | const QCborArray & | a | ) |
Definition at line 1992 of file qcborvalue.cpp.
|
inline |
Creates a QCborValue with the array a.
The array can later be retrieved using toArray().
Definition at line 359 of file qcborarray.h.
QCborValue::QCborValue | ( | const QCborMap & | m | ) |
Definition at line 2008 of file qcborvalue.cpp.
|
inline |
Creates a QCborValue with the map m.
The map can later be retrieved using toMap().
Definition at line 430 of file qcbormap.h.
QCborValue::QCborValue | ( | QCborTag | tag, |
const QCborValue & | taggedValue = QCborValue() ) |
Definition at line 2025 of file qcborvalue.cpp.
|
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 121 of file qcborvalue.h.
|
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 2077 of file qcborvalue.cpp.
|
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 2116 of file qcborvalue.cpp.
|
inline |
Disposes of the current QCborValue object and frees any associated resources.
Definition at line 136 of file qcborvalue.h.
|
delete |
|
noexcept |
Copies the contents of other into this object.
Definition at line 2037 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 142 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 1490 of file qcborvalue.cpp.
|
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 615 of file qjsoncbor.cpp.
|
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 708 of file qjsoncbor.cpp.
|
inline |
Returns true if this QCborValue is of the array type.
The array value can be retrieved using toArray().
Definition at line 160 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is a boolean.
The value can be retrieved using toBool().
Definition at line 165 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 158 of file qcborvalue.h.
|
inline |
This convenience function returns true if the QCborValue is either an array or a map.
Definition at line 174 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 169 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is of the floating-point type.
The value can be retrieved using toDouble().
Definition at line 168 of file qcborvalue.h.
|
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 163 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is of the integer type.
The integer value can be retrieved using toInteger().
Definition at line 157 of file qcborvalue.h.
|
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 173 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is of the map type.
The map value can be retrieved using toMap().
Definition at line 161 of file qcborvalue.h.
|
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 166 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue contains a regular expression's pattern.
The pattern can be retrieved using toRegularExpression().
Definition at line 171 of file qcborvalue.h.
|
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 176 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 180 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 159 of file qcborvalue.h.
|
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 162 of file qcborvalue.h.
|
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 164 of file qcborvalue.h.
|
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 167 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue is of the URL type.
The URL value can be retrieved using toUrl().
Definition at line 170 of file qcborvalue.h.
|
inline |
Returns true if this QCborValue contains a UUID.
The value can be retrieved using toUuid().
Definition at line 172 of file qcborvalue.h.
|
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 2133 of file qcborvalue.cpp.
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 2575 of file qcborvalue.cpp.
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 2425 of file qcborvalue.cpp.
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 2616 of file qcborvalue.cpp.
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 2460 of file qcborvalue.cpp.
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 2595 of file qcborvalue.cpp.
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 2444 of file qcborvalue.cpp.
|
inlinenoexcept |
\memberswap{value}
Definition at line 149 of file qcborvalue.h.
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 2151 of file qcborvalue.cpp.
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 2167 of file qcborvalue.cpp.
QCborArray QCborValue::toArray | ( | ) | const |
Definition at line 2353 of file qcborvalue.cpp.
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 2358 of file qcborvalue.cpp.
|
inline |
Returns the boolean value stored in this QCborValue, if it is of a boolean type.
Otherwise, it returns defaultValue.
Definition at line 191 of file qcborvalue.h.
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 2182 of file qcborvalue.cpp.
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 193 of file qcborvalue.h.
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 189 of file qcborvalue.h.
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 348 of file qjsoncbor.cpp.
QCborMap QCborValue::toMap | ( | ) | const |
Definition at line 2396 of file qcborvalue.cpp.
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 2401 of file qcborvalue.cpp.
|
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 184 of file qcborvalue.h.
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 2200 of file qcborvalue.cpp.
QAnyStringView QCborValue::toStringView | ( | QAnyStringView | defaultValue = {} | ) | const |
Returns the string value stored in this QCborValue, if it is of the string type. Otherwise, it returns defaultValue. Since QCborValue stores strings in either US-ASCII, UTF-8 or UTF-16, the returned QAnyStringView may be in any of these encodings.
This function does not allocate memory. The return value is valid until the next call to a non-const member function on this object. If this object goes out of scope, the return value is valid until the next call to a non-const member function on the parent CBOR object (map or array).
Note that this function performs no conversion from other types to QString.
Definition at line 2227 of file qcborvalue.cpp.
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 2271 of file qcborvalue.cpp.
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 2313 of file qcborvalue.cpp.
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 517 of file qjsoncbor.cpp.
|
inline |
Returns the type of this QCborValue.
The type can also later be retrieved by one of the "isXxx" functions.
Definition at line 156 of file qcborvalue.h.
|
friend |
Definition at line 1366 of file qcborvalue.cpp.
References QtCbor::ForEquality.
|
friend |
Definition at line 259 of file qcborvalue.h.
|
friend |
Definition at line 267 of file qcborvalue.h.
|
friend |
Definition at line 271 of file qcborvalue.h.
|
friend |
Definition at line 268 of file qcborvalue.h.
|
friend |
Definition at line 269 of file qcborvalue.h.
|
friend |
Definition at line 270 of file qcborvalue.h.
|
friend |
Definition at line 272 of file qcborvalue.h.