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)))
176#define GBL_CAST_(cType, self) ((cType*)GblInstance_cast((GblInstance*)self,GBL_TYPEID(cType)))
177#define GBL_AS_(cType, self) ((cType*)GblInstance_as((GblInstance*)self, GBL_TYPEID(cType)))
178#define GBL_CLASSOF_(cType, self) ((GBL_CLASS_STRUCT(cType)*)GblClass_cast(GblInstance_class((GblInstance*)self), GBL_TYPEID(cType)))
179#define GBL_CLASSOF_AS_(cType, self) ((GBL_CLASSOF(cType)*)GblClass_as(GblInstance_class((GblInstance*)self), GBL_TYPEID(cType)))
181#define GBL_VCALL_(cType, method, ...)
185 GBL_CTX_VERIFY(pClass->method, GBL_RESULT_ERROR_INVALID_VIRTUAL_CALL);
189#define GBL_VCALL_DEFAULT_(cType, method, ...)
194 GBL_CTX_VERIFY(pClass->method, GBL_RESULT_ERROR_INVALID_VIRTUAL_CALL);
200
201
202
203
204
205
208
209
210
211
212
213
216
217
218
219
220
221
222
223
224
227
228
229
230
231
232
233
234
235
238
239
240
241
242
243
244
247
248
249
250
251
252
253
256
257
258
259
260
261
262
265
266
267
268
269
270
271
272
276
277
278
279
280
281
282
286
287
288
289
290
291
292
295
296
297
298
299
302
303
304
305
306
307
310
311
312
313
314
317
318
319
320
321
324
325
326
327
328
#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_CLASSOF(cType, self)
#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.
GblClass * GblInstance_class(const GblInstance *pSelf)
Returns the GblClass associated with the given GblInstance.
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.
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)