#if defined(__COBJ_PUB__) && defined(__COBJ_DECL__) || defined(__COBJ_IMPL__) && defined(__COBJ_H__) # undef Atom # undef Attr # undef Call # undef Class # undef DefaultDelete # undef Define # undef Del # undef DelF # undef Func # undef GET # undef Get # undef List # undef New # undef Prop # undef Self # undef Set # undef TYPE # undef UNUSED # undef __COBJ_DECL__ # undef __COBJ_PUB__ #endif #if ! defined(__COBJ_H__) && ! defined(__COBJ_IMPL__) && ! defined(__COBJ_DECL__) # define Get(instance, field, ...) \ (instance)->get_##field(instance, ## __VA_ARGS__) # define Set(instance, field, ...) \ (instance)->set_##field(instance, ## __VA_ARGS__) # define Call(instance, fun, ...) \ (instance)->fun(instance, ## __VA_ARGS__) # define New(klass, ...) \ klass##_new(__VA_ARGS__) # define Del(instance) \ (instance)->destroy((instance)), instance = NULL #elif defined(__COBJ_DECL__) # define Class(klass, data, ...) \ typedef struct __##klass##_impl * klass; \ klass klass ## _new(__VA_ARGS__); \ void klass ## _delete(klass); \ struct __##klass##_impl data # define List(klass, field, type, dim, ...) \ type _property_ ## field dim; \ type* (*get_ ## field)(klass, ## __VA_ARGS__); \ bool (*set_ ## field)(klass, ## __VA_ARGS__, const type * const) # define Atom(klass, field, type, ...) \ type _property_ ## field; \ type (*get_ ## field)(klass, ## __VA_ARGS__);\ bool (*set_ ## field)(klass, ## __VA_ARGS__, type) # define Func(klass, name, type, ...) \ type (*name)(klass, ## __VA_ARGS__) # define Del(klass) \ void (*destroy)(klass) #elif defined(__COBJ_IMPL__) # define UNUSED(arg) while(0 && (arg)) # define TYPE(klass) \ struct __ ## klass ## _impl # define Get(klass, field, type, body, ...) \ type klass##_get_##field(klass self, ## __VA_ARGS__) \ body # define Set(klass, field, type, body, ...) \ bool klass##_set_##field(klass self, ## __VA_ARGS__, type value) \ body # define Def(klass, name, type, body, ...) \ type klass##_##name(klass self, ## __VA_ARGS__) \ body # define New(klass, body, ...) \ klass klass ## _new(__VA_ARGS__) { \ klass self = (klass)malloc(sizeof(TYPE(klass))); \ if(self != NULL) body; \ return self; \ } # define Del(klass, body, ...) \ void klass ## _delete(klass self, ## __VA_ARGS__) \ body # define Prop(klass, name) \ (self->get_ ## name) = (& klass ## _ ## get_ ## name), \ (self->set_ ## name) = (& klass ## _ ## set_ ## name) # define Func(klass, name) \ (self->name) = (& klass ## _ ## name) # define DelF(klass) \ (self->destroy) = (&klass ## _delete) # define Self(name) \ self->_property_ ## name # define Attr(instance, name) \ (instance)->_property_ ## name # define Call(instance, fun, ...) \ (instance)->fun(instance, ## __VA_ARGS__) # define DefaultDelete { \ if(self != NULL) free(self); \ } #endif