Browse Source

modify static instance generation so that static instances of a class can now be created anywhere. But the class needs to be prepared for this after its definition (TR_INSTANCE_INIT).

1.0.2
Georg Hopp 12 years ago
parent
commit
c5c48bb320
  1. 17
      include/tr/class.h
  2. 4
      include/tr/logger.h

17
include/tr/class.h

@ -61,11 +61,18 @@
* that are needed to create a new class.
*/
#define TR_CLASS(name) \
struct TR_class c_##name; \
struct c_##name; \
typedef struct c_##name * name; \
extern struct TR_class * const _##name; \
struct c_##name
#define TR_INSTANCE_INIT(name) \
struct c_##name##_object { \
void * TR_class; \
struct c_##name data; \
}
/**
* Make the new class a child of an existing class.
* This is used within the class declaration and can
@ -97,25 +104,19 @@
* created.
*/
#define TR_CREATE_CLASS(name,_parent,...) \
static struct TR_class c_##name; \
static TR_class_ptr _classInit##name##_(void) { \
c_##name.parent = _##_parent; \
c_##name.init = NULL; \
return &c_##name; \
}; \
static struct TR_class 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; \
struct c_##name##_object { \
void * TR_class; \
struct c_##name data; \
}
struct TR_class * const _##name = &c_##name
/**
* Create a static instance of a class.

4
include/tr/logger.h

@ -54,6 +54,10 @@ TR_CLASS(TR_LoggerSyslog) {
TR_EXTENDS(TR_Logger);
};
TR_INSTANCE_INIT(TR_Logger);
TR_INSTANCE_INIT(TR_LoggerStderr);
TR_INSTANCE_INIT(TR_LoggerSyslog);
extern TR_Logger TR_logger;
#endif // __TR_LOGGER_H__

Loading…
Cancel
Save