Mon, 16 Feb 2004 18:04:44 +0100
trunk: changeset 1313
Moved Ion object system and other generic code from Ion to libtu.
60 | 1 | /* |
2 | * libtu/obj.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_OBJ_H | |
11 | #define LIBTU_OBJ_H | |
12 | ||
13 | #include "types.h" | |
14 | ||
15 | #define CLASSDESCR(TYPE) TYPE##_classdescr | |
16 | ||
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)) | |
19 | ||
20 | #define INTRSTRUCT(STRU) \ | |
21 | struct STRU##_struct; typedef struct STRU##_struct STRU | |
22 | #define DECLSTRUCT(STRU) \ | |
23 | struct STRU##_struct | |
24 | ||
25 | #define INTRCLASS(OBJ) INTRSTRUCT(OBJ); extern ClassDescr CLASSDESCR(OBJ) | |
26 | #define DECLCLASS(OBJ) DECLSTRUCT(OBJ) | |
27 | ||
28 | INTRSTRUCT(ClassDescr); | |
29 | INTRCLASS(Obj); | |
30 | INTRSTRUCT(Watch); | |
31 | ||
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); | |
35 | ||
36 | extern void destroy_obj(Obj *obj); | |
37 | ||
38 | DECLCLASS(Obj){ | |
39 | ClassDescr *obj_type; | |
40 | Watch *obj_watches; | |
41 | int flags; | |
42 | }; | |
43 | ||
44 | #define OBJ_DEST 0x0001 | |
45 | #define OBJ_EXTL_CACHED 0x0002 | |
46 | ||
47 | #define OBJ_IS_BEING_DESTROYED(OBJ) (((Obj*)(OBJ))->flags&OBJ_DEST) | |
48 | ||
49 | #define DYNFUN | |
50 | ||
51 | typedef void WatchHandler(Watch *watch, Obj *obj); | |
52 | ||
53 | #define WWATCH_INIT {NULL, NULL, NULL, NULL} | |
54 | ||
55 | DECLSTRUCT(Watch){ | |
56 | Obj *obj; | |
57 | Watch *next, *prev; | |
58 | WatchHandler *handler; | |
59 | }; | |
60 | ||
61 | extern bool watch_setup(Watch *watch, Obj *obj, | |
62 | WatchHandler *handler); | |
63 | extern void watch_reset(Watch *watch); | |
64 | extern bool watch_ok(Watch *watch); | |
65 | extern void watch_init(Watch *watch); | |
66 | extern void watch_call(Obj *obj); | |
67 | ||
68 | #endif /* LIBTU_OBJ_H */ |