objp.h

Sun, 27 Feb 2005 00:09:12 +0100

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 27 Feb 2005 00:09:12 +0100
changeset 94
f48ffd2f2224
parent 83
2cdbf1464796
permissions
-rw-r--r--

Added routinesn for generic iterables.

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

mercurial