qlist.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef QLIST_H
  13. #define QLIST_H
  14. #include "qobject.h"
  15. #include "qemu-queue.h"
  16. #include "qemu-common.h"
  17. #include "qemu-queue.h"
  18. typedef struct QListEntry {
  19. QObject *value;
  20. QTAILQ_ENTRY(QListEntry) next;
  21. } QListEntry;
  22. typedef struct QList {
  23. QObject_HEAD;
  24. QTAILQ_HEAD(,QListEntry) head;
  25. } QList;
  26. #define qlist_append(qlist, obj) \
  27. qlist_append_obj(qlist, QOBJECT(obj))
  28. #define QLIST_FOREACH_ENTRY(qlist, var) \
  29. for ((var) = ((qlist)->head.tqh_first); \
  30. (var); \
  31. (var) = ((var)->next.tqe_next))
  32. static inline QObject *qlist_entry_obj(const QListEntry *entry)
  33. {
  34. return entry->value;
  35. }
  36. QList *qlist_new(void);
  37. QList *qlist_copy(QList *src);
  38. void qlist_append_obj(QList *qlist, QObject *obj);
  39. void qlist_iter(const QList *qlist,
  40. void (*iter)(QObject *obj, void *opaque), void *opaque);
  41. QObject *qlist_pop(QList *qlist);
  42. QObject *qlist_peek(QList *qlist);
  43. int qlist_empty(const QList *qlist);
  44. QList *qobject_to_qlist(const QObject *obj);
  45. static inline const QListEntry *qlist_first(const QList *qlist)
  46. {
  47. return QTAILQ_FIRST(&qlist->head);
  48. }
  49. static inline const QListEntry *qlist_next(const QListEntry *entry)
  50. {
  51. return QTAILQ_NEXT(entry, next);
  52. }
  53. #endif /* QLIST_H */