![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore\reentrant More...
#include <qcborarray.h>
Classes | |
class | ConstIterator |
\inmodule QtCore More... | |
class | Iterator |
\inmodule QtCore More... | |
Public Types | |
typedef qsizetype | size_type |
A typedef to qsizetype. | |
typedef QCborValue | value_type |
The type of values that can be held in a QCborArray: that is, QCborValue. | |
typedef value_type * | pointer |
A typedef to {QCborValue *}, for compatibility with generic algorithms. | |
typedef const value_type * | const_pointer |
A typedef to {const QCborValue *}, for compatibility with generic algorithms. | |
typedef QCborValue & | reference |
A typedef to {QCborValue &}, for compatibility with generic algorithms. | |
typedef const QCborValue & | const_reference |
A typedef to {const QCborValue &}, for compatibility with generic algorithms. | |
typedef qsizetype | difference_type |
A typedef to qsizetype. | |
typedef Iterator | iterator |
A synonym to QCborArray::Iterator. | |
typedef ConstIterator | const_iterator |
A synonym to QCborArray::ConstIterator. | |
Public Member Functions | |
QCborArray () noexcept | |
Constructs an empty QCborArray. | |
QCborArray (const QCborArray &other) noexcept | |
Copies the contents of other into this object. | |
QCborArray & | operator= (const QCborArray &other) noexcept |
Replaces the contents of this array with that found in other, then returns a reference to this object. | |
QCborArray (std::initializer_list< QCborValue > args) | |
Initializes this QCborArray from the C++ brace-enclosed list found in args, as in the following example: | |
~QCborArray () | |
Destroys this QCborArray and frees any associated resources. | |
void | swap (QCborArray &other) noexcept |
Swaps the contents of this object and other. | |
QCborValue | toCborValue () const |
Explicitly construcuts a \l QCborValue object that represents this array. | |
qsizetype | size () const noexcept |
Returns the size of this array. | |
bool | isEmpty () const |
Returns true if this QCborArray is empty (that is if size() is 0). | |
void | clear () |
Empties this array. | |
QCborValue | at (qsizetype i) const |
Returns the QCborValue element at position i in the array. | |
QCborValue | first () const |
Returns the first QCborValue of this array. | |
QCborValue | last () const |
Returns the last QCborValue of this array. | |
const QCborValue | operator[] (qsizetype i) const |
Returns the QCborValue element at position i in the array. | |
QCborValueRef | first () |
Returns a reference to the first QCborValue of this array. | |
QCborValueRef | last () |
Returns a reference to the last QCborValue of this array. | |
QCborValueRef | operator[] (qsizetype i) |
Returns a reference to the QCborValue element at position i in the array. | |
void | insert (qsizetype i, const QCborValue &value) |
void | insert (qsizetype i, QCborValue &&value) |
Inserts value into the array at position i in this array. | |
void | prepend (const QCborValue &value) |
void | prepend (QCborValue &&value) |
Prepends value into the array before any other elements it may already contain. | |
void | append (const QCborValue &value) |
void | append (QCborValue &&value) |
Appends value into the array after all other elements it may already contain. | |
QCborValue | extract (ConstIterator it) |
Extracts a value from the array at the position indicated by iterator it and returns the value so extracted. | |
QCborValue | extract (Iterator it) |
void | removeAt (qsizetype i) |
Removes the item at position i from the array. | |
QCborValue | takeAt (qsizetype i) |
Removes the item at position i from the array and returns it. | |
void | removeFirst () |
Removes the first item in the array, making the second element become the first. | |
void | removeLast () |
Removes the last item in the array. | |
QCborValue | takeFirst () |
Removes the first item in the array and returns it, making the second element become the first. | |
QCborValue | takeLast () |
Removes the last item in the array and returns it. | |
bool | contains (const QCborValue &value) const |
Returns true if this array contains an element that is equal to value. | |
int | compare (const QCborArray &other) const noexcept Q_DECL_PURE_FUNCTION |
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). | |
bool | operator== (const QCborArray &other) const noexcept |
Compares this array and other, comparing each element in sequence, and returns true if both arrays contains the same elements, false otherwise. | |
bool | operator!= (const QCborArray &other) const noexcept |
Compares this array and other, comparing each element in sequence, and returns true if the two arrays' contents are different, false otherwise. | |
bool | operator< (const QCborArray &other) const |
Compares this array and other, comparing each element in sequence, and returns true if this array should be sorted before other, false otherwise. | |
iterator | begin () |
Returns an array iterator pointing to the first item in this array. | |
const_iterator | constBegin () const |
Returns an array iterator pointing to the first item in this array. | |
const_iterator | begin () const |
Returns an array iterator pointing to the first item in this array. | |
const_iterator | cbegin () const |
Returns an array iterator pointing to the first item in this array. | |
iterator | end () |
Returns an array iterator pointing to just after the last element in this array. | |
const_iterator | constEnd () const |
Returns an array iterator pointing to just after the last element in this array. | |
const_iterator | end () const |
Returns an array iterator pointing to just after the last element in this array. | |
const_iterator | cend () const |
Returns an array iterator pointing to just after the last element in this array. | |
iterator | insert (iterator before, const QCborValue &value) |
iterator | insert (const_iterator before, const QCborValue &value) |
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. | |
iterator | erase (iterator it) |
iterator | erase (const_iterator it) |
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). | |
void | push_back (const QCborValue &t) |
Synonym for append(). | |
void | push_front (const QCborValue &t) |
Synonym for prepend(). | |
void | pop_front () |
Synonym for removeFirst(). | |
void | pop_back () |
Synonym for removeLast(). | |
bool | empty () const |
Synonym for isEmpty(). | |
QCborArray | operator+ (const QCborValue &v) const |
Returns a new QCborArray containing the same elements as this array, plus v appended as the last element. | |
QCborArray & | operator+= (const QCborValue &v) |
Appends v to this array and returns a reference to this array. | |
QCborArray & | operator<< (const QCborValue &v) |
Appends v to this array and returns a reference to this array. | |
QVariantList | toVariantList () const |
Recursively converts each \l QCborValue in this array using QCborValue::toVariant() and returns the QVariantList composed of the converted items. | |
QJsonArray | 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. | |
Static Public Member Functions | |
static QCborArray | fromStringList (const QStringList &list) |
Returns a QCborArray containing all the strings found in the list list. | |
static QCborArray | fromVariantList (const QVariantList &list) |
Converts all the items in the list to CBOR using QCborValue::fromVariant() and returns the array composed of those elements. | |
static QCborArray | fromJsonArray (const QJsonArray &array) |
Converts all JSON items found in the array array to CBOR using QCborValue::fromJson(), and returns the CBOR array composed of those elements. | |
static QCborArray | fromJsonArray (QJsonArray &&array) noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Friends | |
class | QJsonPrivate::Variant |
\inmodule QtCore
\reentrant
The QCborArray class is used to hold an array of CBOR elements.
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 19 of file qcborarray.h.
A synonym to QCborArray::ConstIterator.
Definition at line 202 of file qcborarray.h.
A typedef to {const QCborValue *}, for compatibility with generic algorithms.
Definition at line 125 of file qcborarray.h.
A typedef to {const QCborValue &}, for compatibility with generic algorithms.
Definition at line 127 of file qcborarray.h.
A typedef to qsizetype.
Definition at line 128 of file qcborarray.h.
A synonym to QCborArray::Iterator.
Definition at line 201 of file qcborarray.h.
A typedef to {QCborValue *}, for compatibility with generic algorithms.
Definition at line 124 of file qcborarray.h.
A typedef to {QCborValue &}, for compatibility with generic algorithms.
Definition at line 126 of file qcborarray.h.
A typedef to qsizetype.
Definition at line 122 of file qcborarray.h.
The type of values that can be held in a QCborArray: that is, QCborValue.
Definition at line 123 of file qcborarray.h.
|
noexcept |
Constructs an empty QCborArray.
Definition at line 83 of file qcborarray.cpp.
|
noexcept |
Copies the contents of other into this object.
Definition at line 91 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 133 of file qcborarray.h.
References append(), args, and QList< T >::size().
QCborArray::~QCborArray | ( | ) |
Destroys this QCborArray and frees any associated resources.
Definition at line 110 of file qcborarray.cpp.
|
inline |
Definition at line 170 of file qcborarray.h.
References insert().
Referenced by QShaderDescriptionPrivate::makeDoc(), members(), QQuickSplitView::saveState(), and QV4::Compiler::Codegen::visit().
|
inline |
Appends value into the array after all other elements it may already contain.
Definition at line 171 of file qcborarray.h.
References insert().
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 185 of file qcborarray.cpp.
References i, and QCborContainerPrivate::valueAt().
Referenced by QImageReaderWriterHelpers::appendImagePluginMimeTypes().
|
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 203 of file qcborarray.h.
References d.
|
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 205 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 206 of file qcborarray.h.
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 210 of file qcborarray.h.
void QCborArray::clear | ( | ) |
Empties this array.
Definition at line 160 of file qcborarray.cpp.
References QExplicitlySharedDataPointer< T >::reset().
|
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 1326 of file qcborvalue.cpp.
References compareContainer(), d, and other().
|
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 204 of file qcborarray.h.
References d.
Referenced by QQuickSplitView::restoreState().
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 208 of file qcborarray.h.
References d.
Referenced by QQuickSplitView::restoreState().
bool QCborArray::contains | ( | const QCborValue & | value | ) | const |
Returns true if this array contains an element that is equal to value.
Definition at line 420 of file qcborarray.cpp.
References QCborContainerPrivate::compareElement(), and i.
Referenced by QV4::Compiler::Codegen::visit().
|
inline |
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 207 of file qcborarray.h.
References d.
|
inline |
Returns an array iterator pointing to just after the last element in this array.
Definition at line 209 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 216 of file qcborarray.h.
|
inline |
Definition at line 215 of file qcborarray.h.
|
inline |
Extracts a value from the array at the position indicated by iterator it and returns the value so extracted.
Definition at line 172 of file qcborarray.h.
Referenced by extract().
QCborValue QCborArray::extract | ( | Iterator | it | ) |
Definition at line 323 of file qcborarray.cpp.
References QCborContainerPrivate::extractAt(), it, and QCborContainerPrivate::removeAt().
|
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 157 of file qcborarray.h.
References begin(), and Q_ASSERT.
|
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 154 of file qcborarray.h.
References at.
|
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 846 of file qjsoncbor.cpp.
Referenced by QCborValue::fromJsonValue(), QCborValue::fromVariant(), and QJsonArray::toVariantList().
|
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 857 of file qjsoncbor.cpp.
|
static |
Returns a QCborArray containing all the strings found in the list list.
Definition at line 808 of file qjsoncbor.cpp.
References list, and QList< T >::size().
Referenced by QCborValue::fromVariant(), and QJsonDocument::fromVariant().
|
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 826 of file qjsoncbor.cpp.
References appendVariant(), list, and QList< T >::size().
Referenced by QCborValue::fromVariant(), and QJsonPrivate::Variant::toJsonArray().
|
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 213 of file qcborarray.h.
References d, QCborValueConstRef::i, and insert().
|
inline |
void QCborArray::insert | ( | qsizetype | i, |
const QCborValue & | value | ||
) |
Definition at line 289 of file qcborarray.cpp.
References QExplicitlySharedDataPointer< T >::data(), QCborContainerPrivate::grow(), i, QCborContainerPrivate::insertAt(), and Q_ASSERT.
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 301 of file qcborarray.cpp.
References QExplicitlySharedDataPointer< T >::data(), QCborContainerPrivate::grow(), i, QCborContainerPrivate::insertAt(), QCborContainerPrivate::MoveContainer, Q_ASSERT, and QCborContainerPrivate::resetValue().
|
inline |
Returns true if this QCborArray is empty (that is if size() is 0).
Definition at line 150 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 158 of file qcborarray.h.
References begin(), and Q_ASSERT.
|
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 155 of file qcborarray.h.
References at.
|
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 195 of file qcborarray.h.
References other().
|
inline |
Returns a new QCborArray containing the same elements as this array, plus v appended as the last element.
Definition at line 225 of file qcborarray.h.
|
inline |
Appends v to this array and returns a reference to this array.
Definition at line 227 of file qcborarray.h.
References append().
|
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 197 of file qcborarray.h.
References compare(), and other().
|
inline |
Appends v to this array and returns a reference to this array.
Definition at line 229 of file qcborarray.h.
References append().
|
noexcept |
Replaces the contents of this array with that found in other, then returns a reference to this object.
Definition at line 118 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 193 of file qcborarray.h.
References compare(), and other().
|
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 159 of file qcborarray.h.
References begin(), i, and insert().
|
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 156 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 221 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 220 of file qcborarray.h.
|
inline |
Definition at line 168 of file qcborarray.h.
References insert().
|
inline |
Prepends value into the array before any other elements it may already contain.
Definition at line 169 of file qcborarray.h.
References insert().
|
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 218 of file qcborarray.h.
References append().
|
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 219 of file qcborarray.h.
References prepend().
Removes the item at position i from the array.
The array must have more than i elements before the removal.
Definition at line 361 of file qcborarray.cpp.
References i, and QCborContainerPrivate::removeAt().
|
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 176 of file qcborarray.h.
|
inline |
Removes the last item in the array.
The array must not be empty before this call.
Definition at line 177 of file qcborarray.h.
|
noexcept |
Returns the size of this array.
Definition at line 150 of file qcborarray.cpp.
References QCborContainerPrivate::elements, and QList< T >::size().
Referenced by QV4::Compiler::JSUnitGenerator::registerJSClass(), and QQuickSplitView::restoreState().
|
inlinenoexcept |
Swaps the contents of this object and other.
Definition at line 142 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 175 of file qcborarray.h.
References begin(), i, and Q_ASSERT.
|
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 178 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 179 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 147 of file qcborarray.h.
Referenced by QQuickSplitView::saveState().
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 419 of file qjsoncbor.cpp.
References convertToJsonArray(), and QExplicitlySharedDataPointer< T >::data().
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 794 of file qjsoncbor.cpp.
References QList< T >::append(), d, i, and QList< T >::reserve().
Referenced by QJsonArray::toVariantList().
|
friend |
Definition at line 244 of file qcborarray.h.