Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcborarray.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qcborarray.h"
5#include "qcborvalue_p.h"
6#include "qdatastream.h"
7
9
10using namespace QtCbor;
11
88 : d(nullptr)
89{
90}
91
96 : d(other.d)
97{
98}
99
117
123{
124 d = other.d;
125 return *this;
126}
127
155{
156 return d ? d->elements.size() : 0;
157}
158
165{
166 d.reset();
167}
168
190{
191 if (!d || size_t(i) >= size_t(size()))
192 return QCborValue();
193 return d->valueAt(i);
194}
195
294{
295 if (i < 0) {
296 Q_ASSERT(i == -1);
297 i = size();
298 detach(i + 1);
299 } else {
300 d = QCborContainerPrivate::grow(d.data(), i); // detaches
301 }
302 d->insertAt(i, value);
303}
304
306{
307 if (i < 0) {
308 Q_ASSERT(i == -1);
309 i = size();
310 detach(i + 1);
311 } else {
312 d = QCborContainerPrivate::grow(d.data(), i); // detaches
313 }
316}
317
328{
329 detach();
330
331 QCborValue v = d->extractAt(it.item.i);
332 d->removeAt(it.item.i);
333 return v;
334}
335
366{
367 detach(size());
368 d->removeAt(i);
369}
370
425{
426 for (qsizetype i = 0; i < size(); ++i) {
427 int cmp = d->compareElement(i, value, Comparison::ForEquality);
428 if (cmp == 0)
429 return true;
430 }
431 return false;
432}
433
712void QCborArray::detach(qsizetype reserved)
713{
714 d = QCborContainerPrivate::detach(d.data(), reserved ? reserved : size());
715}
716
1214size_t qHash(const QCborArray &array, size_t seed)
1215{
1216 return qHashRange(array.begin(), array.end(), seed);
1217}
1218
1219#if !defined(QT_NO_DEBUG_STREAM)
1221{
1222 QDebugStateSaver saver(dbg);
1223 dbg.nospace() << "QCborArray{";
1224 const char *comma = "";
1225 for (auto v : a) {
1226 dbg << comma << v;
1227 comma = ", ";
1228 }
1229 return dbg << '}';
1230}
1231#endif
1232
1233#ifndef QT_NO_DATASTREAM
1234#if QT_CONFIG(cborstreamwriter)
1236{
1237 stream << value.toCborValue().toCbor();
1238 return stream;
1239}
1240#endif
1241
1243{
1245 stream >> buffer;
1246 QCborParserError parseError{};
1247 value = QCborValue::fromCbor(buffer, &parseError).toArray();
1248 if (parseError.error)
1249 stream.setStatus(QDataStream::ReadCorruptData);
1250 return stream;
1251}
1252#endif
1253
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qcborarray.h:23
\inmodule QtCore\reentrant
Definition qcborarray.h:20
QCborArray & operator=(const QCborArray &other) noexcept
Replaces the contents of this array with that found in other, then returns a reference to this object...
bool contains(const QCborValue &value) const
Returns true if this array contains an element that is equal to value.
void removeAt(qsizetype i)
Removes the item at position i from the array.
QCborArray() noexcept
Constructs an empty QCborArray.
qsizetype size() const noexcept
Returns the size of this array.
void insert(qsizetype i, const QCborValue &value)
~QCborArray()
Destroys this QCborArray and frees any associated resources.
QCborValue extract(ConstIterator it)
Extracts a value from the array at the position indicated by iterator it and returns the value so ext...
Definition qcborarray.h:246
void clear()
Empties this array.
QCborValue at(qsizetype i) const
Returns the QCborValue element at position i in the array.
void insertAt(qsizetype idx, const QCborValue &value, ContainerDisposition disp=CopyContainer)
static QCborContainerPrivate * grow(QCborContainerPrivate *d, qsizetype index)
Prepare for an insertion at position index.
static QCborContainerPrivate * detach(QCborContainerPrivate *d, qsizetype reserved)
void removeAt(qsizetype idx)
QList< QtCbor::Element > elements
QCborValue extractAt(qsizetype idx)
int compareElement(qsizetype idx, const QCborValue &value, QtCbor::Comparison mode) const
static void resetValue(QCborValue &v)
QCborValue valueAt(qsizetype idx) const
\inmodule QtCore\reentrant
Definition qcborvalue.h:47
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
void reset(T *ptr=nullptr) noexcept
T * data() const noexcept
Returns a pointer to the shared data object.
qsizetype size() const noexcept
Definition qlist.h:397
QSet< QString >::iterator it
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QCborArray &a)
size_t qHash(const QCborArray &array, size_t seed)
QDataStream & operator>>(QDataStream &stream, QCborArray &value)
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
size_t qHashRange(InputIterator first, InputIterator last, size_t seed=0) noexcept(noexcept(qHash(*first)))
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint buffer
GLenum array
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ptrdiff_t qsizetype
Definition qtypes.h:165
QSharedPointer< T > other(t)
[5]
\inmodule QtCore\reentrant
Definition qcborvalue.h:37