QCborArray Class

The QCborArray class is used to hold an array of CBOR elements. More...

Header: #include <QCborArray>
qmake: QT += core
Since: Qt 5.12

Note: All functions in this class are reentrant.

Public Types

class ConstIterator
class Iterator
typedef const_iterator
typedef const_pointer
typedef const_reference
typedef difference_type
typedef pointer
typedef reference
typedef size_type
typedef value_type

Public Functions

QCborArray(std::initializer_list<QCborValue> args)
~QCborArray()
void append(const QCborValue &value)
void append(QCborValue &&value)
QCborValue at(qsizetype i) const
iterator begin()
const_iterator begin() const
const_iterator cbegin() const
const_iterator cend() const
void clear()
const_iterator constBegin() const
const_iterator constEnd() const
bool contains(const QCborValue &value) const
bool empty() const
iterator end()
const_iterator end() const
iterator erase(iterator it)
iterator erase(const_iterator it)
QCborValue extract(ConstIterator it)
QCborValue extract(Iterator it)
QCborValue first() const
QCborValueRef first()
void insert(qsizetype i, const QCborValue &value)
void insert(qsizetype i, QCborValue &&value)
iterator insert(iterator before, const QCborValue &value)
iterator insert(const_iterator before, const QCborValue &value)
bool isEmpty() const
QCborValue last() const
QCborValueRef last()
void pop_back()
void pop_front()
void prepend(const QCborValue &value)
void prepend(QCborValue &&value)
void push_back(const QCborValue &t)
void push_front(const QCborValue &t)
void removeAt(qsizetype i)
void removeFirst()
void removeLast()
QCborValue takeAt(qsizetype i)
QCborValue takeFirst()
QCborValue takeLast()
QJsonArray toJsonArray() const
QVariantList toVariantList() const
QCborArray operator+(const QCborValue &v) const
QCborArray &operator+=(const QCborValue &v)
QCborArray &operator<<(const QCborValue &v)
const QCborValue operator[](qsizetype i) const
QCborValueRef operator[](qsizetype i)

Static Public Members

QCborArray fromJsonArray(const QJsonArray &array)
QCborArray fromStringList(const QStringList &list)
QCborArray fromVariantList(const QVariantList &list)

Detailed Description

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 CoAP protocol.

QCborArray is very similar to QVariantList and 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.

See also QCborValue, QCborMap, QJsonArray, QList, and QVector.

Member Type Documentation

typedef QCborArray::const_iterator

A synonym to QCborArray::ConstIterator.

typedef QCborArray::const_pointer

A typedef to const QCborValue *, for compatibility with generic algorithms.

typedef QCborArray::const_reference

A typedef to const QCborValue &, for compatibility with generic algorithms.

typedef QCborArray::difference_type

A typedef to qsizetype.

typedef QCborArray::pointer

A typedef to QCborValue *, for compatibility with generic algorithms.

typedef QCborArray::reference

A typedef to QCborValue &, for compatibility with generic algorithms.

typedef QCborArray::size_type

A typedef to qsizetype.

typedef QCborArray::value_type

The type of values that can be held in a QCborArray: that is, QCborValue.

Member Function Documentation

QCborArray::QCborArray(std::initializer_list<QCborValue> args)

Initializes this QCborArray from the C++ brace-enclosed list found in args, as in the following example:

 QCborArray a = { null, 0, 1, 1.5, 2, "Hello", QByteArray("World") };

QCborArray::~QCborArray()

Destroys this QCborArray and frees any associated resources.

void QCborArray::append(const QCborValue &value)

Appends value into the array after all other elements it may already contain.

See also at(), operator[](), first(), last(), insert(), prepend(), removeAt(), and takeAt().

void QCborArray::append(QCborValue &&value)

Appends value into the array after all other elements it may already contain.

See also at(), operator[](), first(), last(), insert(), prepend(), removeAt(), and takeAt().

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.

