77#include < QtCore/qobject.h>
88#include < QtCore/qfuture.h>
99#include < QtCore/qmetaobject.h>
10+ #include < functional>
1011
1112namespace QtDataSync {
1213
@@ -44,6 +45,10 @@ class Q_DATASYNC_EXPORT AsyncDataStore : public QObject
4445 Task remove (int metaTypeId, const QVariant &key);
4546 // ! @copybrief AsyncDataStore::search(const QString &)
4647 Task search (int dataMetaTypeId, int listMetaTypeId, const QString &query);
48+ // ! @copybrief AsyncDataStore::iterate(const std::function<bool(T)> &, const std::function<void(const QException &)> &)
49+ void iterate(int metaTypeId,
50+ const std::function<bool (QVariant)> &iterator,
51+ const std::function<void (const QException &)> &onExcept);
4752
4853 // ! Counts the number of datasets for the given type
4954 template <typename T>
@@ -72,6 +77,10 @@ class Q_DATASYNC_EXPORT AsyncDataStore : public QObject
7277 // ! Searches the store for datasets of the given type where the key matches the query
7378 template <typename T>
7479 GenericTask<QList<T>> search (const QString &query);
80+ // ! Asynchronously iterates over all existing datasets of the given types
81+ template <typename T>
82+ void iterate(const std::function<bool (T)> &iterator,
83+ const std::function<void (const QException &)> &onExcept);
7584
7685 // ! Loads the dataset with the given key for the given type into the existing object by updating it's properties
7786 template <typename T>
@@ -96,6 +105,13 @@ class Q_DATASYNC_EXPORT AsyncDataStore : public QObject
96105 QFutureInterface<QVariant> internalSave (int metaTypeId, const QVariant &value);
97106 QFutureInterface<QVariant> internalRemove (int metaTypeId, const QString &key);
98107 QFutureInterface<QVariant> internalSearch (int dataMetaTypeId, int listMetaTypeId, const QString &query);
108+
109+ void internalIterate (int metaTypeId,
110+ const QStringList &keys,
111+ int index,
112+ QVariant res,
113+ const std::function<bool (QVariant)> &iterator,
114+ const std::function<void(const QException &)> &onExcept);
99115};
100116
101117template <typename T>
@@ -152,6 +168,14 @@ GenericTask<QList<T>> AsyncDataStore::search(const QString &query)
152168 return internalSearch (qMetaTypeId<T>(), qMetaTypeId<QList<T>>(), query);
153169}
154170
171+ template <typename T>
172+ void AsyncDataStore::iterate (const std::function<bool (T)> &iterator, const std::function<void(const QException &)> &onExcept)
173+ {
174+ return iterate(qMetaTypeId<T>(), [iterator](QVariant variant) {
175+ return iterator (variant.template value <T>());
176+ }, onExcept);
177+ }
178+
155179template <typename T>
156180UpdateTask<T> AsyncDataStore::loadInto (const QString &key, const T &object)
157181{
0 commit comments