1 #ifndef BGLIBS__GENERIC_QUEUE__H__
2 #define BGLIBS__GENERIC_QUEUE__H__
4 #include "adt_common.h"
45 #define GQUEUE_DECL(PREFIX,TYPE) \
46 extern int PREFIX##_push(struct gqueue* q, TYPE const* data); \
47 extern TYPE* PREFIX##_top(struct gqueue* q); \
48 extern void PREFIX##_pop(struct gqueue* q);
51 #define GQUEUE_PUSH_DEFN(PREFIX,TYPE,COPY) \
52 int PREFIX##_push(struct gqueue* q, TYPE const* data) { \
53 return gqueue_push(q, sizeof *data, data, (adt_copy_fn*)COPY); \
57 #define GQUEUE_TOP_DEFN(PREFIX,TYPE) \
58 TYPE* PREFIX##_top(struct gqueue* q) { \
59 return (q->head == 0) ? 0 : (TYPE*)q->head->data; \
63 #define GQUEUE_POP_DEFN(PREFIX,FREE) \
64 void PREFIX##_pop(struct gqueue* q) { \
65 gqueue_pop(q, (adt_free_fn*)(FREE)); \
71 #define GQUEUE_DEFN(PREFIX,TYPE,COPY,FREE) \
72 GQUEUE_PUSH_DEFN(PREFIX,TYPE,COPY) \
73 GQUEUE_TOP_DEFN(PREFIX,TYPE) \
74 GQUEUE_POP_DEFN(PREFIX,FREE)
int gqueue_push(struct gqueue *q, unsigned datasize, const void *data, adt_copy_fn *fn)
Definition: gqueue_push.c:8
void adt_free_fn(void *)
Definition: adt_common.h:12
void gqueue_pop(struct gqueue *q, adt_free_fn *fn)
Definition: gqueue_pop.c:9
struct gqueue_node * next
Definition: gqueue.h:23
char data[0]
Definition: gqueue.h:25
void * gqueue_top(const struct gqueue *q)
Definition: gqueue_top.c:5
unsigned count
Definition: gqueue.h:36
struct gqueue_node * tail
Definition: gqueue.h:34
struct gqueue_node * head
Definition: gqueue.h:32
int adt_copy_fn(void *, const void *)
Definition: adt_common.h:16