summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qcbormap.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-05-19 14:58:43 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-07-04 03:04:21 +0000
commit2bb44414ff456873c885391e4a03afb67e7306da (patch)
tree9d6f7d1b2912cd494073c10e23fd61543535a022 /src/corelib/serialization/qcbormap.h
parentfcb0f68e77bb69544f0ae310baffd3ceff8a9e5d (diff)
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 <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qcbormap.h')
-rw-r--r--src/corelib/serialization/qcbormap.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h
index 9499f46ace..89de3d6786 100644
--- a/src/corelib/serialization/qcbormap.h
+++ b/src/corelib/serialization/qcbormap.h
@@ -207,6 +207,14 @@ public:
QCborValueRef operator[](const QString & key);
QCborValueRef operator[](const QCborValue &key);
+ QCborValue take(qint64 key)
+ { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); }
+ QCborValue take(QLatin1String key)
+ { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); }
+ QCborValue take(const QString &key)
+ { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); }
+ QCborValue take(const QCborValue &key)
+ { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); }
void remove(qint64 key)
{ iterator it = find(key); if (it != end()) erase(it); }
void remove(QLatin1String key)
@@ -254,6 +262,8 @@ public:
const_iterator cend() const { return constEnd(); }
iterator erase(iterator it);
iterator erase(const_iterator it) { return erase(iterator{ it.item.d, it.item.i }); }
+ QCborValue extract(iterator it);
+ QCborValue extract(const_iterator it) { return extract(iterator{ it.item.d, it.item.i }); }
bool empty() const { return isEmpty(); }
iterator find(qint64 key);