mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
Add the instanceOf() macro and supporting function, and try to fix
gcc 2.95 support again.
This commit is contained in:
parent
dfe1dbe4bf
commit
a0b8566337
2 changed files with 18 additions and 6 deletions
|
@ -39,11 +39,11 @@
|
||||||
#include "QF/qtypes.h"
|
#include "QF/qtypes.h"
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define superInit(cl, obj, args...) (cl##_class->parent->init ((obj), ##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 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 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 methodCall(obj, m, args...) ((obj)->m(obj , ## args))
|
||||||
#define methodDecl(type, name, args...) (* name) (struct type##_s *self, ##args)
|
#define methodDecl(type, name, args...) (* name) (struct type##_s *self , ## args)
|
||||||
#else
|
#else
|
||||||
#define superInit(cl, obj, ...) (cl##_class->parent->init ((obj), ##__VA_ARGS__))
|
#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__))))
|
#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 retain(obj) (Object_Retain((Object *)obj))
|
||||||
#define release(obj) (Object_Release((Object *)obj))
|
#define release(obj) (Object_Release((Object *)obj))
|
||||||
|
|
||||||
|
#define instanceOf(obj, cl) (Object_InstaceOf((Object *)obj, cl##_class))
|
||||||
|
|
||||||
typedef struct Object_s {
|
typedef struct Object_s {
|
||||||
struct Class_s *cl;
|
struct Class_s *cl;
|
||||||
int refs;
|
int refs;
|
||||||
|
@ -109,7 +111,7 @@ Object *Object_Create (Class *cl);
|
||||||
void Object_Delete (Object *obj);
|
void Object_Delete (Object *obj);
|
||||||
Object *Object_Retain (Object *obj);
|
Object *Object_Retain (Object *obj);
|
||||||
Object *Object_Release (Object *obj);
|
Object *Object_Release (Object *obj);
|
||||||
|
qboolean Object_InstanceOf (Object *obj, Class *cl);
|
||||||
void Object_Init (void);
|
void Object_Init (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -158,6 +158,16 @@ Object_Release (Object *obj)
|
||||||
return 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 *
|
static String *
|
||||||
List_ToString_f (Object *self)
|
List_ToString_f (Object *self)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue