QtBase
v6.3.1
|
The QCborArray class is used to hold an array of CBOR elements. More...
#include <qcborarray.h>
Classes | |
class | ConstIterator |
The QCborArray::ConstIterator class provides an STL-style const iterator for QCborArray. More... | |
class | Iterator |
The QCborArray::Iterator class provides an STL-style non-const iterator for QCborArray. More... | |
Public Types | |
typedef qsizetype | size_type |
typedef QCborValue | value_type |
typedef value_type * | pointer |
typedef const value_type * | const_pointer |
typedef QCborValue & | reference |
typedef const QCborValue & | const_reference |
typedef qsizetype | difference_type |
typedef Iterator | iterator |
typedef ConstIterator | const_iterator |
Static Public Member Functions | |
static QCborArray | fromStringList (const QStringList &list) |
static QCborArray | fromVariantList (const QVariantList &list) |
static QCborArray | fromJsonArray (const QJsonArray &array) |
static QCborArray | fromJsonArray (QJsonArray &&array) noexcept |
Friends | |
class | QJsonPrivate::Variant |
The QCborArray class is used to hold an array of CBOR elements.
\inmodule QtCore
\reentrant
This class can be used to hold one sequential container in CBOR (an array). 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}.
QCborArray is very similar to \l QVariantList and \l QJsonArray and its API is almost identical to those two classes. It can also be converted to and from those two, though there may be loss of information in some conversions.
Definition at line 55 of file qcborarray.h.
A synonym to QCborArray::ConstIterator.
Definition at line 237 of file qcborarray.h.
A typedef to {const QCborValue *}, for compatibility with generic algorithms.
Definition at line 160 of file qcborarray.h.
A typedef to {const QCborValue &}, for compatibility with generic algorithms.
Definition at line 162 of file qcborarray.h.
A typedef to qsizetype.
Definition at line 163 of file qcborarray.h.
A synonym to QCborArray::Iterator.
Definition at line 236 of file qcborarray.h.
A typedef to {QCborValue *}, for compatibility with generic algorithms.
Definition at line 159 of file qcborarray.h.
A typedef to {QCborValue &}, for compatibility with generic algorithms.
Definition at line 161 of file qcborarray.h.
A typedef to qsizetype.
Definition at line 157 of file qcborarray.h.
The type of values that can be held in a QCborArray: that is, QCborValue.
Definition at line 158 of file qcborarray.h.
|
noexcept |
Constructs an empty QCborArray.
Definition at line 117 of file qcborarray.cpp.
|
noexcept |
Copies the contents of other into this object.
Definition at line 125 of file qcborarray.cpp.
|
inline |
Initializes this QCborArray from the C++ brace-enclosed list found in args, as in the following example:
Definition at line 168 of file qcborarray.h.
QCborArray::~QCborArray | ( | ) |
Destroys this QCborArray and frees any associated resources.
Definition at line 144 of file qcborarray.cpp.
|
inline |
|
inline |
Appends value into the array after all other elements it may already contain.
Definition at line 206 of file qcborarray.h.
QCborValue QCborArray::at | ( | qsizetype | i | ) | const |
Returns the QCborValue element at position i in the array.
If the array is smaller than i elements, this function returns a QCborValue containing an undefined value. For that reason, it is not possible with this function to tell apart the situation where the array is not large enough from the case where the array starts with an undefined value.
Definition at line 219 of file qcborarray.cpp.
|
inline |
Returns an array iterator pointing to the first item in this array. If the array is empty, then this function returns the same as end().
Definition at line 238 of file qcborarray.h.
|
inline |
Returns an array iterator pointing to the first item in this array. If the array is empty, then this function returns the same as end().
Definition at line 240 of file qcborarray.h.
|
inline |
Returns an array iterator pointing to the first item in this array. If the array is empty, then this function returns the same as end().
Definition at line 241 of file qcborarray.h.
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 245 of file qcborarray.h.
void QCborArray::clear | ( | ) |
|
noexcept |
Compares this array and other, comparing each element in sequence, and returns an integer that indicates whether this array should be sorted before (if the result is negative) or after other (if the result is positive). If this function returns 0, the two arrays are equal and contain the same elements.
For more information on CBOR sorting order, see QCborValue::compare().
Definition at line 1327 of file qcborvalue.cpp.
|
inline |
Returns an array iterator pointing to the first item in this array. If the array is empty, then this function returns the same as end().
Definition at line 239 of file qcborarray.h.
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 243 of file qcborarray.h.
bool QCborArray::contains | ( | const QCborValue & | value | ) | const |
Returns true if this array contains an element that is equal to value.
Definition at line 454 of file qcborarray.cpp.
|
inline |
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 242 of file qcborarray.h.
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 244 of file qcborarray.h.
|
inline |
Removes the element pointed to by the array iterator it from this array, then returns an iterator to the next element (the one that took the same position in the array that it used to occupy).
Definition at line 251 of file qcborarray.h.
|
inline |
|
inline |
Extracts a value from the array at the position indicated by iterator it and returns the value so extracted.
Definition at line 207 of file qcborarray.h.
QCborValue QCborArray::extract | ( | Iterator | it | ) |
Definition at line 357 of file qcborarray.cpp.
|
inline |
Returns a reference to the first QCborValue of this array. The array must not be empty.
QCborValueRef has the exact same API as \l QCborValue, with one important difference: if you assign new values to it, this array will be updated with that new value.
Definition at line 192 of file qcborarray.h.
|
inline |
Returns the first QCborValue of this array.
If the array is empty, this function returns a QCborValue containing an undefined value. For that reason, it is not possible with this function to tell apart the situation where the array is not large enough from the case where the array ends with an undefined value.
Definition at line 189 of file qcborarray.h.
|
static |
Converts all JSON items found in the array array to CBOR using QCborValue::fromJson(), and returns the CBOR array composed of those elements.
This conversion is lossless, as the CBOR type system is a superset of JSON's. Moreover, the array returned by this function can be converted back to the original array by using toJsonArray().
Definition at line 875 of file qjsoncbor.cpp.
|
staticnoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 886 of file qjsoncbor.cpp.
|
static |
Returns a QCborArray containing all the strings found in the list list.
Definition at line 837 of file qjsoncbor.cpp.
|
static |
Converts all the items in the list to CBOR using QCborValue::fromVariant() and returns the array composed of those elements.
Conversion from \l QVariant is not completely lossless. Please see the documentation in QCborValue::fromVariant() for more information.
Definition at line 855 of file qjsoncbor.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Inserts value into this array before element before and returns an array iterator pointing to the just-inserted element.
Definition at line 248 of file qcborarray.h.
|
inline |
void QCborArray::insert | ( | qsizetype | i, |
const QCborValue & | value | ||
) |
void QCborArray::insert | ( | qsizetype | i, |
QCborValue && | value | ||
) |
Inserts value into the array at position i in this array. If i is -1, the entry is appended to the array. Pads the array with invalid entries if i is greater than the prior size of the array.
Definition at line 335 of file qcborarray.cpp.
|
inline |
Returns true if this QCborArray is empty (that is if size() is 0).
Definition at line 185 of file qcborarray.h.
|
inline |
Returns a reference to the last QCborValue of this array. The array must not be empty.
QCborValueRef has the exact same API as \l QCborValue, with one important difference: if you assign new values to it, this array will be updated with that new value.
Definition at line 193 of file qcborarray.h.
|
inline |
Returns the last QCborValue of this array.
If the array is empty, this function returns a QCborValue containing an undefined value. For that reason, it is not possible with this function to tell apart the situation where the array is not large enough from the case where the array ends with an undefined value.
Definition at line 190 of file qcborarray.h.
|
inlinenoexcept |
Compares this array and other, comparing each element in sequence, and returns true if the two arrays' contents are different, false otherwise.
For more information on CBOR equality in Qt, see, QCborValue::compare().
Definition at line 230 of file qcborarray.h.
|
inline |
Returns a new QCborArray containing the same elements as this array, plus v appended as the last element.
Definition at line 260 of file qcborarray.h.
|
inline |
Appends v to this array and returns a reference to this array.
Definition at line 262 of file qcborarray.h.
|
inline |
Compares this array and other, comparing each element in sequence, and returns true if this array should be sorted before other, false otherwise.
For more information on CBOR sorting order, see QCborValue::compare().
Definition at line 232 of file qcborarray.h.
|
inline |
Appends v to this array and returns a reference to this array.
Definition at line 264 of file qcborarray.h.
|
noexcept |
Replaces the contents of this array with that found in other, then returns a reference to this object.
Definition at line 152 of file qcborarray.cpp.
|
inlinenoexcept |
Compares this array and other, comparing each element in sequence, and returns true if both arrays contains the same elements, false otherwise.
For more information on CBOR equality in Qt, see, QCborValue::compare().
Definition at line 228 of file qcborarray.h.
|
inline |
Returns a reference to the QCborValue element at position i in the array. Indices beyond the end of the array will grow the array, filling with undefined entries, until it has an entry at the specified index.
QCborValueRef has the exact same API as \l QCborValue, with one important difference: if you assign new values to it, this array will be updated with that new value.
Definition at line 194 of file qcborarray.h.
|
inline |
Returns the QCborValue element at position i in the array.
If the array is smaller than i elements, this function returns a QCborValue containing an undefined value. For that reason, it is not possible with this function to tell apart the situation where the array is not large enough from the case where the array contains an undefined value at position i.
Definition at line 191 of file qcborarray.h.
|
inline |
Synonym for removeLast(). This function is provided for compatibility with generic code that uses the Standard Library API.
Removes the last element of this array. The array must not be empty before the removal
Definition at line 256 of file qcborarray.h.
|
inline |
Synonym for removeFirst(). This function is provided for compatibility with generic code that uses the Standard Library API.
Removes the first element of this array. The array must not be empty before the removal
Definition at line 255 of file qcborarray.h.
|
inline |
|
inline |
Prepends value into the array before any other elements it may already contain.
Definition at line 204 of file qcborarray.h.
|
inline |
Synonym for append(). This function is provided for compatibility with generic code that uses the Standard Library API.
Appends the element t to this array.
Definition at line 253 of file qcborarray.h.
|
inline |
Synonym for prepend(). This function is provided for compatibility with generic code that uses the Standard Library API.
Prepends the element t to this array.
Definition at line 254 of file qcborarray.h.
Removes the item at position i from the array. The array must have more than i elements before the removal.
Definition at line 395 of file qcborarray.cpp.
|
inline |
Removes the first item in the array, making the second element become the first. The array must not be empty before this call.
Definition at line 211 of file qcborarray.h.
|
inline |
Removes the last item in the array. The array must not be empty before this call.
Definition at line 212 of file qcborarray.h.
|
noexcept |
|
inlinenoexcept |
Swaps the contents of this object and other.
Definition at line 177 of file qcborarray.h.
|
inline |
Removes the item at position i from the array and returns it. The array must have more than i elements before the removal.
Definition at line 210 of file qcborarray.h.
|
inline |
Removes the first item in the array and returns it, making the second element become the first. The array must not be empty before this call.
Definition at line 213 of file qcborarray.h.
|
inline |
Removes the last item in the array and returns it. The array must not be empty before this call.
Definition at line 214 of file qcborarray.h.
|
inline |
Explicitly construcuts a \l QCborValue object that represents this array. This function is usually not necessary since QCborValue has a constructor for QCborArray, so the conversion is implicit.
Converting QCborArray to QCborValue allows it to be used in any context where QCborValues can be used, including as items in QCborArrays and as keys and mapped types in QCborMap. Converting an array to QCborValue allows access to QCborValue::toCbor().
Definition at line 182 of file qcborarray.h.
QJsonArray QCborArray::toJsonArray | ( | ) | const |
Recursively converts every \l QCborValue element in this array to JSON using QCborValue::toJsonValue() and returns the corresponding QJsonArray composed of those elements.
Please note that CBOR contains a richer and wider type set than JSON, so some information may be lost in this conversion. For more details on what conversions are applied, see QCborValue::toJsonValue().
Definition at line 447 of file qjsoncbor.cpp.
QVariantList QCborArray::toVariantList | ( | ) | const |
Recursively converts each \l QCborValue in this array using QCborValue::toVariant() and returns the QVariantList composed of the converted items.
Conversion to \l QVariant is not completely lossless. Please see the documentation in QCborValue::toVariant() for more information.
Definition at line 823 of file qjsoncbor.cpp.
|
friend |
Definition at line 279 of file qcborarray.h.