Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 1 | /* |
Luiz Capitulino | 41836a9 | 2010-05-12 16:34:42 -0300 | [diff] [blame] | 2 | * QList Module |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2009 Red Hat Inc. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Luiz Capitulino <lcapitulino@redhat.com> |
| 8 | * |
Luiz Capitulino | 41836a9 | 2010-05-12 16:34:42 -0300 | [diff] [blame] | 9 | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. |
| 10 | * See the COPYING.LIB file in the top-level directory. |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 11 | */ |
Luiz Capitulino | 41836a9 | 2010-05-12 16:34:42 -0300 | [diff] [blame] | 12 | |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 13 | #ifndef QLIST_H |
| 14 | #define QLIST_H |
| 15 | |
| 16 | #include "qobject.h" |
| 17 | #include "qemu-queue.h" |
| 18 | #include "qemu-common.h" |
Michael Roth | 54d8380 | 2011-07-19 14:50:30 -0500 | [diff] [blame] | 19 | #include "qemu-queue.h" |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 20 | |
| 21 | typedef struct QListEntry { |
| 22 | QObject *value; |
| 23 | QTAILQ_ENTRY(QListEntry) next; |
| 24 | } QListEntry; |
| 25 | |
| 26 | typedef struct QList { |
| 27 | QObject_HEAD; |
| 28 | QTAILQ_HEAD(,QListEntry) head; |
| 29 | } QList; |
| 30 | |
| 31 | #define qlist_append(qlist, obj) \ |
| 32 | qlist_append_obj(qlist, QOBJECT(obj)) |
| 33 | |
Luiz Capitulino | 59eb1c8 | 2010-01-21 19:15:38 -0200 | [diff] [blame] | 34 | #define QLIST_FOREACH_ENTRY(qlist, var) \ |
| 35 | for ((var) = ((qlist)->head.tqh_first); \ |
| 36 | (var); \ |
| 37 | (var) = ((var)->next.tqe_next)) |
| 38 | |
| 39 | static inline QObject *qlist_entry_obj(const QListEntry *entry) |
| 40 | { |
| 41 | return entry->value; |
| 42 | } |
| 43 | |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 44 | QList *qlist_new(void); |
Anthony Liguori | 033815f | 2009-11-11 10:48:51 -0600 | [diff] [blame] | 45 | QList *qlist_copy(QList *src); |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 46 | void qlist_append_obj(QList *qlist, QObject *obj); |
| 47 | void qlist_iter(const QList *qlist, |
| 48 | void (*iter)(QObject *obj, void *opaque), void *opaque); |
Anthony Liguori | 033815f | 2009-11-11 10:48:51 -0600 | [diff] [blame] | 49 | QObject *qlist_pop(QList *qlist); |
| 50 | QObject *qlist_peek(QList *qlist); |
| 51 | int qlist_empty(const QList *qlist); |
Michael Roth | a86a4c2 | 2012-08-15 13:45:42 -0500 | [diff] [blame] | 52 | size_t qlist_size(const QList *qlist); |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 53 | QList *qobject_to_qlist(const QObject *obj); |
| 54 | |
Michael Roth | 54d8380 | 2011-07-19 14:50:30 -0500 | [diff] [blame] | 55 | static inline const QListEntry *qlist_first(const QList *qlist) |
| 56 | { |
| 57 | return QTAILQ_FIRST(&qlist->head); |
| 58 | } |
| 59 | |
| 60 | static inline const QListEntry *qlist_next(const QListEntry *entry) |
| 61 | { |
| 62 | return QTAILQ_NEXT(entry, next); |
| 63 | } |
| 64 | |
Luiz Capitulino | a6fd08e | 2009-10-07 13:41:48 -0300 | [diff] [blame] | 65 | #endif /* QLIST_H */ |