4 ** $VER: ListMacros.h 2.1 (1.9.97)
6 ** Copyright (C) 1996,97 Bernardo Innocenti. All rights reserved.
8 ** Use 4 chars wide TABs to read this source
10 ** Some handy macros for list operations. Using these macros is faster
11 ** than calling their exec.library equivalents, but they will eventually
12 ** make your code a little bigger and are also subject to common macro
17 #define NEWLIST(l) ( (l)->lh_TailPred = (struct Node *)(l), \
19 (l)->lh_Head = (struct Node *)(&((l)->lh_Tail)) )
21 #define ADDHEAD(l,n) ( (n)->ln_Pred = (struct Node *)(l), \
22 (n)->ln_Succ = (l)->lh_Head, \
23 (l)->lh_Head->ln_Pred = (n), \
26 #define ADDTAIL(l,n) ( (n)->ln_Succ = (struct Node *)(&((l)->lh_Tail)), \
27 (n)->ln_Pred = (l)->lh_TailPred, \
28 (l)->lh_TailPred->ln_Succ = (n), \
29 (l)->lh_TailPred = (n) )
31 #define REMOVE(n) ( (n)->ln_Succ->ln_Pred = (n)->ln_Pred, \
32 (n)->ln_Pred->ln_Succ = (n)->ln_Succ )
34 #define GETHEAD(l) ( (l)->lh_Head->ln_Succ ? (l)->lh_Head : (struct Node *)NULL )
36 #define GETTAIL(l) ( (l)->lh_TailPred->ln_Succ ? (l)->lh_TailPred : (struct Node *)NULL )
38 #define GETSUCC(n) ( (n)->ln_Succ->ln_Succ ? (n)->ln_Succ : (struct Node *)NULL )
40 #define GETPRED(n) ( (n)->ln_Pred->ln_Pred ? (n)->ln_Pred : (struct Node *)NULL )
47 struct Node *n = (l)->lh_Head; \
49 (l)->lh_Head = n->ln_Succ, \
50 (l)->lh_Head->ln_Pred = (struct Node *)(l), \
57 struct Node *n = (l)->lh_TailPred; \
59 (l)->lh_TailPred = n->ln_Pred, \
60 (l)->lh_TailPred->ln_Succ = (struct Node *)(&((l)->lh_Tail)), \
68 /* These two can't be implemented as macros without the GCC ({...}) language extension */
70 INLINE struct Node *REMHEAD(struct List *l)
72 struct Node *n = l->lh_Head;
76 l->lh_Head = n->ln_Succ;
77 l->lh_Head->ln_Pred = (struct Node *)l;
83 INLINE struct Node *REMTAIL(struct List *l)
85 struct Node *n = l->lh_TailPred;
89 l->lh_TailPred = n->ln_Pred;
90 l->lh_TailPred->ln_Succ = (struct Node *)(&(l->lh_Tail));
98 #endif /* !LISTMACROS_H */