Commit c5c48bb32051fa8e3fc6755475fb72276cd43482
1 parent
bbf4463f
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).
Showing
2 changed files
with
13 additions
and
8 deletions
... | ... | @@ -61,11 +61,18 @@ |
61 | 61 | * that are needed to create a new class. |
62 | 62 | */ |
63 | 63 | #define TR_CLASS(name) \ |
64 | + struct TR_class c_##name; \ | |
64 | 65 | struct c_##name; \ |
65 | 66 | typedef struct c_##name * name; \ |
66 | 67 | extern struct TR_class * const _##name; \ |
67 | 68 | struct c_##name |
68 | 69 | |
70 | +#define TR_INSTANCE_INIT(name) \ | |
71 | + struct c_##name##_object { \ | |
72 | + void * TR_class; \ | |
73 | + struct c_##name data; \ | |
74 | + } | |
75 | + | |
69 | 76 | /** |
70 | 77 | * Make the new class a child of an existing class. |
71 | 78 | * This is used within the class declaration and can |
... | ... | @@ -97,25 +104,19 @@ |
97 | 104 | * created. |
98 | 105 | */ |
99 | 106 | #define TR_CREATE_CLASS(name,_parent,...) \ |
100 | - static struct TR_class c_##name; \ | |
101 | 107 | static TR_class_ptr _classInit##name##_(void) { \ |
102 | 108 | c_##name.parent = _##_parent; \ |
103 | 109 | c_##name.init = NULL; \ |
104 | 110 | return &c_##name; \ |
105 | 111 | }; \ |
106 | - static struct TR_class c_##name = { \ | |
112 | + struct TR_class c_##name = { \ | |
107 | 113 | TR_CLASS_MAGIC, \ |
108 | 114 | NULL, \ |
109 | 115 | sizeof(struct c_##name), \ |
110 | 116 | _classInit##name##_, \ |
111 | 117 | TR_INIT_IFACE_IMPL(__VA_ARGS__) \ |
112 | 118 | }; \ |
113 | - struct TR_class * const _##name = &c_##name; \ | |
114 | - struct c_##name##_object { \ | |
115 | - void * TR_class; \ | |
116 | - struct c_##name data; \ | |
117 | - } | |
118 | - | |
119 | + struct TR_class * const _##name = &c_##name | |
119 | 120 | |
120 | 121 | /** |
121 | 122 | * Create a static instance of a class. | ... | ... |
Please
register
or
login
to post a comment