Add the instanceOf() macro and supporting function, and try to fix

gcc 2.95 support again.
This commit is contained in:
Brian Koropoff 2003-11-29 23:09:50 +00:00
parent dfe1dbe4bf
commit a0b8566337
2 changed files with 18 additions and 6 deletions

View file

@ -39,11 +39,11 @@
#include "QF/qtypes.h"
#ifdef __GNUC__
#define superInit(cl, obj, args...) (cl##_class->parent->init ((obj), ##args))
#define new(cl, args...) ((void *) (cl##_class->abstract ? NULL : retain(cl##_class->init (Object_Create(cl##_class), ##args))))
#define newFloat(cl, args...) ((void *) (cl##_class->abstract ? NULL : cl##_class->init (Object_Create(cl##_class), ##args)))
#define methodCall(obj, m, args...) ((obj)->m(obj, ##args))
#define methodDecl(type, name, args...) (* name) (struct type##_s *self, ##args)
#define superInit(cl, obj, args...) (cl##_class->parent->init ((obj) , ## args))
#define new(cl, args...) ((void *) (cl##_class->abstract ? NULL : retain(cl##_class->init (Object_Create(cl##_class) , ## args))))
#define newFloat(cl, args...) ((void *) (cl##_class->abstract ? NULL : cl##_class->init (Object_Create(cl##_class) , ## args)))
#define methodCall(obj, m, args...) ((obj)->m(obj , ## args))
#define methodDecl(type, name, args...) (* name) (struct type##_s *self , ## args)
#else
#define superInit(cl, obj, ...) (cl##_class->parent->init ((obj), ##__VA_ARGS__))
#define new(cl, ...) ((void *) (cl##_class->abstract ? NULL : retain(cl##_class->init (Object_Create(cl##_class), ##__VA_ARGS__))))
@ -56,6 +56,8 @@
#define retain(obj) (Object_Retain((Object *)obj))
#define release(obj) (Object_Release((Object *)obj))
#define instanceOf(obj, cl) (Object_InstaceOf((Object *)obj, cl##_class))
typedef struct Object_s {
struct Class_s *cl;
int refs;
@ -109,7 +111,7 @@ Object *Object_Create (Class *cl);
void Object_Delete (Object *obj);
Object *Object_Retain (Object *obj);
Object *Object_Release (Object *obj);
qboolean Object_InstanceOf (Object *obj, Class *cl);
void Object_Init (void);
#endif

View file

@ -158,6 +158,16 @@ Object_Release (Object *obj)
return obj;
}
qboolean
Object_InstanceOf (Object *obj, Class *cl)
{
Class *c;
for (c = obj->cl; c; c = c->parent)
if (c == cl)
return true;
return false;
}
static String *
List_ToString_f (Object *self)
{