diff mbox

[1/4] QList: Introduce QLIST_FOREACH_ENTRY()

Message ID 1264108541-4071-2-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Jan. 21, 2010, 9:15 p.m. UTC
Iterate over QList entries, it's needed to call qlist_entry_obj()
to retrieve the stored QObject.

I'm not sure if it's ok to have this, because it's not as easy as
qlist_iter() and the QListEntry data type is now exposed to the
users, which means we have one more struct to be maintained when
we have libqmp.

Adding anyway, as it's more compact and people are asking for it.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qlist.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

Comments

Anthony Liguori Jan. 26, 2010, 10:05 p.m. UTC | #1
On 01/21/2010 03:15 PM, Luiz Capitulino wrote:
> Iterate over QList entries, it's needed to call qlist_entry_obj()
> to retrieve the stored QObject.
>
> I'm not sure if it's ok to have this, because it's not as easy as
> qlist_iter() and the QListEntry data type is now exposed to the
> users, which means we have one more struct to be maintained when
> we have libqmp.
>
> Adding anyway, as it's more compact and people are asking for it.
>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
>    
Applied all.  Thanks.

Regards,

Anthony Liguori
> ---
>   qlist.h |   10 ++++++++++
>   1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/qlist.h b/qlist.h
> index afdc446..a3261e1 100644
> --- a/qlist.h
> +++ b/qlist.h
> @@ -29,6 +29,16 @@ typedef struct QList {
>   #define qlist_append(qlist, obj) \
>           qlist_append_obj(qlist, QOBJECT(obj))
>
> +#define QLIST_FOREACH_ENTRY(qlist, var)             \
> +        for ((var) = ((qlist)->head.tqh_first);     \
> +            (var);                                  \
> +            (var) = ((var)->next.tqe_next))
> +
> +static inline QObject *qlist_entry_obj(const QListEntry *entry)
> +{
> +    return entry->value;
> +}
> +
>   QList *qlist_new(void);
>   QList *qlist_copy(QList *src);
>   void qlist_append_obj(QList *qlist, QObject *obj);
>
diff mbox

Patch

diff --git a/qlist.h b/qlist.h
index afdc446..a3261e1 100644
--- a/qlist.h
+++ b/qlist.h
@@ -29,6 +29,16 @@  typedef struct QList {
 #define qlist_append(qlist, obj) \
         qlist_append_obj(qlist, QOBJECT(obj))
 
+#define QLIST_FOREACH_ENTRY(qlist, var)             \
+        for ((var) = ((qlist)->head.tqh_first);     \
+            (var);                                  \
+            (var) = ((var)->next.tqe_next))
+
+static inline QObject *qlist_entry_obj(const QListEntry *entry)
+{
+    return entry->value;
+}
+
 QList *qlist_new(void);
 QList *qlist_copy(QList *src);
 void qlist_append_obj(QList *qlist, QObject *obj);