[v2,02/21] qlist: add qlist_first()/qlist_next()

Submitted by Michael Roth on June 3, 2011, 10:33 p.m.

Details

Message ID 1307140399-9023-3-git-send-email-mdroth@linux.vnet.ibm.com
State New
Headers show

Commit Message

Michael Roth June 3, 2011, 10:33 p.m.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qlist.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

Comments

Luiz Capitulino June 8, 2011, 5:50 p.m.
On Fri,  3 Jun 2011 17:33:00 -0500
Michael Roth <mdroth@linux.vnet.ibm.com> wrote:

> 
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  qlist.h |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
> 
> diff --git a/qlist.h b/qlist.h
> index dbe7b92..cd2d23e 100644
> --- a/qlist.h
> +++ b/qlist.h
> @@ -16,6 +16,7 @@
>  #include "qobject.h"
>  #include "qemu-queue.h"
>  #include "qemu-common.h"
> +#include "qemu-queue.h"
>  
>  typedef struct QListEntry {
>      QObject *value;
> @@ -50,4 +51,14 @@ QObject *qlist_peek(QList *qlist);
>  int qlist_empty(const QList *qlist);
>  QList *qobject_to_qlist(const QObject *obj);
>  
> +static inline QListEntry *qlist_first(QList *qlist)
> +{
> +    return QTAILQ_FIRST(&qlist->head);
> +}
> +
> +static inline QListEntry *qlist_next(QListEntry *entry)
> +{
> +    return QTAILQ_NEXT(entry, next);
> +}

I'm not sure how the return value (QListEntry) is being used, but the same
interface for qdict returns a const value and users use get functions to
get visible members. The rationale is that QListEntry and QDictEntry
shouldn't be visible to users.

And the input parameter can be const too and would be nice to have
unit-tests...

> +
>  #endif /* QLIST_H */

Patch hide | download patch | download mbox

diff --git a/qlist.h b/qlist.h
index dbe7b92..cd2d23e 100644
--- a/qlist.h
+++ b/qlist.h
@@ -16,6 +16,7 @@ 
 #include "qobject.h"
 #include "qemu-queue.h"
 #include "qemu-common.h"
+#include "qemu-queue.h"
 
 typedef struct QListEntry {
     QObject *value;
@@ -50,4 +51,14 @@  QObject *qlist_peek(QList *qlist);
 int qlist_empty(const QList *qlist);
 QList *qobject_to_qlist(const QObject *obj);
 
+static inline QListEntry *qlist_first(QList *qlist)
+{
+    return QTAILQ_FIRST(&qlist->head);
+}
+
+static inline QListEntry *qlist_next(QListEntry *entry)
+{
+    return QTAILQ_NEXT(entry, next);
+}
+
 #endif /* QLIST_H */