qlist.h (1617B)
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 19typedef struct QListEntry { 20 QObject *value; 21 QTAILQ_ENTRY(QListEntry) next; 22} QListEntry; 23 24struct QList { 25 struct QObjectBase_ base; 26 QTAILQ_HEAD(,QListEntry) head; 27}; 28 29#define qlist_append(qlist, obj) \ 30 qlist_append_obj(qlist, QOBJECT(obj)) 31 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); 36 37#define QLIST_FOREACH_ENTRY(qlist, var) \ 38 for ((var) = QTAILQ_FIRST(&(qlist)->head); \ 39 (var); \ 40 (var) = QTAILQ_NEXT((var), next)) 41 42static inline QObject *qlist_entry_obj(const QListEntry *entry) 43{ 44 return entry->value; 45} 46 47QList *qlist_new(void); 48QList *qlist_copy(QList *src); 49void qlist_append_obj(QList *qlist, QObject *obj); 50QObject *qlist_pop(QList *qlist); 51QObject *qlist_peek(QList *qlist); 52int qlist_empty(const QList *qlist); 53size_t qlist_size(const QList *qlist); 54 55static inline const QListEntry *qlist_first(const QList *qlist) 56{ 57 return QTAILQ_FIRST(&qlist->head); 58} 59 60static inline const QListEntry *qlist_next(const QListEntry *entry) 61{ 62 return QTAILQ_NEXT(entry, next); 63} 64 65#endif /* QLIST_H */