From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mxkgq-00042Q-B1 for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mxkgj-0003su-W2 for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:34 -0400 Received: from [199.232.76.173] (port=51959 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mxkgj-0003sa-Op for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37373) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mxkgj-00022q-6y for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:29 -0400 From: Luiz Capitulino Date: Tue, 13 Oct 2009 13:56:58 -0300 Message-Id: <1255453026-18637-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1255453026-18637-1-git-send-email-lcapitulino@redhat.com> References: <1255453026-18637-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PATCH 1/9] QDict: Introduce qdict_iter() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, kraxel@redhat.com This adds iterator support to QDict, it will be used by the (to be introduced) QError module. Signed-off-by: Luiz Capitulino --- qdict.c | 19 +++++++++++++++++++ qdict.h | 3 +++ 2 files changed, 22 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) diff --git a/qdict.h b/qdict.h index 3102ca2..14b2633 100644 --- 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) \ -- 1.6.5.rc3.8.g8ba5e