See also operator[](), first(), last(), insert(), prepend(), append(), removeAt(), and takeAt().

iterator QCborArray::begin()

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().

See also constBegin() and end().

const_iterator QCborArray::begin() const

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().

See also constBegin() and constEnd().

const_iterator QCborArray::cbegin() const

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().

See also constBegin() and constEnd().

const_iterator QCborArray::cend() const

Returns an array iterator pointing to just after the last element in this array.

See also constBegin() and constEnd().

void QCborArray::clear()

const_iterator QCborArray::constBegin() const

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().

See also begin() and constEnd().

const_iterator QCborArray::constEnd() const

Returns an array iterator pointing to just after the last element in this array.

See also constBegin() and end().

bool QCborArray::contains(const QCborValue &value) const

Returns true if this array contains an element that is equal to value.

bool QCborArray::empty() const

Synonym for isEmpty(). This function is provided for compatibility with generic code that uses the Standard Library API.

Returns true if this array is empty (size() == 0).

See also isEmpty() and size().

iterator QCborArray::end()

Returns an array iterator pointing to just after the last element in this array.

See also begin() and constEnd().

const_iterator QCborArray::end() const

Returns an array iterator pointing to just after the last element in this array.

See also constBegin() and constEnd().

iterator QCborArray::erase(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).

See also insert(), removeAt(), takeAt(), takeFirst(), and takeLast().

iterator QCborArray::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).

See also insert(), removeAt(), takeAt(), takeFirst(), and takeLast().

QCborValue QCborArray::extract(ConstIterator it)

Extracts a value from the array at the position indicated by iterator it and returns the value so extracted.

See also insert(), erase(), takeAt(), and removeAt().

QCborValue QCborArray::extract(Iterator it)

Extracts a value from the array at the position indicated by iterator it and returns the value so extracted.

See also insert(), erase(), takeAt(), and removeAt().

QCborValue QCborArray::first() const

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.

See also operator[](), at(), last(), insert(), prepend(), append(), removeAt(), and takeAt().

QCborValueRef QCborArray::first()

Returns a reference to the first QCborValue of this array. The array must not be empty.

QCborValueRef has the exact same API as QCborValue, with one important difference: if you assign new values to it, this array will be updated with that new value.

See also operator[](), at(), last(), insert(), prepend(), append(), removeAt(), and takeAt().

[static] QCborArray 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.

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().

See also toJsonArray(), toVariantList(), QCborValue::fromJsonValue(), and QCborMap::fromJsonObject().

[static] QCborArray QCborArray::fromStringList(const QStringList &list)

Returns a QCborArray containing all the strings found in the list list.

See also fromVariantList() and fromJsonArray().

[static] QCborArray 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.

Conversion from QVariant is not completely lossless. Please see the documentation in QCborValue::fromVariant() for more information.

See also toVariantList(), fromStringList(), fromJsonArray(), and QCborMap::fromVariantMap().

