|
|
|
@ -20,7 +20,7 @@ |
|
|
|
* \author Georg Hopp |
|
|
|
* |
|
|
|
* \copyright |
|
|
|
* Copyright © 2012-2013 Georg Hopp |
|
|
|
* Copyright © 2014 Georg Hopp |
|
|
|
* |
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
|
|
* it under the terms of the GNU General Public License as published by |
|
|
|
@ -73,6 +73,9 @@ |
|
|
|
struct c_##name data; \ |
|
|
|
} |
|
|
|
|
|
|
|
#define TR_CLASSVARS_DECL(name) struct c_##name##_vars |
|
|
|
#define TR_CLASSVARS(name, class) ((struct c_##name##_vars *)(class)->vars) |
|
|
|
|
|
|
|
/** |
|
|
|
* Make the new class a child of an existing class. |
|
|
|
* This is used within the class declaration and can |
|
|
|
@ -80,8 +83,8 @@ |
|
|
|
* is undefined, but most likely the resulting code won't |
|
|
|
* even compile. |
|
|
|
*/ |
|
|
|
#define TR_EXTENDS(parent) \ |
|
|
|
const char _[sizeof(struct c_##parent)] |
|
|
|
#define TR_EXTENDS(parent) const char _[sizeof(struct c_##parent)] |
|
|
|
#define TR_CV_EXTENDS(parent) const char _[sizeof(struct c_##parent##_vars)] |
|
|
|
|
|
|
|
/** |
|
|
|
* Some macros might translate a give NULL to _NULL, |
|
|
|
@ -103,20 +106,26 @@ |
|
|
|
* for the ctor interface else no instances can be |
|
|
|
* created. |
|
|
|
*/ |
|
|
|
#define TR_CREATE_CLASS(name,_parent,...) \ |
|
|
|
static TR_class_ptr _classInit##name##_(void) { \ |
|
|
|
c_##name.parent = _##_parent; \ |
|
|
|
c_##name.init = NULL; \ |
|
|
|
return &c_##name; \ |
|
|
|
}; \ |
|
|
|
struct TR_class c_##name = { \ |
|
|
|
TR_CLASS_MAGIC, \ |
|
|
|
NULL, \ |
|
|
|
sizeof(struct c_##name), \ |
|
|
|
_classInit##name##_, \ |
|
|
|
TR_INIT_IFACE_IMPL(__VA_ARGS__) \ |
|
|
|
}; \ |
|
|
|
struct TR_class * const _##name = &c_##name |
|
|
|
#define TR_CREATE_CLASS(name,_parent,cvInit,...) \ |
|
|
|
struct c_##name##_vars c_vars; \ |
|
|
|
void (* TR_initClassVars##name)(TR_class_ptr) = cvInit; \ |
|
|
|
static TR_class_ptr _classInit##name##_(void) { \ |
|
|
|
c_##name.parent = _##_parent; \ |
|
|
|
if (TR_initClassVars##name) \ |
|
|
|
TR_initClassVars##name(_##name); \ |
|
|
|
c_##name.init = NULL; \ |
|
|
|
return &c_##name; \ |
|
|
|
}; \ |
|
|
|
struct TR_class c_##name = { \ |
|
|
|
TR_CLASS_MAGIC, \ |
|
|
|
NULL, \ |
|
|
|
sizeof(struct c_##name), \ |
|
|
|
_classInit##name##_, \ |
|
|
|
&c_vars, \ |
|
|
|
TR_INIT_IFACE_IMPL(__VA_ARGS__) \ |
|
|
|
}; \ |
|
|
|
struct TR_class * const _##name = &c_##name; \ |
|
|
|
struct c_##name##_vars c_vars |
|
|
|
|
|
|
|
/** |
|
|
|
* Create a static instance of a class. |
|
|
|
@ -293,11 +302,12 @@ struct TR_class; |
|
|
|
typedef struct TR_class * TR_class_ptr; |
|
|
|
typedef TR_class_ptr (* TR_fptr_classInit)(void); |
|
|
|
struct TR_class { |
|
|
|
const int magic; |
|
|
|
TR_class_ptr parent; |
|
|
|
size_t object_size; |
|
|
|
TR_fptr_classInit init; |
|
|
|
struct TR_iface_impl impl; |
|
|
|
const int magic; |
|
|
|
TR_class_ptr parent; |
|
|
|
size_t object_size; |
|
|
|
TR_fptr_classInit init; |
|
|
|
void * vars; |
|
|
|
struct TR_iface_impl impl; |
|
|
|
}; |
|
|
|
/** \endcond */ |
|
|
|
|
|
|
|
|