Browse Source

some minor fixes for the classvars stuff

1.0.2
Georg Hopp 12 years ago
parent
commit
8c0277e8d8
  1. 15
      include/tr/class.h

15
include/tr/class.h

@ -84,7 +84,7 @@
* even compile. * 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)]
#define TR_CV_EXTENDS(parent) struct c_##parent##_vars _
/** /**
* Some macros might translate a give NULL to _NULL, * Some macros might translate a give NULL to _NULL,
@ -107,13 +107,13 @@
* created. * created.
*/ */
#define TR_CREATE_CLASS(name,_parent,cvInit,...) \ #define TR_CREATE_CLASS(name,_parent,cvInit,...) \
struct c_##name##_vars c_vars; \
struct c_##name##_vars _##name##_vars; \
void (* TR_initClassVars##name)(TR_class_ptr) = cvInit; \ void (* TR_initClassVars##name)(TR_class_ptr) = cvInit; \
static TR_class_ptr _classInit##name##_(void) { \ static TR_class_ptr _classInit##name##_(void) { \
c_##name.init = NULL; \
c_##name.parent = _##_parent; \ c_##name.parent = _##_parent; \
if (TR_initClassVars##name) \ if (TR_initClassVars##name) \
TR_initClassVars##name(_##name); \ TR_initClassVars##name(_##name); \
c_##name.init = NULL; \
return &c_##name; \ return &c_##name; \
}; \ }; \
struct TR_class c_##name = { \ struct TR_class c_##name = { \
@ -121,11 +121,11 @@
NULL, \ NULL, \
sizeof(struct c_##name), \ sizeof(struct c_##name), \
_classInit##name##_, \ _classInit##name##_, \
&c_vars, \
&_##name##_vars, \
TR_INIT_IFACE_IMPL(__VA_ARGS__) \ TR_INIT_IFACE_IMPL(__VA_ARGS__) \
}; \ }; \
struct TR_class * const _##name = &c_##name; \ struct TR_class * const _##name = &c_##name; \
struct c_##name##_vars c_vars
struct c_##name##_vars _##name##_vars
/** /**
* Create a static instance of a class. * Create a static instance of a class.
@ -176,7 +176,10 @@
* \see TR_CREATE_CLASS * \see TR_CREATE_CLASS
*/ */
#define TR_GET_CLASS(object) \ #define TR_GET_CLASS(object) \
(TR_INIT_CLASS(*(TR_class_ptr *)((void*)(object) - sizeof(void*))))
(TR_INIT_CLASS(*(TR_class_ptr *)((void*)(object) - sizeof(void*))))
#define TR_CLASS_BY_NAME(class_name) (TR_INIT_CLASS(& c_##class_name))
#define TR_CLASS_BY_NAME_STATIC(class_name) (& c_##class_name)
/** /**
* Returns this class's implementations of the interface * Returns this class's implementations of the interface

Loading…
Cancel
Save