summaryrefslogtreecommitdiff
path: root/src/cobj.h
blob: 736170b614c13e69264f5512e7524c59d5b51166 (plain) (blame)
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
72
73
74
75
#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 CLASS
#	undef GETTER
#	undef SETTER
#	undef DEFINE
#	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 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 PROPERTY(klass, name) \
			(self->get_ ## name) = (& klass ## _ ## get_ ## name), \
			(self->set_ ## name) = (& klass ## _ ## set_ ## name)

#	define CALLABLE(klass, name) \
			(self->name) = (& klass ## _ ## name)

#	define DEL() void   (*del)(klass self)
#	define __USE_C_OBJSYS__
#endif