void QCborArray::insert(qsizetype i, const 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.

See also at(), operator[](), first(), last(), prepend(), append(), removeAt(), takeAt(), and extract().

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.

See also at(), operator[](), first(), last(), prepend(), append(), removeAt(), takeAt(), and extract().

iterator QCborArray::insert(iterator before, const QCborValue &value)

This is an overloaded function.

Inserts value into this array before element before and returns an array iterator pointing to the just-inserted element.

See also erase(), removeAt(), prepend(), and append().

iterator QCborArray::insert(const_iterator before, const QCborValue &value)

This is an overloaded function.

Inserts value into this array before element before and returns an array iterator pointing to the just-inserted element.

See also erase(), removeAt(), prepend(), and append().

bool QCborArray::isEmpty() const

Returns true if this QCborArray is empty (that is if size() is 0).

See also size() and clear().

QCborValue QCborArray::last() const

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.

See also operator[](), at(), first(), insert(), prepend(), append(), removeAt(), and takeAt().

QCborValueRef QCborArray::last()

Returns a reference to the last QCborValue of this array. The array must not be empty.

QCborValueRef has the exact same API as QCborValue, with one important difference: if you assign new values to it, this array will be updated with that new value.

See also operator[](), at(), first(), insert(), prepend(), append(), removeAt(), and takeAt().

void QCborArray::pop_back()

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

See also removeLast(), takeLast(), pop_front(), push_back(), append(), and insert().

void QCborArray::pop_front()

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

See also removeFirst(), takeFirst(), pop_back(), push_front(), prepend(), and insert().

void QCborArray::prepend(const QCborValue &value)

Prepends value into the array before any other elements it may already contain.

See also at(), operator[](), first(), last(), insert(), append(), removeAt(), and takeAt().

void QCborArray::prepend(QCborValue &&value)

Prepends value into the array before any other elements it may already contain.

See also at(), operator[](), first(), last(), insert(), append(), removeAt(), and takeAt().

void QCborArray::push_back(const QCborValue &t)

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.

See also append(), push_front(), pop_back(), prepend(), and insert().

void QCborArray::push_front(const QCborValue &t)

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.

See also prepend(), push_back(), pop_front(), append(), and insert().

void QCborArray::removeAt(qsizetype i)

Removes the item at position i from the array. The array must have more than i elements before the removal.

See also takeAt(), removeFirst(), removeLast(), at(), operator[](), insert(), prepend(), and append().

void QCborArray::removeFirst()

Removes the first item in the array, making the second element become the first. The array must not be empty before this call.

See also removeAt(), takeFirst(), removeLast(), at(), operator[](), insert(), prepend(), and append().

void QCborArray::removeLast()

Removes the last item in the array. The array must not be empty before this call.

See also removeAt(), takeLast(), removeFirst(), at(), operator[](), insert(), prepend(), and append().

QCborValue QCborArray::takeAt(qsizetype i)

Removes the item at position i from the array and returns it. The array must have more than i elements before the removal.

See also removeAt(), removeFirst(), removeLast(), at(), operator[](), insert(), prepend(), and append().

QCborValue QCborArray::takeFirst()

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.

See also takeAt(), removeFirst(), removeLast(), at(), operator[](), insert(), prepend(), and append().

QCborValue QCborArray::takeLast()

Removes the last item in the array and returns it. The array must not be empty before this call.

See also takeAt(), removeLast(), removeFirst(), at(), operator[](), insert(), prepend(), and append().

QJsonArray QCborArray::toJsonArray() const

Recursively converts every 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().

See also fromJsonArray(), QCborValue::toJsonValue(), QCborMap::toJsonObject(), and toVariantList().

QVariantList QCborArray::toVariantList() const

Recursively converts each QCborValue in this array using QCborValue::toVariant() and returns the QVariantList composed of the converted items.

Conversion to QVariant is not completely lossless. Please see the documentation in QCborValue::toVariant() for more information.

See also fromVariantList(), fromStringList(), toJsonArray(), QCborValue::toVariant(), and QCborMap::toVariantMap().

QCborArray QCborArray::operator+(const QCborValue &v) const

Returns a new QCborArray containing the same elements as this array, plus v appended as the last element.

See also operator+=(), operator<<(), and append().

QCborArray &QCborArray::operator+=(const QCborValue &v)

Appends v to this array and returns a reference to this array.

See also append(), insert(), operator+(), and operator<<().

QCborArray &QCborArray::operator<<(const QCborValue &v)

Appends v to this array and returns a reference to this array.

See also append(), insert(), operator+(), and operator+=().

const QCborValue QCborArray::operator[](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 contains an undefined value at position i.

See also at(), first(), last(), insert(), prepend(), append(), removeAt(), and takeAt().

QCborValueRef QCborArray::operator[](qsizetype i)

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 QCborValue, with one important difference: if you assign new values to it, this array will be updated with that new value.

See also at(), first(), last(), insert(), prepend(), append(), removeAt(), and takeAt().