]>
Commit | Line | Data |
---|---|---|
a6fd08eb | 1 | /* |
41836a9f | 2 | * QList Module |
a6fd08eb LC |
3 | * |
4 | * Copyright (C) 2009 Red Hat Inc. | |
5 | * | |
6 | * Authors: | |
7 | * Luiz Capitulino <lcapitulino@redhat.com> | |
8 | * | |
41836a9f LC |
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. | |
a6fd08eb | 11 | */ |
41836a9f | 12 | |
a6fd08eb LC |
13 | #ifndef QLIST_H |
14 | #define QLIST_H | |
15 | ||
7b1b5d19 | 16 | #include "qapi/qmp/qobject.h" |
1de7afc9 | 17 | #include "qemu/queue.h" |
a6fd08eb LC |
18 | |
19 | typedef struct QListEntry { | |
20 | QObject *value; | |
21 | QTAILQ_ENTRY(QListEntry) next; | |
22 | } QListEntry; | |
23 | ||
24 | typedef struct QList { | |
25 | QObject_HEAD; | |
26 | QTAILQ_HEAD(,QListEntry) head; | |
27 | } QList; | |
28 | ||
29 | #define qlist_append(qlist, obj) \ | |
30 | qlist_append_obj(qlist, QOBJECT(obj)) | |
31 | ||
59eb1c85 LC |
32 | #define QLIST_FOREACH_ENTRY(qlist, var) \ |
33 | for ((var) = ((qlist)->head.tqh_first); \ | |
34 | (var); \ | |
35 | (var) = ((var)->next.tqe_next)) | |
36 | ||
37 | static inline QObject *qlist_entry_obj(const QListEntry *entry) | |
38 | { | |
39 | return entry->value; | |
40 | } | |
41 | ||
a6fd08eb | 42 | QList *qlist_new(void); |
033815fe | 43 | QList *qlist_copy(QList *src); |
a6fd08eb LC |
44 | void qlist_append_obj(QList *qlist, QObject *obj); |
45 | void qlist_iter(const QList *qlist, | |
46 | void (*iter)(QObject *obj, void *opaque), void *opaque); | |
033815fe AL |
47 | QObject *qlist_pop(QList *qlist); |
48 | QObject *qlist_peek(QList *qlist); | |
49 | int qlist_empty(const QList *qlist); | |
a86a4c2f | 50 | size_t qlist_size(const QList *qlist); |
a6fd08eb LC |
51 | QList *qobject_to_qlist(const QObject *obj); |
52 | ||
54d83804 MR |
53 | static inline const QListEntry *qlist_first(const QList *qlist) |
54 | { | |
55 | return QTAILQ_FIRST(&qlist->head); | |
56 | } | |
57 | ||
58 | static inline const QListEntry *qlist_next(const QListEntry *entry) | |
59 | { | |
60 | return QTAILQ_NEXT(entry, next); | |
61 | } | |
62 | ||
a6fd08eb | 63 | #endif /* QLIST_H */ |