aboutsummaryrefslogtreecommitdiff
path: root/qdict.c
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2009-10-13 13:56:58 -0300
committerAnthony Liguori <aliguori@us.ibm.com>2009-11-17 08:49:39 -0600
commit21f800d340ae080435f08e762d7b2868204c3772 (patch)
tree894385bcf7f5784879782fbf7ad76e3997e2db9c /qdict.c
parent422c46a81d41748d5d944b68c4b81b58092ca34e (diff)
downloadqemu-21f800d340ae080435f08e762d7b2868204c3772.zip
qemu-21f800d340ae080435f08e762d7b2868204c3772.tar.gz
qemu-21f800d340ae080435f08e762d7b2868204c3772.tar.bz2
QDict: Introduce qdict_iter()
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>
Diffstat (limited to 'qdict.c')
-rw-r--r--qdict.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/qdict.c b/qdict.c
index a302f4c..0e04cb1 100644
--- a/qdict.c
+++ b/qdict.c
@@ -242,6 +242,25 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key)
}
/**
+ * 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
*/
static void qentry_destroy(QDictEntry *e)