libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_decls.h
Go to the documentation of this file.
1/*! \file
2 * \brief Helper defines for struct, enum, flags, handle delcarations
3 * \ingroup core
4 * \sa gimbal_macro_utilities.h
5 *
6 * \author Falco Girgis
7 */
8
9#ifndef GIMBAL_DECLS_H
10#define GIMBAL_DECLS_H
11
13#include "../preprocessor/gimbal_macro_utils.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#ifdef __cplusplus
20# define GBL_DECLS_BEGIN extern "C" {
21# define GBL_DECLS_END }
22#else
23# define GBL_DECLS_BEGIN
24# define GBL_DECLS_END
25#endif
26
27#define GBL_CLASS_IMPL_INTERFACE(iface)
28 /*! Embedded interface class structure */
29 iface##Class iface##Impl;
30
31#define GBL_CLASS_DERIVE_N(instance, baseKlass, ...)
32 GBL_CLASS_DERIVE_2(instance, baseKlass)
34
35#define GBL_CLASS_DERIVE_2(instance, baseInstance)
36 struct instance##Class;
37 typedef struct instance##Class instance##Class;
38 struct instance##Class {
39 /*! Inherited base class structure */
40 baseInstance##Class base;
41
42#define GBL_CLASS_DERIVE_1(instance)
43 GBL_CLASS_DERIVE_2(instance, Gbl)
44
45#define GBL_CLASS_DERIVE(...)
47
48#define GBL_CLASS_BASE_N(instance, ...)
49 GBL_CLASS_DERIVE_N(instance, Gbl, __VA_ARGS__)
50
51#define GBL_CLASS_BASE_1(instance)
52 GBL_CLASS_DERIVE_2(instance, Gbl)
53
54#define GBL_CLASS_BASE(...)
56
57#define GBL_CLASS_BASE_EMPTY(...)
58 GBL_CLASS_BASE(__VA_ARGS__)
60
61#define GBL_CLASS_END };
62
63#define GBL_CLASS_DERIVE_EMPTY(...)
64 GBL_CLASS_DERIVE(__VA_ARGS__)
66
67#define GBL_STATIC_CLASS_DERIVE_N(klass, ...)
68 GBL_CLASS_DERIVE_N(klass, GblStatic, __VA_ARGS__)
69
70#define GBL_STATIC_CLASS_DERIVE_1(klass)
71 GBL_CLASS_DERIVE_2(klass, GblStatic)
72
73#define GBL_STATIC_CLASS_DERIVE(...)
75
76#define GBL_STATIC_CLASS_DERIVE_EMPTY(...)
77 GBL_STATIC_CLASS_DERIVE(__VA_ARGS__)
79
80#define GBL_INTERFACE_DERIVE_N(instance, klass, baseClass, ...)
81 GBL_INTERFACE_DERIVE_3(instance, klass, baseClass)
83
84#define GBL_INTERFACE_DERIVE_3(instance, klass, baseKlass)
85 struct instance;
86 typedef struct instance instance;
87 struct klass;
88 typedef struct klass klass;
89 struct klass {
90 /*! Inherited base class instance */
91 baseKlass base;
92
93#define GBL_INTERFACE_DERIVE_2(instance, klass)
94 GBL_INTERFACE_DERIVE_3(instance, klass, GblInterface)
95
96#define GBL_INTERFACE_DERIVE_1(instance)
97 GBL_INTERFACE_DERIVE_2(instance, instance##Class)
98
99#define GBL_INTERFACE_DERIVE(...)
101
102#define GBL_INTERFACE_END };
103
104#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
105 struct derivedInstance;
106 typedef struct derivedInstance derivedInstance;
107 struct derivedInstance {
108 union {
109 /*! Pointer to class/vtable structure */
110 derivedInstance##Class* pClass;
111 /*! Inherited base instance structure */
112 baseInstance base;
113 };
114
115#define GBL_INSTANCE_BASE(instance)
116 struct instance;
117 typedef struct instance instance;
118 struct instance {
119 union {
120 /*! Pointer to class/vtable structure */
121 instance##Class* pClass;
122 /*! Inherited base instance structure */
123 GblInstance base;
124 };
125
126#define GBL_INSTANCE_BASE_EMPTY(instance)
127 GBL_INSTANCE_BASE(instance)
129
130#define GBL_INSTANCE_END };
131
132#define GBL_INSTANCE_DERIVE_EMPTY(derived, base)
133 GBL_INSTANCE_DERIVE(derived, base)
135
136#define GBL_TYPEID(instanceStruct)
137 GBL_GLUE(instanceStruct, _type())
138
139#define GBL_CLASS_STRUCT(cType) cType##Class
140
141#define GBL_INSTANCE_PRIVATE_STRUCT(instanceStruct)
142 GBL_GLUE(instanceStruct, _)
143
144#define GBL_CLASS_PRIVATE_STRUCT(instanceStruct)
145 GBL_GLUE(GBL_GLUE(instanceStruct, Class), _)
146
147#ifdef __cplusplus
148# define GBL_DECLARE_TYPE(instanceStruct)
149 extern "C" GBL_DECLARE_TYPE_(instanceStruct)
150#else
151# define GBL_DECLARE_TYPE(instanceStruct)
152 GBL_DECLARE_TYPE_(instanceStruct)
153#endif
154
155#define GBL_DECLARE_TYPE_(instanceStruct)
156 GblType GBL_GLUE(instanceStruct, _type(void)) GBL_NOEXCEPT
157
158#define GBL_DERIVE_EMPTY_TYPE(derivedInstance, baseInstance)
159 GBL_CLASS_DERIVE(derivedInstance, baseInstance)
161 GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
163 GBL_DECLARE_TYPE(derivedInstance);
164
165
166#define GBL_DECLARE_UNION(S)
167 union S;
168 typedef union S S;
169 union S
170
171#define GBL_DECLARE_STRUCT(S)
172 struct S;
173 typedef struct S S;
174 struct S
175
176#define GBL_DECLARE_STRUCT_PRIVATE(S)
177 struct S##_;
178 typedef struct S##_ S##_;
179 struct S##_
180
181#define GBL_FORWARD_DECLARE_STRUCT(S)
182 struct S;
183 typedef struct S S;
184
185#define GBL_FORWARD_DECLARE_STRUCT_PRIVATE(S)
186 struct S##_;
187 typedef struct S##_ S
188
189#define GBL_FORWARD_DECLARE_TYPE(t)
190 GBL_TYPEID(t)
191
192#ifndef __cplusplus
193# define GBL_DECLARE_ENUM(E)
194 typedef GblEnum E;
195 enum E
196#else
197# define GBL_DECLARE_ENUM(E)
198 enum E : GblEnum
199#endif
200
201#ifndef __cplusplus
202# define GBL_DECLARE_FLAGS(F)
203 typedef GblFlags F;
204 enum F
205#else
206# define GBL_DECLARE_FLAGS(F)
207 enum F: GblFlags
208#endif
209
210#define GBL_FORWARD_DECLARE_ENUM(E)
211 typedef GBL_ENUM E
212
213#define GBL_FORWARD_DECLARE_FLAGS(F)
214 typedef GBL_FLAGS F
215
216#define GBL_DECLARE_OPAQUE(S)
217 struct S##_;
218 typedef struct S##_* S
219
220#define GBL_PRIVATE_BEGIN struct {
221
222#define GBL_PRIVATE_END } private_; //!< Private data structure
223
224#define GBL_PRIV(a) (a).private_
225#define GBL_PRIV_REF(a) (a)->private_
226
227#define GBL_VSELF GBL_SELF_TYPE self
228
229#define GBL_KLASS GBL_GLUE(GBL_SELF_TYPE, Class)* pSelf
230#define GBL_CKLASS const GBL_KLASS
231
232#define GBL_SELF GBL_SELF_TYPE* pSelf
233#define GBL_CSELF const GBL_SELF
234
235// sizeof(emptyStruct) is 1 in Cpp, 0 in C!
236#define GBL_DEFINE_EMPTY_STRUCT(S)
237 typedef struct S {
238 char cppCompat;
239 } S
240
241#define GBL_UNUSED_(a)
242 (void)(a)
243
244#define GBL_UNUSED(...) GBL_MAP_LIST(GBL_UNUSED_, __VA_ARGS__)
245
246#ifdef GBL_CTX_SHARED_LIB
247# ifdef GBL_CTX_EXPORTS
248# define GBL_EXPORT GBL_EXPORT_SHARED
249# else
250# define GBL_EXPORT GBL_IMPORT_SHARED
251# endif
252#else
253# define GBL_EXPORT
254#endif
255
256// ===== MISCELLANEOUS META TUPLES FOR MACRO GENERATORS ====
257#define GBL_DECL_VAR_TYPE(type, ...)
258 type
259#define GBL_DECL_VAR_NAME(type, name)
260 name
261
262#define GBL_DECL_VAR(type, name)
263 GBL_DECL_VAR_TYPE(type, name) GBL_DECL_VAR_NAME(type, name)
264
265#define GBL_DECL_VAR_PAIR_TYPE(pair)
267
268#define GBL_DECL_VAR_PAIR_NAME(pair)
270
271#define GBL_DECL_VAR_PAIR(pair)
272 GBL_DECL_VAR pair
273
274
275// === ENUMERATION AUTOGENERATION ===========
276
277#define GBL_ENUM_TABLE_DECL_ENUM(cName, value, name, string)
278 /*! string */
279 cName = value,
280
281
282#define GBL_ENUM_TABLE_DECLARE(table)
285 };
287
288#define GBL_ENUM_TABLE_RETURN_STRING(cName, value, name, string)
289 case value: return string;
290
291#define GBL_ENUM_TABLE_TO_STRING(table, value)
292 switch(value) {
294 }
295
296#define GBL_ENUM_TABLE_DECLARE_STRINGIFIER(table)
297 GBL_INLINE GBL_CONSTEXPR const char* GBL_EVAL(GBL_META_ENUM_TYPE_PROPERTY(table, STRINGIFIER))(GBL_EVAL(GBL_META_ENUM_TYPE_PROPERTY(table, CNAME)) value) {
298 GBL_EVAL(GBL_ENUM_TABLE_TO_STRING(table, value));
299 return "";
300 }
301
302#define GBL_META_ENUM_TUPLE(tuple)
303
304#define GBL_META_ENUM_TUPLE_TYPE_INFO(typeInfo, valueTable) typeInfo
305
306#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_CNAME(cName, name, description, stringifier) cName
307#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_NAME(cName, name, description, stringifier) name
308#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_DESCRIPTION(cName, name, description, stringifier) description
309#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_STRINGIFIER(cName, name, description, stringifier) stringifier
310
311#define GBL_META_ENUM_TUPLE_VALUE_ARRAY(typeInfo, valueArray) valueArray
312
313#define GBL_META_ENUM_TUPLE_VALUE_ARRAY_TUPLE_VALUE(...) GBL_EVAL __VA_ARGS__
314
315#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_CNAME(cName, value, name, string) cName
316#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_NAME(cName, value, name, string) name
317#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_VALUE(cName, value, name, string) value
318#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_STRING(cName, value, name, string) string
319
320#define GBL_META_ENUM_TYPE_PROPERTY(table, postfix) GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_##postfix GBL_META_ENUM_TUPLE_TYPE_INFO table
321
322
323#ifdef __cplusplus
324}
325#endif
326
327#endif // GIMBAL_DECLS_H
#define GBL_NOEXCEPT
#define GBL_CONSTEXPR
#define GBL_INLINE
#define GBL_KLASS
#define GBL_META_ENUM_TUPLE_VALUE_ARRAY(typeInfo, valueArray)
#define GBL_INSTANCE_BASE(instance)
#define GBL_ENUM_TABLE_DECL_ENUM(cName, value, name, string)
#define GBL_TYPEID(instanceStruct)
#define GBL_INTERFACE_DERIVE_3(instance, klass, baseKlass)
#define GBL_CLASS_IMPL_INTERFACE(iface)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_CLASS_BASE(...)
#define GBL_DECL_VAR(type, name)
#define GBL_DECL_VAR_TYPE(type,...)
#define GBL_DECLARE_ENUM(E)
#define GBL_CLASS_DERIVE(...)
#define GBL_INTERFACE_DERIVE(...)
#define GBL_INTERFACE_DERIVE_2(instance, klass)
#define GBL_DECL_VAR_NAME(type, name)
#define GBL_DECLARE_TYPE_(instanceStruct)
#define GBL_UNUSED_(a)
#define GBL_DECLARE_TYPE(instanceStruct)
#define GBL_CLASS_DERIVE_N(instance, baseKlass,...)
#define GBL_INSTANCE_END
#define GBL_STATIC_CLASS_DERIVE(...)
#define GBL_ENUM_TABLE_TO_STRING(table, value)
#define GBL_CLASS_DERIVE_2(instance, baseInstance)
#define GBL_CLASS_END
#define GBL_META_ENUM_TUPLE_TYPE_INFO(typeInfo, valueTable)
#define GBL_ENUM_TABLE_DECLARE_STRINGIFIER(table)
#define GBL_ENUM_TABLE_RETURN_STRING(cName, value, name, string)
#define GBL_META_ENUM_TYPE_PROPERTY(table, postfix)
#define GBL_VA_OVERLOAD_CALL(BASE, SUFFIXER,...)
#define GBL_GLUE(A, B)
#define GBL_VA_OVERLOAD_SUFFIXER_3_N(...)
#define GBL_VA_OVERLOAD_SUFFIXER_1_N(...)
#define GBL_VA_OVERLOAD_SUFFIXER_2_N(...)
#define GBL_MAP(f,...)
Applies the function macro f to each of the remaining parameters.
#define GBL_MAP_LIST(f,...)
#define GBL_MAP_TUPLES(f,...)
#define GBL_EVAL(...)