2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef GIMBAL_INSTANCE_H
17#define GIMBAL_INSTANCE_H
19#include "../../core/gimbal_ctx.h"
20#include "../classes/gimbal_class.h"
23
24
25
27#define GBL_INSTANCE(self) ((GblInstance*)self)
28#define GBL_INSTANCE_GET_CLASS(self) (GblInstance_class(GBL_INSTANCE(self)))
32
33
34
35
37#define GBL_TYPEOF(self) GBL_TYPEOF_
(self)
39#define GBL_PRIVATE(cType, self) GBL_PRIVATE_
(cType, self)
41#define GBL_PUBLIC(cType, selfPriv) GBL_PUBLIC_
(cType, selfPriv)
43#define GBL_TYPECHECK(cType, self) GBL_TYPECHECK_
(cType, self)
45#define GBL_CAST(cType, self) GBL_CAST_
(cType, self)
47#define GBL_AS(cType, self) GBL_AS_
(cType, self)
49#define GBL_CLASSOF(cType, self) GBL_CLASSOF_
(cType, self)
51#define GBL_CLASSOF_AS(cType, self) GBL_CLASSOF_AS_
(cType, self)
53#define GBL_VCALL(cType, method, ...) GBL_VCALL_
(cType, method, __VA_ARGS__)
55#define GBL_VCALL_DEFAULT(cType, method, ...) GBL_VCALL_DEFAULT_
(cType, method, __VA_ARGS__)
58#define GBL_SELF_TYPE GblInstance
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
84
85
86
102
103
104
105
115
116
117
118
126
127
128
129
141
142
143
144
158#define GblInstance_create(...)
159 GblInstance_createDefault_
(__VA_ARGS__)
160#define GblInstance_createDefault_(...)
161 GblInstance_createDefault__
(__VA_ARGS__, 0
, GBL_NULL)
162#define GblInstance_createDefault__(type, size, klass, ...)
163 (GblInstance_create
)(type, size, klass)
165#define GblInstance_construct(...)
166 GblInstance_constructDefault_
(__VA_ARGS__)
167#define GblInstance_constructDefault_(...)
168 GblInstance_constructDefault__
(__VA_ARGS__, GBL_NULL)
169#define GblInstance_constructDefault__(self, type, klass, ...)
170 (GblInstance_construct
)(self, type, klass)
172#define GBL_TYPEOF_(self) (GblInstance_typeOf(GBL_INSTANCE(self)))
174#define GBL_PUBLIC_(cType, selfPriv) ((cType*)GblInstance_public((const void*)selfPriv, GBL_TYPEID(cType)))
177# define GBL_CAST_(cType, self) ((cType*)GblInstance_cast((GblInstance*)self, GBL_TYPEID(cType)))
179# define GBL_CAST_(cType, self) ((cType*)self)
181#define GBL_AS_(cType, self) ((cType*)GblInstance_as((GblInstance*)self, GBL_TYPEID(cType)))
182#define GBL_CLASSOF_(cType, self) ((GBL_CLASS_STRUCT(cType)*)GblClass_cast(GblInstance_class((GblInstance*)self), GBL_TYPEID(cType)))
183#define GBL_CLASSOF_AS_(cType, self) ((GBL_CLASSOF
(cType)*)GblClass_as(GblInstance_class((GblInstance*)self), GBL_TYPEID(cType)))
185#define GBL_VCALL_(cType, method, ...)
189 GBL_CTX_VERIFY(pClass->method, GBL_RESULT_ERROR_INVALID_VIRTUAL_CALL);
193#define GBL_VCALL_DEFAULT_(cType, method, ...)
198 GBL_CTX_VERIFY(pClass->method, GBL_RESULT_ERROR_INVALID_VIRTUAL_CALL);
204
205
206
207
208
209
212
213
214
215
216
217
220
221
222
223
224
225
226
227
228
231
232
233
234
235
236
237
238
239
242
243
244
245
246
247
248
251
252
253
254
255
256
257
260
261
262
263
264
265
266
269
270
271
272
273
274
275
276
280
281
282
283
284
285
286
290
291
292
293
294
295
296
299
300
301
302
303
306
307
308
309
310
311
314
315
316
317
318
321
322
323
324
325
328
329
330
331
332
#define GBL_BUILTIN_TYPE(prefix)
Returns a type from the macro prefix of a builtin type.
#define GBL_CTX_CALL(...)
#define GBL_CTX_VERIFY(...)
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_PRIVATE_STRUCT(instanceStruct)
#define GBL_CLASS_STRUCT(cType)
GblInstance * GblInstance_create(GblType type, size_t publicSize, GblClass *pClass)
Creates and returns an instance, optionally with an extended size and/or non-default class.
GblRefCount GblInstance_destruct(GblInstance *pSelf)
Destructs but doesn't deallocate an instance. It must have been created with GblInstance_construct().
GblRefCount GblInstance_destroy(GblInstance *pSelf)
Destructs and deallocates an instance. It must have been created with GblInstance_create().
#define GBL_INSTANCE(self)
Casts GblInstance-compatible to GblInstance.
GBL_RESULT GblInstance_construct(GblInstance *pSelf, GblType type, GblClass *pClass)
Constructs an instance, optionally with a non-default class, returning a result code.
#define GBL_TUPLE_FIRST(...)
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
Base struct for all instantiable meta types.
GblBool GblInstance_check(const GblInstance *pSelf, GblType toType)
Returns GBL_TRUE if the given instance's type is compatible with toType.
void * GblInstance_private(const GblInstance *pSelf, GblType base)
Returns the private structure associated with the given base type of the instance.
GblClass * pClass
READ-ONLY Pointer to Instance's Class, do not modify directly.
GBL_RESULT GblInstance_swizzleClass(GblInstance *pSelf, GblClass *pClass)
Swaps out the class associated with the instance, without taking ownership of it.
GblType GblInstance_typeOf(const GblInstance *pSelf)
Returns the GblType associated with the given GblInstance.
size_t GblInstance_size(const GblInstance *pSelf)
Returns the size of the given GblInstance's public data segment.
GblClass * GblInstance_class(const GblInstance *pSelf)
Returns the GblClass associated with the given GblInstance.
GblInstance * GblInstance_public(const void *pPriv, GblType base)
Casts back to the instance type from a base type's private data segment structure.
GblInstance * GblInstance_as(GblInstance *pSelf, GblType toType)
Attempts to cast the given instance to toType, gracefully returning NULL upon failure.
GBL_RESULT GblInstance_sinkClass(GblInstance *pSelf)
Takes ownership of the class associated with the instance, deallocating it with the instance.
GBL_RESULT GblInstance_floatClass(GblInstance *pSelf)
Relinquishes ownership of the class assosciated with the instance, but maintaining their association.
GblInstance * GblInstance_cast(GblInstance *pSelf, GblType toType)
Attempts to cast the given instance to toType, raising an error and returning NULL upon failure.
size_t GblInstance_privateSize(const GblInstance *pSelf)
Returns the size of the given GblInstance's private data segment.
size_t GblInstance_totalSize(const GblInstance *pSelf)
Returns the instance's combined DEFAULT size (not extended allocation size)