blob: dbe7b92db5262656c3ba1f3a6e2f8a91b91d2f6b [file] [log] [blame]
David 'Digit' Turner2910f182010-05-10 18:48:35 -07001/*
David Turnerfd4c0072010-09-09 21:23:36 +02002 * QList Module
David 'Digit' Turner2910f182010-05-10 18:48:35 -07003 *
4 * Copyright (C) 2009 Red Hat Inc.
5 *
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
8 *
David Turnerfd4c0072010-09-09 21:23:36 +02009 * 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.
David 'Digit' Turner2910f182010-05-10 18:48:35 -070011 */
David Turnerfd4c0072010-09-09 21:23:36 +020012
David 'Digit' Turner2910f182010-05-10 18:48:35 -070013#ifndef QLIST_H
14#define QLIST_H
15
16#include "qobject.h"
17#include "qemu-queue.h"
18#include "qemu-common.h"
19
20typedef struct QListEntry {
21 QObject *value;
22 QTAILQ_ENTRY(QListEntry) next;
23} QListEntry;
24
25typedef 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
33#define QLIST_FOREACH_ENTRY(qlist, var) \
34 for ((var) = ((qlist)->head.tqh_first); \
35 (var); \
36 (var) = ((var)->next.tqe_next))
37
38static inline QObject *qlist_entry_obj(const QListEntry *entry)
39{
40 return entry->value;
41}
42
43QList *qlist_new(void);
44QList *qlist_copy(QList *src);
45void qlist_append_obj(QList *qlist, QObject *obj);
46void qlist_iter(const QList *qlist,
47 void (*iter)(QObject *obj, void *opaque), void *opaque);
48QObject *qlist_pop(QList *qlist);
49QObject *qlist_peek(QList *qlist);
50int qlist_empty(const QList *qlist);
51QList *qobject_to_qlist(const QObject *obj);
52
53#endif /* QLIST_H */