|
|
|
@ -33,41 +33,48 @@ |
|
|
|
#define ENDC(_class) } * _class; \ |
|
|
|
extern const _CCLASS const __##_class; |
|
|
|
|
|
|
|
#define INIT_CCLASS(class, jsonConst, toJson) \ |
|
|
|
static const struct CCLASS _class = { \ |
|
|
|
CCLASS_MAGIC, \ |
|
|
|
sizeof(struct _##class), \ |
|
|
|
(ctor)__construct, \ |
|
|
|
(jCtor)jsonConst, \ |
|
|
|
(dtor)__destruct, \ |
|
|
|
(jTo)toJson \ |
|
|
|
}; const _CCLASS const __##class = (const _CCLASS const)&_class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (* ctor)(void *, va_list *); |
|
|
|
typedef void (* dtor)(void *); |
|
|
|
typedef void (* jCtor)(void *, struct json_object *); |
|
|
|
typedef struct json_object * (* jTo)(void *); |
|
|
|
typedef void (* jTo)(void *, struct json_object **); |
|
|
|
|
|
|
|
|
|
|
|
typedef struct CCLASS { |
|
|
|
const int magic; |
|
|
|
size_t size; |
|
|
|
void (* __construct)(void * _this, va_list * params); |
|
|
|
void (* __jsonConst)(void * _this, struct json_object * json); |
|
|
|
void (* __destruct)(void * _this); |
|
|
|
struct json_object * (* __toJson)(void * _this); |
|
|
|
void (* __jsonConst)(void * _this, struct json_object * json); |
|
|
|
void (* __toJson)(void * _this, struct json_object ** json); |
|
|
|
} * _CCLASS; |
|
|
|
#define CCLASS_PTR_SIZE sizeof(struct CCLASS *) |
|
|
|
#define CCLASS_SIZE sizeof(struct CCLASS) |
|
|
|
|
|
|
|
void * _new(const _CCLASS _class, ...); |
|
|
|
void * _newFromJson(const _CCLASS _class, struct json_object * json); |
|
|
|
void delete(void * _object); |
|
|
|
struct json_object * toJson(void * _object); |
|
|
|
int isObject(void * _object); |
|
|
|
int _instanceOf(const _CCLASS _class, void * _object); |
|
|
|
#define __construct(class) static void __construct(class _this, va_list * params) |
|
|
|
#define __destruct(class) static void __destruct(class _this) |
|
|
|
#define __jsonConst(class) static void __jsonConst(class _this, struct json_object * json) |
|
|
|
#define __toJson(class) static void __toJson(class _this, struct json_object ** json) |
|
|
|
|
|
|
|
#define INIT_CCLASS(class) \ |
|
|
|
__construct(class); \ |
|
|
|
__destruct(class); \ |
|
|
|
__jsonConst(class); \ |
|
|
|
__toJson(class); \ |
|
|
|
static const struct CCLASS _class = { \ |
|
|
|
CCLASS_MAGIC, \ |
|
|
|
sizeof(struct _##class), \ |
|
|
|
(ctor)__construct, \ |
|
|
|
(dtor)__destruct, \ |
|
|
|
(jCtor)__jsonConst, \ |
|
|
|
(jTo)__toJson \ |
|
|
|
}; const _CCLASS __##class = (const _CCLASS)&_class |
|
|
|
|
|
|
|
void * _new(const _CCLASS _class, ...); |
|
|
|
void * _newFromJson(const _CCLASS _class, struct json_object * json); |
|
|
|
void delete(void * _object); |
|
|
|
void toJson(void * _object, struct json_object ** json); |
|
|
|
int isObject(void * _object); |
|
|
|
int _instanceOf(const _CCLASS _class, void * _object); |
|
|
|
|
|
|
|
#define new(class, ...) _new((__##class), __VA_ARGS__) |
|
|
|
#define newFromJson(class, json) _newFromJson((__##class), (json)) |
|
|
|
|