obj.h

Sun, 20 Jun 2004 13:46:00 +0200

author
tuomov
date
Sun, 20 Jun 2004 13:46:00 +0200
changeset 76
58280b944cda
parent 62
aae5facf9fc5
child 77
bcd82ab9ecdc
permissions
-rw-r--r--

trunk: changeset 1585
Oops.

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
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
46
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
47 #define OBJ_IS_BEING_DESTROYED(OBJ) (((Obj*)(OBJ))->flags&OBJ_DEST)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
48
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
49 #define DYNFUN
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
50
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
51 typedef void WatchHandler(Watch *watch, Obj *obj);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
52
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
53 #define WWATCH_INIT {NULL, NULL, NULL, NULL}
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
54
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
55 DECLSTRUCT(Watch){
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
56 Obj *obj;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
57 Watch *next, *prev;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
58 WatchHandler *handler;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
59 };
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
61 extern bool watch_setup(Watch *watch, Obj *obj,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
62 WatchHandler *handler);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
63 extern void watch_reset(Watch *watch);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
64 extern bool watch_ok(Watch *watch);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
65 extern void watch_init(Watch *watch);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
66 extern void watch_call(Obj *obj);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
67
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
68 #endif /* LIBTU_OBJ_H */

mercurial