Tue, 16 Mar 2004 21:38:58 +0100
trunk: changeset 1411
Removed superfluous include flag.
60 | 1 | /* |
2 | * libtu/objp.h | |
3 | * | |
4 | * Copyright (c) Tuomo Valkonen 1999-2004. | |
5 | * | |
6 | * You may distribute and modify this library under the terms of either | |
7 | * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. | |
8 | */ | |
9 | ||
10 | #ifndef LIBTU_OBJP_H | |
11 | #define LIBTU_OBJP_H | |
12 | ||
13 | #include "types.h" | |
14 | #include "obj.h" | |
15 | ||
16 | typedef void DynFun(); | |
17 | ||
18 | INTRSTRUCT(DynFunTab); | |
19 | ||
20 | DECLSTRUCT(DynFunTab){ | |
62 | 21 | DynFun *func, *handler; |
60 | 22 | }; |
23 | ||
24 | DECLSTRUCT(ClassDescr){ | |
62 | 25 | const char *name; |
26 | ClassDescr *ancestor; | |
27 | int funtab_n; | |
28 | DynFunTab *funtab; | |
29 | void (*destroy_fn)(); | |
60 | 30 | }; |
31 | ||
32 | #define OBJ_TYPESTR(OBJ) (((Obj*)OBJ)->obj_type->name) | |
33 | ||
34 | #define IMPLCLASS(CLS, ANCESTOR, DFN, DYN) \ | |
62 | 35 | ClassDescr CLASSDESCR(CLS)={ \ |
36 | #CLS, &CLASSDESCR(ANCESTOR), -1, DYN, (void (*)())DFN} | |
60 | 37 | |
38 | #define OBJ_INIT(O, TYPE) {((Obj*)(O))->obj_type=&CLASSDESCR(TYPE); \ | |
62 | 39 | ((Obj*)(O))->obj_watches=NULL; ((Obj*)(O))->flags=0;} |
60 | 40 | |
41 | #define CREATEOBJ_IMPL(OBJ, LOWOBJ, INIT_ARGS) \ | |
62 | 42 | OBJ *p; p=ALLOC(OBJ); if(p==NULL){ warn_err(); return NULL; } \ |
43 | OBJ_INIT(p, OBJ); \ | |
44 | if(!LOWOBJ ## _init INIT_ARGS) { free((void*)p); return NULL; } return p | |
60 | 45 | |
46 | #define SIMPLECREATEOBJ_IMPL(OBJ, LOWOBJ) \ | |
62 | 47 | OBJ *p; p=ALLOC(OBJ); if(p==NULL){ warn_err(); return NULL; } \ |
48 | OBJ_INIT(p, OBJ); \ | |
49 | return p; | |
60 | 50 | |
51 | #define END_DYNFUNTAB {NULL, NULL} | |
52 | ||
53 | extern DynFun *lookup_dynfun(const Obj *obj, DynFun *func, | |
62 | 54 | bool *funnotfound); |
60 | 55 | extern bool has_dynfun(const Obj *obj, DynFun *func); |
56 | ||
57 | #define CALL_DYN(FUNC, OBJ, ARGS) \ | |
62 | 58 | bool funnotfound; \ |
59 | lookup_dynfun((Obj*)OBJ, (DynFun*)FUNC, &funnotfound) ARGS; | |
60 | 60 | |
61 | #define CALL_DYN_RET(RETV, RET, FUNC, OBJ, ARGS) \ | |
62 | 62 | typedef RET ThisDynFun(); \ |
63 | bool funnotfound; \ | |
64 | ThisDynFun *funtmp; \ | |
65 | funtmp=(ThisDynFun*)lookup_dynfun((Obj*)OBJ, (DynFun*)FUNC, \ | |
66 | &funnotfound); \ | |
67 | if(!funnotfound) \ | |
68 | RETV=funtmp ARGS; | |
60 | 69 | |
70 | #define HAS_DYN(OBJ, FUNC) has_dynfun((Obj*)OBJ, (DynFun*)FUNC) | |
71 | ||
72 | #endif /* LIBTU_OBJP_H */ |