Mon, 20 Apr 2020 10:14:32 -0500
Convert README to markdown
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) \ | |
62 | 21 | struct STRU##_struct; typedef struct STRU##_struct STRU |
60 | 22 | #define DECLSTRUCT(STRU) \ |
62 | 23 | struct STRU##_struct |
60 | 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){ | |
62 | 39 | ClassDescr *obj_type; |
40 | Watch *obj_watches; | |
41 | int flags; | |
60 | 42 | }; |
43 | ||
44 | #define OBJ_DEST 0x0001 | |
45 | #define OBJ_EXTL_CACHED 0x0002 | |
77 | 46 | #define OBJ_EXTL_OWNED 0x0004 |
60 | 47 | |
48 | #define OBJ_IS_BEING_DESTROYED(OBJ) (((Obj*)(OBJ))->flags&OBJ_DEST) | |
49 | ||
50 | #define DYNFUN | |
51 | ||
52 | typedef void WatchHandler(Watch *watch, Obj *obj); | |
53 | ||
78 | 54 | #define WATCH_INIT {NULL, NULL, NULL, NULL} |
60 | 55 | |
56 | DECLSTRUCT(Watch){ | |
62 | 57 | Obj *obj; |
58 | Watch *next, *prev; | |
59 | WatchHandler *handler; | |
60 | 60 | }; |
61 | ||
62 | extern bool watch_setup(Watch *watch, Obj *obj, | |
62 | 63 | WatchHandler *handler); |
60 | 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); | |
68 | ||
69 | #endif /* LIBTU_OBJ_H */ |