1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#ifndef __COBJ_IMPLS_H__
# define __COBJ_IMPLS_H__
# 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(klass, ...) klass##_del(__VA_ARGS__)
#endif /* __COBJ_IMPLS_H__ */
#if defined(__USE_C_OBJSYS__)
# undef New
# undef Del
# undef __USE_C_OBJSYS__
#elif defined(__COBJ_PRIV_IMPLS_H__)
# define UNUSED(arg) while(0 && (arg))
# define TYPE(klass) \
struct __ ## klass ## _impl
# define GETTER(klass, field, type, body, ...) \
type klass##_get_##field(klass self, ## __VA_ARGS__) \
body
# define SETTER(klass, field, type, body, ...) \
bool klass##_set_##field(klass self, ## __VA_ARGS__, type value) \
body
# define DEFINE(klass, name, type, body, ...) \
type klass##_##name(klass self, ## __VA_ARGS__) \
body
# define NEW(klass, body, ...) \
klass klass ## _new(__VA_ARGS__) \
body
# define DEL(klass, body, ...) \
void klass ## _del(klass self, ## __VA_ARGS__) \
body
# define Property(klass, name) \
(self->get_ ## name) = (& klass ## _ ## get_ ## name), \
(self->set_ ## name) = (& klass ## _ ## set_ ## name)
# define Callable(klass, name) \
(self->name) = (& klass ## _ ## name)
# define SELF(name) \
self->_property_ ## name
# define GET(obj, name) \
(obj)->_property_ ## name
#else
# define Class(klass, data, ...) \
typedef struct __##klass##_impl * klass; \
klass klass ## _new(__VA_ARGS__); \
void klass ## _delete(); \
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)
# define __USE_C_OBJSYS__
#endif
|