]> git.proxmox.com Git - qemu.git/commitdiff
QDict: Introduce qdict_iter()
authorLuiz Capitulino <lcapitulino@redhat.com>
Tue, 13 Oct 2009 16:56:58 +0000 (13:56 -0300)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 17 Nov 2009 14:49:39 +0000 (08:49 -0600)
This adds iterator support to QDict, it will be used by the
(to be introduced) QError module.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qdict.c
qdict.h

diff --git a/qdict.c b/qdict.c
index a302f4c0c402845d9e68aea6c5a89a3399b2363c..0e04cb1feded31435acbaf17bd5fcd419f3eff2d 100644 (file)
--- a/qdict.c
+++ b/qdict.c
@@ -241,6 +241,25 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key)
     return qstring_get_str(qobject_to_qstring(obj));
 }
 
+/**
+ * qdict_iter(): Iterate over all the dictionary's stored values.
+ *
+ * This function allows the user to provide an iterator, which will be
+ * called for each stored value in the dictionary.
+ */
+void qdict_iter(const QDict *qdict,
+                void (*iter)(const char *key, QObject *obj, void *opaque),
+                void *opaque)
+{
+    int i;
+    QDictEntry *entry;
+
+    for (i = 0; i < QDICT_HASH_SIZE; i++) {
+        QLIST_FOREACH(entry, &qdict->table[i], next)
+            iter(entry->key, entry->value, opaque);
+    }
+}
+
 /**
  * qentry_destroy(): Free all the memory allocated by a QDictEntry
  */
diff --git a/qdict.h b/qdict.h
index 3102ca296f5caa96b62e9897d055065ca8f21189..14b26330f7ba7ae629b183e3353103d2241bd977 100644 (file)
--- a/qdict.h
+++ b/qdict.h
@@ -27,6 +27,9 @@ void qdict_del(QDict *qdict, const char *key);
 int qdict_haskey(const QDict *qdict, const char *key);
 QObject *qdict_get(const QDict *qdict, const char *key);
 QDict *qobject_to_qdict(const QObject *obj);
+void qdict_iter(const QDict *qdict,
+                void (*iter)(const char *key, QObject *obj, void *opaque),
+                void *opaque);
 
 /* Helper to qdict_put_obj(), accepts any object */
 #define qdict_put(qdict, key, obj) \