Qt 6.x
The Qt SDK
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
84 : d(nullptr)
85{
86}
87
92 : d(other.d)
93{
94}
95
111{
112}
113
119{
120 d = other.d;
121 return *this;
122}
123
151{
152 return d ? d->elements.size() : 0;
153}
154
161{
162 d.reset();
163}
164
186{
187 if (!d || size_t(i) >= size_t(size()))
188 return QCborValue();
189 return d->valueAt(i);
190}
191
290{
291 if (i < 0) {
292 Q_ASSERT(i == -1);
293 i = size();
294 detach(i + 1);
295 } else {
296 d = QCborContainerPrivate::grow(d.data(), i); // detaches
297 }
298 d->insertAt(i, value);
299}
300
302{
303 if (i < 0) {
304 Q_ASSERT(i == -1);
305 i = size();
306 detach(i + 1);
307 } else {
308 d = QCborContainerPrivate::grow(d.data(), i); // detaches
309 }
312}
313
324{
325 detach();
326
327 QCborValue v = d->extractAt(it.item.i);
328 d->removeAt(it.item.i);
329 return v;
330}
331
362{
363 detach(size());
364 d->removeAt(i);
365}
366
421{
422 for (qsizetype i = 0; i < size(); ++i) {
423 int cmp = d->compareElement(i, value);
424 if (cmp == 0)
425 return true;
426 }
427 return false;
428}
429
669void QCborArray::detach(qsizetype reserved)
670{
671 d = QCborContainerPrivate::detach(d.data(), reserved ? reserved : size());
672}
673
1169size_t qHash(const QCborArray &array, size_t seed)
1170{
1171 return qHashRange(array.begin(), array.end(), seed);
1172}
1173
1174#if !defined(QT_NO_DEBUG_STREAM)
1176{
1177 QDebugStateSaver saver(dbg);
1178 dbg.nospace() << "QCborArray{";
1179 const char *comma = "";
1180 for (auto v : a) {
1181 dbg << comma << v;
1182 comma = ", ";
1183 }
1184 return dbg << '}';
1185}
1186#endif
1187
1188#ifndef QT_NO_DATASTREAM
1189#if QT_CONFIG(cborstreamwriter)
1191{
1192 stream << value.toCborValue().toCbor();
1193 return stream;
1194}
1195#endif
1196
1198{
1200 stream >> buffer;
1201 QCborParserError parseError{};
1202 value = QCborValue::fromCbor(buffer, &parseError).toArray();
1203 if (parseError.error)
1205 return stream;
1206}
1207#endif
1208
\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:172
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) const
static void resetValue(QCborValue &v)
QCborValue valueAt(qsizetype idx) const
\inmodule QtCore\reentrant
Definition qcborvalue.h:50
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\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:386
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:70
QSharedPointer< T > other(t)
[5]
\inmodule QtCore\reentrant
Definition qcborvalue.h:40