Showing
2 changed files
with
20 additions
and
3 deletions
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | 8 | ||
9 | typedef void (* fptr_ctor)(void *, va_list *); | 9 | typedef void (* fptr_ctor)(void *, va_list *); |
10 | typedef void (* fptr_dtor)(void *); | 10 | typedef void (* fptr_dtor)(void *); |
11 | -typedef void (* fptr_clone)(void *, const void * const); | 11 | +typedef void (* fptr_clone)(void *, void * const); |
12 | 12 | ||
13 | extern const struct interface i_Class; | 13 | extern const struct interface i_Class; |
14 | 14 | ||
@@ -21,9 +21,11 @@ struct i_Class { | @@ -21,9 +21,11 @@ struct i_Class { | ||
21 | 21 | ||
22 | extern void * classNew(class_ptr, ...); | 22 | extern void * classNew(class_ptr, ...); |
23 | extern void classDelete(void **); | 23 | extern void classDelete(void **); |
24 | +extern void * classClone(void *); | ||
24 | 25 | ||
25 | -#define new(class,...) classNew(_##class, __VA_ARGS__) | ||
26 | -#define delete(object) classDelete((void **)(object)) | 26 | +#define new(class,...) classNew(_##class, ##__VA_ARGS__) |
27 | +#define delete(object) classDelete((void **)(object)) | ||
28 | +#define clone(object) classClone((void *)(object)) | ||
27 | 29 | ||
28 | #endif // __INTERFACE_CLASS_H__ | 30 | #endif // __INTERFACE_CLASS_H__ |
29 | 31 |
@@ -38,4 +38,19 @@ classDelete(void ** object) | @@ -38,4 +38,19 @@ classDelete(void ** object) | ||
38 | *object = NULL; | 38 | *object = NULL; |
39 | } | 39 | } |
40 | 40 | ||
41 | +void * | ||
42 | +classClone(void * _object) | ||
43 | +{ | ||
44 | + class_ptr class = class_getClass(_object); | ||
45 | + void * object = calloc(1, class->object_size + sizeof(void*)); | ||
46 | + | ||
47 | + * (class_ptr *)object = class; | ||
48 | + object += sizeof(void*); | ||
49 | + | ||
50 | +#undef clone | ||
51 | + CALL(object, Class, clone, _object); | ||
52 | + | ||
53 | + return object; | ||
54 | +} | ||
55 | + | ||
41 | // vim: set ts=4 sw=4: | 56 | // vim: set ts=4 sw=4: |
Please
register
or
login
to post a comment