Renamed package to ion1, and made it conflict with package 'ion'.
[ion1.git] / src / objp.h
blob9d3d674cff8382d25660b9dd08dcc03323ff84a1
1 /*
2 * ion/objp.h
4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
6 */
8 #ifndef INCLUDED_WOBJP_H
9 #define INCLUDED_WOBJP_H
11 #include "obj.h"
13 DECLSTRUCT(WObjDescr){
14 const char *name;
15 WObjDescr *ancestor;
16 void *funtab;
19 #define IMPLOBJ(OBJ, ANCESTOR, FUNTAB) \
20 WObjDescr OBJDESCR(OBJ)={#OBJ, &OBJDESCR(ANCESTOR), (void*)FUNTAB};
22 #define WOBJ_INIT(O, TYPE) ((WObj*)(O))->obj_type=&OBJDESCR(TYPE)
24 #define CREATESTRUCT_IMPL_(OBJ, LOWOBJ, INIT, ARGS) \
25 OBJ *p; p=ALLOC(OBJ); if(p==NULL){ warn_err(); return NULL; } \
26 INIT; \
27 if(!init_##LOWOBJ ARGS){ free((void*)p); return NULL; } return p
29 #define CREATESTRUCT_IMPL(OBJ, LOWOBJ, ARGS) \
30 CREATESTRUCT_IMPL_(OBJ, LOWOBJ, /* */, ARGS)
32 #define SIMPLECREATESTRUCT_IMPL(OBJ, LOWOBJ, ARGS) \
33 CREATESTRUCT_IMPL_(OBJ, LOWOBJ, /* */, (p))
35 #define CREATEOBJ_IMPL(OBJ, LOWOBJ, ARGS) \
36 CREATESTRUCT_IMPL_(OBJ, LOWOBJ, WOBJ_INIT(p, OBJ), ARGS)
38 #define SIMPLECREATEOBJ_IMPL(OBJ, LOWOBJ, ARGS) \
39 CREATESTRUCT_IMPL_(OBJ, LOWOBJ, WOBJ_INIT(p, OBJ), (p))
41 #define FUNTAB(OBJ, TYPE) ((TYPE*)(((WObj*)OBJ)->obj_type->funtab))
42 #define CALL_FUNTAB(OBJ, TYPE, FN) if(FUNTAB(OBJ, TYPE)->FN!=NULL) FUNTAB(OBJ, TYPE)->FN
44 #endif /* INCLUDED_WOBJP_H */