]> git.proxmox.com Git - mirror_qemu.git/blame - include/qapi/qmp/qlist.h
qdict qlist: Make most helper macros functions
[mirror_qemu.git] / include / qapi / qmp / qlist.h
CommitLineData
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
19typedef struct QListEntry {
20 QObject *value;
21 QTAILQ_ENTRY(QListEntry) next;
22} QListEntry;
23
9f5c734d 24struct QList {
c7c46212 25 QObject base;
a6fd08eb 26 QTAILQ_HEAD(,QListEntry) head;
9f5c734d 27};
a6fd08eb
LC
28
29#define qlist_append(qlist, obj) \
30 qlist_append_obj(qlist, QOBJECT(obj))
31
15280c36
MA
32void qlist_append_bool(QList *qlist, bool value);
33void qlist_append_int(QList *qlist, int64_t value);
34void qlist_append_null(QList *qlist);
35void qlist_append_str(QList *qlist, const char *value);
a92c2159 36
59eb1c85
LC
37#define QLIST_FOREACH_ENTRY(qlist, var) \
38 for ((var) = ((qlist)->head.tqh_first); \
39 (var); \
40 (var) = ((var)->next.tqe_next))
41
42static inline QObject *qlist_entry_obj(const QListEntry *entry)
43{
44 return entry->value;
45}
46
a6fd08eb 47QList *qlist_new(void);
033815fe 48QList *qlist_copy(QList *src);
a6fd08eb
LC
49void qlist_append_obj(QList *qlist, QObject *obj);
50void qlist_iter(const QList *qlist,
51 void (*iter)(QObject *obj, void *opaque), void *opaque);
033815fe
AL
52QObject *qlist_pop(QList *qlist);
53QObject *qlist_peek(QList *qlist);
54int qlist_empty(const QList *qlist);
a86a4c2f 55size_t qlist_size(const QList *qlist);
a6fd08eb 56QList *qobject_to_qlist(const QObject *obj);
b38dd678 57bool qlist_is_equal(const QObject *x, const QObject *y);
55e1819c 58void qlist_destroy_obj(QObject *obj);
a6fd08eb 59
54d83804
MR
60static inline const QListEntry *qlist_first(const QList *qlist)
61{
62 return QTAILQ_FIRST(&qlist->head);
63}
64
65static inline const QListEntry *qlist_next(const QListEntry *entry)
66{
67 return QTAILQ_NEXT(entry, next);
68}
69
a6fd08eb 70#endif /* QLIST_H */