Permalink
Browse files

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>
  • Loading branch information...
Luiz Capitulino Anthony Liguori
Luiz Capitulino authored and Anthony Liguori committed Oct 13, 2009
1 parent 422c46a commit 21f800d340ae080435f08e762d7b2868204c3772
Showing with 22 additions and 0 deletions.
  1. +19 −0 qdict.c
  2. +3 −0 qdict.h
View
19 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
*/
View
@@ -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) \

0 comments on commit 21f800d

Please sign in to comment.