Releasing version 3-2014010505
[notion/jeffpc.git] / libtu / obj.h
blob68ee3dff3dafa9be58d3572ecefbe319946d2858
1 /*
2 * libtu/obj.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_OBJ_H
11 #define LIBTU_OBJ_H
13 #include "types.h"
15 #define CLASSDESCR(TYPE) TYPE##_classdescr
17 #define OBJ_IS(OBJ, TYPE) obj_is((Obj*)OBJ, &CLASSDESCR(TYPE))
18 #define OBJ_CAST(OBJ, TYPE) (TYPE*)obj_cast((Obj*)OBJ, &CLASSDESCR(TYPE))
20 #define INTRSTRUCT(STRU) \
21 struct STRU##_struct; typedef struct STRU##_struct STRU
22 #define DECLSTRUCT(STRU) \
23 struct STRU##_struct
25 #define INTRCLASS(OBJ) INTRSTRUCT(OBJ); extern ClassDescr CLASSDESCR(OBJ)
26 #define DECLCLASS(OBJ) DECLSTRUCT(OBJ)
28 INTRSTRUCT(ClassDescr);
29 INTRCLASS(Obj);
30 INTRSTRUCT(Watch);
32 extern bool obj_is(const Obj *obj, const ClassDescr *descr);
33 extern bool obj_is_str(const Obj *obj, const char *str);
34 extern const void *obj_cast(const Obj *obj, const ClassDescr *descr);
36 extern void destroy_obj(Obj *obj);
38 DECLCLASS(Obj){
39 ClassDescr *obj_type;
40 Watch *obj_watches;
41 int flags;
44 #define OBJ_DEST 0x0001
45 #define OBJ_EXTL_CACHED 0x0002
46 #define OBJ_EXTL_OWNED 0x0004
48 #define OBJ_IS_BEING_DESTROYED(OBJ) (((Obj*)(OBJ))->flags&OBJ_DEST)
50 #define DYNFUN
52 typedef void WatchHandler(Watch *watch, Obj *obj);
54 #define WATCH_INIT {NULL, NULL, NULL, NULL}
56 DECLSTRUCT(Watch){
57 Obj *obj;
58 Watch *next, *prev;
59 WatchHandler *handler;
62 extern bool watch_setup(Watch *watch, Obj *obj,
63 WatchHandler *handler);
64 extern void watch_reset(Watch *watch);
65 extern bool watch_ok(Watch *watch);
66 extern void watch_init(Watch *watch);
67 extern void watch_call(Obj *obj);
69 #endif /* LIBTU_OBJ_H */