obj.h

Mon, 20 Apr 2020 10:14:32 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 20 Apr 2020 10:14:32 -0500
changeset 119
87e3bb5086e8
parent 78
9a1ce6020530
permissions
-rw-r--r--

Convert README to markdown

60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
1 /*
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
2 * libtu/obj.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_OBJ_H
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
11 #define LIBTU_OBJ_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
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
15 #define CLASSDESCR(TYPE) TYPE##_classdescr
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
16
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
17 #define OBJ_IS(OBJ, TYPE) obj_is((Obj*)OBJ, &CLASSDESCR(TYPE))
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
18 #define OBJ_CAST(OBJ, TYPE) (TYPE*)obj_cast((Obj*)OBJ, &CLASSDESCR(TYPE))
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
19
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
20 #define INTRSTRUCT(STRU) \
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
21 struct STRU##_struct; typedef struct STRU##_struct STRU
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
22 #define DECLSTRUCT(STRU) \
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
23 struct STRU##_struct
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
24
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
25 #define INTRCLASS(OBJ) INTRSTRUCT(OBJ); extern ClassDescr CLASSDESCR(OBJ)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
26 #define DECLCLASS(OBJ) DECLSTRUCT(OBJ)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
27
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
28 INTRSTRUCT(ClassDescr);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
29 INTRCLASS(Obj);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
30 INTRSTRUCT(Watch);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
31
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
32 extern bool obj_is(const Obj *obj, const ClassDescr *descr);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
33 extern bool obj_is_str(const Obj *obj, const char *str);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
34 extern const void *obj_cast(const Obj *obj, const ClassDescr *descr);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
35
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
36 extern void destroy_obj(Obj *obj);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
37
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
38 DECLCLASS(Obj){
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
39 ClassDescr *obj_type;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
40 Watch *obj_watches;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
41 int flags;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
42 };
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
43
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
44 #define OBJ_DEST 0x0001
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
45 #define OBJ_EXTL_CACHED 0x0002
77
bcd82ab9ecdc trunk: changeset 1634
tuomov
parents: 62
diff changeset
46 #define OBJ_EXTL_OWNED 0x0004
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
47
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
48 #define OBJ_IS_BEING_DESTROYED(OBJ) (((Obj*)(OBJ))->flags&OBJ_DEST)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
49
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
50 #define DYNFUN
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
51
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
52 typedef void WatchHandler(Watch *watch, Obj *obj);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
53
78
9a1ce6020530 trunk: changeset 1635
tuomov
parents: 77
diff changeset
54 #define WATCH_INIT {NULL, NULL, NULL, NULL}
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
55
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
56 DECLSTRUCT(Watch){
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
57 Obj *obj;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
58 Watch *next, *prev;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
59 WatchHandler *handler;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
60 };
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
61
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
62 extern bool watch_setup(Watch *watch, Obj *obj,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
63 WatchHandler *handler);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
64 extern void watch_reset(Watch *watch);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
65 extern bool watch_ok(Watch *watch);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
66 extern void watch_init(Watch *watch);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
67 extern void watch_call(Obj *obj);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
68
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
69 #endif /* LIBTU_OBJ_H */

mercurial