]>
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 <[email protected]> | |
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 | ||
16 | #include "qobject.h" | |
17 | #include "qemu-queue.h" | |
54d83804 | 18 | #include "qemu-queue.h" |
a6fd08eb LC |
19 | |
20 | typedef struct QListEntry { | |
21 | QObject *value; | |
22 | QTAILQ_ENTRY(QListEntry) next; | |
23 | } QListEntry; | |
24 | ||
25 | typedef struct QList { | |
26 | QObject_HEAD; | |
27 | QTAILQ_HEAD(,QListEntry) head; | |
28 | } QList; | |
29 | ||
30 | #define qlist_append(qlist, obj) \ | |
31 | qlist_append_obj(qlist, QOBJECT(obj)) | |
32 | ||
59eb1c85 LC |
33 | #define QLIST_FOREACH_ENTRY(qlist, var) \ |
34 | for ((var) = ((qlist)->head.tqh_first); \ | |
35 | (var); \ | |
36 | (var) = ((var)->next.tqe_next)) | |
37 | ||
38 | static inline QObject *qlist_entry_obj(const QListEntry *entry) | |
39 | { | |
40 | return entry->value; | |
41 | } | |
42 | ||
a6fd08eb | 43 | QList *qlist_new(void); |
033815fe | 44 | QList *qlist_copy(QList *src); |
a6fd08eb LC |
45 | void qlist_append_obj(QList *qlist, QObject *obj); |
46 | void qlist_iter(const QList *qlist, | |
47 | void (*iter)(QObject *obj, void *opaque), void *opaque); | |
033815fe AL |
48 | QObject *qlist_pop(QList *qlist); |
49 | QObject *qlist_peek(QList *qlist); | |
50 | int qlist_empty(const QList *qlist); | |
a86a4c2f | 51 | size_t qlist_size(const QList *qlist); |
a6fd08eb LC |
52 | QList *qobject_to_qlist(const QObject *obj); |
53 | ||
54d83804 MR |
54 | static inline const QListEntry *qlist_first(const QList *qlist) |
55 | { | |
56 | return QTAILQ_FIRST(&qlist->head); | |
57 | } | |
58 | ||
59 | static inline const QListEntry *qlist_next(const QListEntry *entry) | |
60 | { | |
61 | return QTAILQ_NEXT(entry, next); | |
62 | } | |
63 | ||
a6fd08eb | 64 | #endif /* QLIST_H */ |