1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
/*
* libtu/obj.h
*
* Copyright (c) Tuomo Valkonen 1999-2004.
*
* You may distribute and modify this library under the terms of either
* the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
*/
#ifndef LIBTU_OBJ_H
#define LIBTU_OBJ_H
#include "types.h"
#define CLASSDESCR(TYPE) TYPE##_classdescr
#define OBJ_IS(OBJ, TYPE) obj_is((Obj*)OBJ, &CLASSDESCR(TYPE))
#define OBJ_CAST(OBJ, TYPE) (TYPE*)obj_cast((Obj*)OBJ, &CLASSDESCR(TYPE))
#define INTRSTRUCT(STRU) \
struct STRU##_struct; typedef struct STRU##_struct STRU
#define DECLSTRUCT(STRU) \
struct STRU##_struct
#define INTRCLASS(OBJ) INTRSTRUCT(OBJ); extern ClassDescr CLASSDESCR(OBJ)
#define DECLCLASS(OBJ) DECLSTRUCT(OBJ)
INTRSTRUCT(ClassDescr);
INTRCLASS(Obj);
INTRSTRUCT(Watch);
extern bool obj_is(const Obj *obj, const ClassDescr *descr);
extern bool obj_is_str(const Obj *obj, const char *str);
extern const void *obj_cast(const Obj *obj, const ClassDescr *descr);
extern void destroy_obj(Obj *obj);
DECLCLASS(Obj){
ClassDescr *obj_type;
Watch *obj_watches;
int flags;
};
#define OBJ_DEST 0x0001
#define OBJ_EXTL_CACHED 0x0002
#define OBJ_EXTL_OWNED 0x0004
#define OBJ_IS_BEING_DESTROYED(OBJ) (((Obj*)(OBJ))->flags&OBJ_DEST)
#define DYNFUN
typedef void WatchHandler(Watch *watch, Obj *obj);
#define WATCH_INIT {NULL, NULL, NULL, NULL}
DECLSTRUCT(Watch){
Obj *obj;
Watch *next, *prev;
WatchHandler *handler;
};
extern bool watch_setup(Watch *watch, Obj *obj,
WatchHandler *handler);
extern void watch_reset(Watch *watch);
extern bool watch_ok(Watch *watch);
extern void watch_init(Watch *watch);
extern void watch_call(Obj *obj);
#endif /* LIBTU_OBJ_H */
|