From 098f3940557332a818f30c29dfecd16a0c4d3571 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 15 Dec 2016 10:49:27 +0100 Subject: PersistentPool: Replace {store,load}QVariantMap with generic version That one can also be used to store other QMaps as well as QHashes. Change-Id: Icb71c7ef293d115ea2518ddd9e16d094fb91625e Reviewed-by: Joerg Bornemann --- src/lib/corelib/tools/persistence.h | 38 ++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/lib/corelib/tools/persistence.h') diff --git a/src/lib/corelib/tools/persistence.h b/src/lib/corelib/tools/persistence.h index 25529ccf7..f1bfd439d 100644 --- a/src/lib/corelib/tools/persistence.h +++ b/src/lib/corelib/tools/persistence.h @@ -98,9 +98,6 @@ private: void storePersistentObject(const PersistentObject *object); - void storeVariantMap(const QVariantMap &map); - QVariantMap loadVariantMap(); - void storeVariant(const QVariant &variant); QVariant loadVariant(); @@ -223,12 +220,6 @@ template<> struct PersistentPool::Helper static void load(QVariant &v, PersistentPool *pool) { v = pool->loadVariant(); } }; -template<> struct PersistentPool::Helper -{ - static void store(const QVariantMap &map, PersistentPool *pool) { pool->storeVariantMap(map); } - static void load(QVariantMap &map, PersistentPool *pool) { map = pool->loadVariantMap(); } -}; - class ArtifactSet; template struct IsSimpleContainer { static const bool value = false; }; template<> struct IsSimpleContainer { static const bool value = true; }; @@ -256,6 +247,35 @@ struct PersistentPool::Helper::v } }; +template struct IsKeyValueContainer { static const bool value = false; }; +template struct IsKeyValueContainer> +{ + static const bool value = true; +}; + +template +struct PersistentPool::Helper::value>::type> +{ + static void store(const T &container, PersistentPool *pool) + { + pool->stream() << container.count(); + for (auto it = container.cbegin(); it != container.cend(); ++it) { + pool->store(it.key()); + pool->store(it.value()); + } + } + static void load(T &container, PersistentPool *pool) + { + container.clear(); + const int count = pool->load(); + for (int i = 0; i < count; ++i) { + const auto &key = pool->load(); + const auto &value = pool->load(); + container.insert(key, value); + } + } +}; + } // namespace Internal } // namespace qbs -- cgit v1.2.3