xref: /openbmc/qemu/include/qapi/qmp/qlist.h (revision 05caa062)
1 /*
2  * QList Module
3  *
4  * Copyright (C) 2009 Red Hat Inc.
5  *
6  * Authors:
7  *  Luiz Capitulino <lcapitulino@redhat.com>
8  *
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.
11  */
12 
13 #ifndef QLIST_H
14 #define QLIST_H
15 
16 #include "qapi/qmp/qobject.h"
17 #include "qemu/queue.h"
18 
19 typedef struct QListEntry {
20     QObject *value;
21     QTAILQ_ENTRY(QListEntry) next;
22 } QListEntry;
23 
24 struct QList {
25     struct QObjectBase_ base;
26     QTAILQ_HEAD(,QListEntry) head;
27 };
28 
29 void qlist_unref(QList *q);
30 
31 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QList, qlist_unref)
32 
33 #define qlist_append(qlist, obj) \
34         qlist_append_obj(qlist, QOBJECT(obj))
35 
36 void qlist_append_bool(QList *qlist, bool value);
37 void qlist_append_int(QList *qlist, int64_t value);
38 void qlist_append_null(QList *qlist);
39 void qlist_append_str(QList *qlist, const char *value);
40 
41 #define QLIST_FOREACH_ENTRY(qlist, var)                 \
42         for ((var) = QTAILQ_FIRST(&(qlist)->head);      \
43              (var);                                     \
44              (var) = QTAILQ_NEXT((var), next))
45 
46 static inline QObject *qlist_entry_obj(const QListEntry *entry)
47 {
48     return entry->value;
49 }
50 
51 QList *qlist_new(void);
52 QList *qlist_copy(QList *src);
53 void qlist_append_obj(QList *qlist, QObject *obj);
54 QObject *qlist_pop(QList *qlist);
55 QObject *qlist_peek(QList *qlist);
56 int qlist_empty(const QList *qlist);
57 size_t qlist_size(const QList *qlist);
58 
59 static inline const QListEntry *qlist_first(const QList *qlist)
60 {
61     return QTAILQ_FIRST(&qlist->head);
62 }
63 
64 static inline const QListEntry *qlist_next(const QListEntry *entry)
65 {
66     return QTAILQ_NEXT(entry, next);
67 }
68 
69 #endif /* QLIST_H */
70