Import libtu instead of using submodules
[notion/jeffpc.git] / libtu / objp.h
blob54a7b19be920a3cfc826efc7214436f088f2fc9c
1 /*
2 * libtu/objp.h
4 * Copyright (c) Tuomo Valkonen 1999-2004.
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 */
10 #ifndef LIBTU_OBJP_H
11 #define LIBTU_OBJP_H
13 #include "types.h"
14 #include "obj.h"
16 typedef void DynFun();
18 INTRSTRUCT(DynFunTab);
20 DECLSTRUCT(DynFunTab){
21 DynFun *func, *handler;
24 DECLSTRUCT(ClassDescr){
25 const char *name;
26 ClassDescr *ancestor;
27 int funtab_n;
28 DynFunTab *funtab;
29 void (*destroy_fn)();
32 #define OBJ_TYPESTR(OBJ) ((OBJ) ? ((Obj*)OBJ)->obj_type->name : NULL)
34 #define IMPLCLASS(CLS, ANCESTOR, DFN, DYN) \
35 ClassDescr CLASSDESCR(CLS)={ \
36 #CLS, &CLASSDESCR(ANCESTOR), -1, DYN, (void (*)())DFN}
38 #define OBJ_INIT(O, TYPE) {((Obj*)(O))->obj_type=&CLASSDESCR(TYPE); \
39 ((Obj*)(O))->obj_watches=NULL; ((Obj*)(O))->flags=0;}
41 #define CREATEOBJ_IMPL(OBJ, LOWOBJ, INIT_ARGS) \
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
46 #define SIMPLECREATEOBJ_IMPL(OBJ, LOWOBJ) \
47 OBJ *p; p=ALLOC(OBJ); if(p==NULL){ warn_err(); return NULL; } \
48 OBJ_INIT(p, OBJ); \
49 return p;
51 #define END_DYNFUNTAB {NULL, NULL}
53 extern DynFun *lookup_dynfun(const Obj *obj, DynFun *func,
54 bool *funnotfound);
55 extern bool has_dynfun(const Obj *obj, DynFun *func);
57 #define CALL_DYN(FUNC, OBJ, ARGS) \
58 bool funnotfound; \
59 lookup_dynfun((Obj*)OBJ, (DynFun*)FUNC, &funnotfound) ARGS;
61 #define CALL_DYN_RET(RETV, RET, FUNC, OBJ, ARGS) \
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;
70 #define HAS_DYN(OBJ, FUNC) has_dynfun((Obj*)OBJ, (DynFun*)FUNC)
72 #endif /* LIBTU_OBJP_H */