squashed commit of private hostlib-resource branch
[tangerine.git] / test / oop2 / support.h
blob9d7b0a0c392434a6d1586ce4e0b3d948127cfa4e
1 #ifndef SUPPORT_H
2 #define SUPPORT_H
4 /*
5 Copyright © 1997-98, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: Demo of new OOP system - support defs.
9 Lang: english
12 #ifndef TYPES_H
13 # include "types.h"
14 #endif
16 #include <assert.h>
19 struct Node
21 struct Node * ln_Succ,
22 * ln_Pred;
23 /* AROS: pointer should be 32bit aligned */
24 char * ln_Name;
25 UBYTE ln_Type;
26 BYTE ln_Pri;
29 struct MinNode
31 struct MinNode * mln_Succ,
32 * mln_Pred;
35 struct List
37 struct Node * lh_Head,
38 * lh_Tail,
39 * lh_TailPred;
40 UBYTE lh_Type;
41 UBYTE l_pad;
44 struct MinList
46 struct MinNode * mlh_Head,
47 * mlh_Tail,
48 * mlh_TailPred;
51 # define NEWLIST(l) (((struct List *)l)->lh_TailPred \
52 = (struct Node *)(l), \
53 ((struct List *)l)->lh_Tail = 0, \
54 ((struct List *)l)->lh_Head \
55 = (struct Node *)\
56 &(((struct List *)l)->lh_Tail))
58 # define ADDHEAD(l,n) ((void)(\
59 ((struct Node *)n)->ln_Succ = ((struct List *)l)->lh_Head, \
60 ((struct Node *)n)->ln_Pred = (struct Node *)&((struct List *)l)->lh_Head, \
61 ((struct List *)l)->lh_Head->ln_Pred = ((struct Node *)n), \
62 ((struct List *)l)->lh_Head = ((struct Node *)n)))
64 # define ADDTAIL(l,n) ((void)(\
65 ((struct Node *)n)->ln_Succ = (struct Node *)&((struct List *)l)->lh_Tail, \
66 ((struct Node *)n)->ln_Pred = ((struct List *)l)->lh_TailPred, \
67 ((struct List *)l)->lh_TailPred->ln_Succ = ((struct Node *)n), \
68 ((struct List *)l)->lh_TailPred = ((struct Node *)n) ))
70 # define REMOVE(n) ((void)(\
71 ((struct Node *)n)->ln_Pred->ln_Succ = ((struct Node *)n)->ln_Succ,\
72 ((struct Node *)n)->ln_Succ->ln_Pred = ((struct Node *)n)->ln_Pred ))
74 # define GetHead(l) (void *)(((struct List *)l)->lh_Head->ln_Succ \
75 ? ((struct List *)l)->lh_Head \
76 : (struct Node *)0)
77 # define GetTail(l) (void *)(((struct List *)l)->lh_TailPred->ln_Pred \
78 ? ((struct List *)l)->lh_TailPred \
79 : (struct Node *)0)
80 # define GetSucc(n) (void *)(((struct Node *)n)->ln_Succ->ln_Succ \
81 ? ((struct Node *)n)->ln_Succ \
82 : (struct Node *)0)
83 # define GetPred(n) (void *)(((struct Node *)n)->ln_Pred->ln_Pred \
84 ? ((struct Node *)n)->ln_Pred \
85 : (struct Node *)0)
86 # define ForeachNode(l,n) \
87 for (n=(void *)(((struct List *)(l))->lh_Head); \
88 ((struct Node *)(n))->ln_Succ; \
89 n=(void *)(((struct Node *)(n))->ln_Succ))
91 # define ForeachNodeSafe(l,n,n2) \
92 for (n=(void *)(((struct List *)(l))->lh_Head); \
93 (n2=(void *)((struct Node *)(n))->ln_Succ); \
94 n=(void *)n2)
96 # define SetNodeName(node,name) \
97 (((struct Node *)(node))->ln_Name = (char *)(name))
98 # define GetNodeName(node) \
99 (((struct Node *)(node))->ln_Name
101 # define ListLength(list,count) \
102 do { \
103 struct Node * n; \
104 count = 0; \
105 ForeachNode (list,n) count ++; \
106 } while (0)
108 #define IsListEmpty(l) \
109 ( (((struct List *)l)->lh_TailPred) == (struct Node *)(l) )
112 /* Prototypes */
113 VOID AddTail(struct List *, struct Node *);
114 struct Node *FindName(struct List *, STRPTR);
115 VOID Remove(struct Node *node);
116 #endif /* SUPPORT_H */