From 2bb44414ff456873c885391e4a03afb67e7306da Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 19 May 2018 14:58:43 -0700 Subject: QCborArray & Map: implement efficient take() / extract() Questions: 1) should QCborMap::extract return value_type (a pair) instead of just the value? 2) should the both return the iterator to the next element too, like erase()? Change-Id: I052407b777ec43f78378fffd15302a9c14468db3 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/serialization/qcborarray.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/corelib/serialization/qcborarray.cpp') diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp index 020841d604..a1b0d1573c 100644 --- a/src/corelib/serialization/qcborarray.cpp +++ b/src/corelib/serialization/qcborarray.cpp @@ -42,6 +42,8 @@ QT_BEGIN_NAMESPACE +using namespace QtCbor; + /*! \class QCborArray \inmodule QtCore @@ -300,7 +302,7 @@ QCborValue QCborArray::at(qsizetype i) const must have at least \a i elements before the insertion. \sa at(), operator[](), first(), last(), prepend(), append(), - removeAt(), takeAt() + removeAt(), takeAt(), extract() */ void QCborArray::insert(qsizetype i, const QCborValue &value) { @@ -311,6 +313,21 @@ void QCborArray::insert(qsizetype i, const QCborValue &value) d->insertAt(i, value); } +/*! + Extracts a value from the array at the position indicated by iterator \a it + and returns the value so extracted. + + \sa insert(), erase(), takeAt(), removeAt() + */ +QCborValue QCborArray::extract(iterator it) +{ + detach(); + + QCborValue v = d->extractAt(it.item.i); + d->removeAt(it.item.i); + return v; +} + /*! \fn void QCborArray::prepend(const QCborValue &value) -- cgit v1.2.3