1 #ifndef BGLIBS__GENERIC_STACK__H__ 2 #define BGLIBS__GENERIC_STACK__H__ 4 #include "adt_common.h" 43 #define GSTACK_DECL(PREFIX,TYPE) \ 44 extern int PREFIX##_push(struct gstack* s, TYPE const* data); \ 45 extern TYPE* PREFIX##_top(struct gstack* s); \ 46 extern void PREFIX##_pop(struct gstack* s); 49 #define GSTACK_PUSH_DEFN(PREFIX,TYPE,COPY) \ 50 int PREFIX##_push(struct gstack* s, TYPE const* data) { \ 51 return gstack_push(s, sizeof *data, data, (adt_copy_fn*)COPY); \ 55 #define GSTACK_TOP_DEFN(PREFIX,TYPE) \ 56 TYPE* PREFIX##_top(struct gstack* s) { \ 57 return (s->head == 0) ? 0 : (TYPE*)s->head->data; \ 61 #define GSTACK_POP_DEFN(PREFIX,FREE) \ 62 void PREFIX##_pop(struct gstack* s) { \ 63 gstack_pop(s, (adt_free_fn*)(FREE)); \ 69 #define GSTACK_DEFN(PREFIX,TYPE,COPY,FREE) \ 70 GSTACK_PUSH_DEFN(PREFIX,TYPE,COPY) \ 71 GSTACK_TOP_DEFN(PREFIX,TYPE) \ 72 GSTACK_POP_DEFN(PREFIX,FREE) void adt_free_fn(void *)
Definition: adt_common.h:12
void * gstack_top(const struct gstack *s)
Definition: gstack_top.c:5
void gstack_pop(struct gstack *s, adt_free_fn *fn)
Definition: gstack_pop.c:9
struct gstack_node * head
Definition: gstack.h:32
int gstack_push(struct gstack *d, unsigned datasize, const void *data, adt_copy_fn *fn)
Definition: gstack_push.c:8
int adt_copy_fn(void *, const void *)
Definition: adt_common.h:16
char data[0]
Definition: gstack.h:25
struct gstack_node * next
Definition: gstack.h:23
unsigned count
Definition: gstack.h:34