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_INTERFACE_DERIVE_N(instance, klass, baseClass, ...)
68 GBL_INTERFACE_DERIVE_3(instance, klass, baseClass)
70
71#define GBL_INTERFACE_DERIVE_3(instance, klass, baseKlass)
72 struct instance;
73 typedef struct instance instance;
74 struct klass;
75 typedef struct klass klass;
76 struct klass {
77 /*! Inherited base class instance */
78 baseKlass base;
79
80#define GBL_INTERFACE_DERIVE_2(instance, klass)
81 GBL_INTERFACE_DERIVE_3(instance, klass, GblInterface)
82
83#define GBL_INTERFACE_DERIVE_1(instance)
84 GBL_INTERFACE_DERIVE_2(instance, instance##Class)
85
86#define GBL_INTERFACE_DERIVE(...)
88
89#define GBL_INTERFACE_END };
90
91#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
92 struct derivedInstance;
93 typedef struct derivedInstance derivedInstance;
94 struct derivedInstance {
95 union {
96 /*! Pointer to class/vtable structure */
97 derivedInstance##Class* pClass;
98 /*! Inherited base instance structure */
99 baseInstance base;
100 };
101
102#define GBL_INSTANCE_BASE(instance)
103 struct instance;
104 typedef struct instance instance;
105 struct instance {
106 union {
107 /*! Pointer to class/vtable structure */
108 instance##Class* pClass;
109 /*! Inherited base instance structure */
110 GblInstance base;
111 };
112
113#define GBL_INSTANCE_BASE_EMPTY(instance)
114 GBL_INSTANCE_BASE(instance)
116
117#define GBL_INSTANCE_END };
118
119#define GBL_INSTANCE_DERIVE_EMPTY(derived, base)
120 GBL_INSTANCE_DERIVE(derived, base)
122
123#define GBL_TYPEID(instanceStruct)
124 GBL_GLUE(instanceStruct, _type())
125
126#define GBL_CLASS_STRUCT(cType) cType##Class
127
128#define GBL_INSTANCE_PRIVATE_STRUCT(instanceStruct)
129 GBL_GLUE(instanceStruct, _)
130
131#define GBL_CLASS_PRIVATE_STRUCT(instanceStruct)
132 GBL_GLUE(GBL_GLUE(instanceStruct, Class), _)
133
134#ifdef __cplusplus
135# define GBL_DECLARE_TYPE(instanceStruct)
136 extern "C" GBL_DECLARE_TYPE_(instanceStruct)
137#else
138# define GBL_DECLARE_TYPE(instanceStruct)
139 GBL_DECLARE_TYPE_(instanceStruct)
140#endif
141
142#define GBL_DECLARE_TYPE_(instanceStruct)
143 GblType GBL_GLUE(instanceStruct, _type(void)) GBL_NOEXCEPT
144
145#define GBL_DECLARE_UNION(S)
146 union S;
147 typedef union S S;
148 union S
149
150#define GBL_DECLARE_STRUCT(S)
151 struct S;
152 typedef struct S S;
153 struct S
154
155#define GBL_DECLARE_STRUCT_PRIVATE(S)
156 struct S##_;
157 typedef struct S##_ S##_;
158 struct S##_
159
160#define GBL_FORWARD_DECLARE_STRUCT(S)
161 struct S;
162 typedef struct S S;
163
164#define GBL_FORWARD_DECLARE_STRUCT_PRIVATE(S)
165 struct S##_;
166 typedef struct S##_ S
167
168#define GBL_FORWARD_DECLARE_TYPE(t)
169 GBL_TYPEID(t)
170
171#ifndef __cplusplus
172# define GBL_DECLARE_ENUM(E)
173 typedef GblEnum E;
174 enum E
175#else
176# define GBL_DECLARE_ENUM(E)
177 enum E : GblEnum
178#endif
179
180#ifndef __cplusplus
181# define GBL_DECLARE_FLAGS(F)
182 typedef GblFlags F;
183 enum F
184#else
185# define GBL_DECLARE_FLAGS(F)
186 enum F: GblFlags
187#endif
188
189#define GBL_FORWARD_DECLARE_ENUM(E)
190 typedef GBL_ENUM E
191
192#define GBL_FORWARD_DECLARE_FLAGS(F)
193 typedef GBL_FLAGS F
194
195#define GBL_DECLARE_OPAQUE(S)
196 struct S##_;
197 typedef struct S##_* S
198
199#define GBL_PRIVATE_BEGIN struct {
200
201#define GBL_PRIVATE_END } private_; //!< Private data structure
202
203#define GBL_PRIV(a) (a).private_
204#define GBL_PRIV_REF(a) (a)->private_
205
206#define GBL_VSELF GBL_SELF_TYPE self
207
208#define GBL_KLASS GBL_GLUE(GBL_SELF_TYPE, Class)* pSelf
209#define GBL_CKLASS const GBL_KLASS
210
211#define GBL_SELF GBL_SELF_TYPE* pSelf
212#define GBL_CSELF const GBL_SELF
213
214// sizeof(emptyStruct) is 1 in Cpp, 0 in C!
215#define GBL_DEFINE_EMPTY_STRUCT(S)
216 typedef struct S {
217 char cppCompat;
218 } S
219
220#define GBL_UNUSED_(a)
221 (void)(a)
222
223#define GBL_UNUSED(...) GBL_MAP_LIST(GBL_UNUSED_, __VA_ARGS__)
224
225#ifdef GBL_CTX_SHARED_LIB
226# ifdef GBL_CTX_EXPORTS
227# define GBL_EXPORT GBL_EXPORT_SHARED
228# else
229# define GBL_EXPORT GBL_IMPORT_SHARED
230# endif
231#else
232# define GBL_EXPORT
233#endif
234
235// ===== MISCELLANEOUS META TUPLES FOR MACRO GENERATORS ====
236#define GBL_DECL_VAR_TYPE(type, ...)
237 type
238#define GBL_DECL_VAR_NAME(type, name)
239 name
240
241#define GBL_DECL_VAR(type, name)
242 GBL_DECL_VAR_TYPE(type, name) GBL_DECL_VAR_NAME(type, name)
243
244#define GBL_DECL_VAR_PAIR_TYPE(pair)
246
247#define GBL_DECL_VAR_PAIR_NAME(pair)
249
250#define GBL_DECL_VAR_PAIR(pair)
251 GBL_DECL_VAR pair
252
253
254// === ENUMERATION AUTOGENERATION ===========
255
256#define GBL_ENUM_TABLE_DECL_ENUM(cName, value, name, string)
257 /*! string */
258 cName = value,
259
260
261#define GBL_ENUM_TABLE_DECLARE(table)
264 };
266
267#define GBL_ENUM_TABLE_RETURN_STRING(cName, value, name, string)
268 case value: return string;
269
270#define GBL_ENUM_TABLE_TO_STRING(table, value)
271 switch(value) {
273 }
274
275#define GBL_ENUM_TABLE_DECLARE_STRINGIFIER(table)
276 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) {
277 GBL_EVAL(GBL_ENUM_TABLE_TO_STRING(table, value));
278 return "";
279 }
280
281#define GBL_META_ENUM_TUPLE(tuple)
282
283#define GBL_META_ENUM_TUPLE_TYPE_INFO(typeInfo, valueTable) typeInfo
284
285#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_CNAME(cName, name, description, stringifier) cName
286#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_NAME(cName, name, description, stringifier) name
287#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_DESCRIPTION(cName, name, description, stringifier) description
288#define GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_STRINGIFIER(cName, name, description, stringifier) stringifier
289
290#define GBL_META_ENUM_TUPLE_VALUE_ARRAY(typeInfo, valueArray) valueArray
291
292#define GBL_META_ENUM_TUPLE_VALUE_ARRAY_TUPLE_VALUE(...) GBL_EVAL __VA_ARGS__
293
294#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_CNAME(cName, value, name, string) cName
295#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_NAME(cName, value, name, string) name
296#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_VALUE(cName, value, name, string) value
297#define GBL_META_ENUM_TUPLE_VALUE_PROPERTY_STRING(cName, value, name, string) string
298
299#define GBL_META_ENUM_TYPE_PROPERTY(table, postfix) GBL_META_ENUM_TUPLE_TYPE_INFO_PROPERTY_##postfix GBL_META_ENUM_TUPLE_TYPE_INFO table
300
301
302#ifdef __cplusplus
303}
304#endif
305
306#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_CLASS_DERIVE_N(instance, baseKlass,...)
#define GBL_INSTANCE_END
#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(...)