/* clist.h v0.1 (C) 1999 adolfo@di-mare.com */ #ifndef CLIST_H #define CLIST_H #include "binder.h" #ifdef __cplusplus extern "C" { #endif typedef struct link_rep_ { struct link_rep_ * next; } link_rep; typedef struct { link_rep * last; } clist_rep; typedef struct { link_rep private_; /* private */ } cl_link; typedef struct { clist_rep private_; /* private */ } clist, *pclist; void cl_link_init_(cl_link* lk); void cl_link_done_(cl_link* lk); void cl_init_ (clist *); void cl_link_after( clist *, cl_link*, cl_link*); cl_link* cl_unlink_after(clist *, cl_link*); cl_link* cl_first_ (const clist *); cl_link* cl_last_ (const clist *); cl_link* cl_next_ (const clist *, cl_link *); cl_link* cl_nth(const clist *L_, cl_link *q_, size_t n); size_t cl_count (const clist * L); int cl_empty_ (const clist * L); void cl_append_(clist *, cl_link*); /* All these require a binder */ void cl_swap_binder (clist * it, clist * src, const binder *); void cl_copy_binder (clist * it, clist * src, const binder *); int cl_equal_binder(const clist *, const clist *, const binder *); void cl_print_binder(const clist *, FILE *, const binder *); void cl_delete_all (clist * it, const binder *); void cl_done_binder_(clist * it, const binder *); #ifdef NDEBUG /* Use #define to optimize out code */ #define cl_link_init(lk) #define cl_link_done(lk) #else /* typecheck, but only a little */ #define cl_link_init(lk) ((link_rep*) lk)->next = NULL #define cl_link_done(lk) do {} while( (lk) != (lk) ) #endif #define cl_init(L) ((clist_rep*)(L))->last = NULL #define cl_first(L) (cl_link*) \ (( NULL == ((clist_rep*) L)->last ) \ ? NULL \ : ((clist_rep*)(L))->last->next ) #define cl_last(L) ((cl_link*) ((clist_rep*)(L))->last) #define cl_next(L,p) (cl_link*) \ (( (link_rep*) p == ((clist_rep*) L)->last ) \ ? NULL \ : ((link_rep*) p)->next ) #define cl_empty(L) ( NULL == cl_last(L) ) #define cl_append(L, p) \ cl_link_after(L, cl_last(L), p) #define push(S, p) cl_link_after(S, cl_last(S), p) #define pop(S, p) cl_unlink_after(S, NULL) #define cl_done_binder cl_delete_all #define COMPILE_NON_INLINE_METHODS #ifdef __cplusplus } #endif #endif /* CLIST_H */ /* EOF: clist.h */