Mercurial > MadButterfly
annotate src/tools.h @ 149:52f7566777f9
-
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 25 Sep 2008 11:29:42 +0800 |
parents | 6a8588df68af |
children | 6749f6639924 |
rev | line source |
---|---|
12 | 1 #ifndef __TOOLS_H_ |
2 #define __TOOLS_H_ | |
3 | |
4 typedef struct _elmpool elmpool_t; | |
5 | |
6 extern elmpool_t *elmpool_new(int elm_sz, int inc_num); | |
7 extern void *elmpool_elm_alloc(elmpool_t *pool); | |
8 extern void elmpool_elm_free(elmpool_t *pool, void *elm); | |
9 extern void elmpool_free(elmpool_t *pool); | |
10 | |
11 | |
12 #define STAILQ(type) \ | |
13 struct { \ | |
14 type *head; \ | |
15 type *tail; \ | |
16 } | |
17 #define STAILQ_INIT(q) \ | |
18 do { \ | |
19 (q).head = (q).tail = NULL; \ | |
20 } while(0) | |
13 | 21 #define STAILQ_CLEAN(q) STAILQ_INIT(q) |
12 | 22 #define STAILQ_HEAD(q) ((q).head) |
23 #define STAILQ_TAIL(q) ((q).tail) | |
24 #define STAILQ_NEXT(type, field, elm) ((elm)->field) | |
25 #define STAILQ_INS(q, type, field, elm) \ | |
26 do { \ | |
27 (elm)->field = (q).head; \ | |
28 (q).head = elm; \ | |
29 if((q).tail == NULL) \ | |
30 (q).tail = elm; \ | |
31 } while(0) | |
32 #define STAILQ_INS_TAIL(q, type, field, elm) \ | |
33 do { \ | |
34 (elm)->field = NULL; \ | |
35 if((q).tail != NULL) \ | |
36 (q).tail->field = elm; \ | |
37 (q).tail = elm; \ | |
38 if((q).head == NULL) \ | |
39 (q).head = elm; \ | |
40 } while(0) | |
39 | 41 #define STAILQ_INS_AFTER(type, field, follow, elm) \ |
42 do { \ | |
43 (follow)->field = (elm)->field; \ | |
44 (elm)->field = follow; \ | |
45 } while(0) | |
12 | 46 #define STAILQ_REMOVE(q, type, field, elm) \ |
96 | 47 do { \ |
12 | 48 if((elm) == (q).head) { \ |
49 (q).head = (elm)->field; \ | |
50 if((q).head == NULL) \ | |
51 (q).tail = NULL; \ | |
52 } else { \ | |
53 type *_stailq_cur = (q).head; \ | |
54 while(_stailq_cur != NULL && \ | |
55 _stailq_cur->field != (elm)) \ | |
56 _stailq_cur = _stailq_cur->field; \ | |
57 if(_stailq_cur != NULL) { \ | |
58 _stailq_cur->field = elm; \ | |
59 if((q).tail == (elm)) \ | |
60 (q).tail = _stailq_cur; \ | |
61 } \ | |
62 } \ | |
63 } while(0) | |
64 | |
55 | 65 |
131
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
66 #include <stdlib.h> |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
67 |
55 | 68 #define O_ALLOC(type) ((type *)malloc(sizeof(type))) |
69 | |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
55
diff
changeset
|
70 #define OFFSET(type, mem) (((void *)&((type *)NULL)->mem) - NULL) |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
55
diff
changeset
|
71 #define MEM2OBJ(var, type, mem) ((type *)((void *)var - OFFSET(type, mem))) |
93 | 72 #define OFF2TYPE(obj, off, type) (*(type *)((void *)(obj) + (off))) |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
55
diff
changeset
|
73 |
12 | 74 #endif /* __TOOLS_H_ */ |