Boilerplate macros for type operations.
At the top of the file for most libGimbal derived types, along with the type identifier, you will find a collection of convenience utility macros implementing function-style casts for the given type.
#define GBL_OBJECT_TYPE (GBL_TYPEID(GblObject))
#define GBL_OBJECT(instance) (GBL_CAST(instance, GblObject))
#define GBL_OBJECT_CLASS(klass) (GBL_CLASS_CAST(klass, GblObject))
#define GBL_OBJECT_GET_CLASS(instance) (GBL_CLASSOF(instance, GblObject))
While these macros are obviously optional, they do add a lot to the codebase in terms of readability and convenience as well as uniform styling. With these sorts of macros defined, we then gain access to lots of convenience:
pIEvent->pFnEvent = [&](GblIEventHandler* pSelf,
GblEvent* pEvent) {
printf("%s received an Event!", GblObject_name(pSelfObj));
if(GBL_TYPECHECK(pEvent, MyEventType)) {
MyCustomEvent* pEvent = MY_CUSTOM_EVENT(pEvent);
} else if(GBL_TYPECHECK(pEvent, MyOtherEventType)) {
SomeOtherEvent* pEvent = SOME_OTHER_EVENT(pEvent);
}
}
#define GBL_BOX(self)
Casts a GblInstance to GblBox.
GblClass * GblClass_createFloating(GblType type, size_t size)
Creates a standalone, unowned, "floating" class for the given type, which can override defaults.
#define GBL_INSTANCE(self)
Casts GblInstance-compatible to GblInstance.
GblObject * GblObject_createWithClass(GblObjectClass *pClass,...)
Creates an object-derived type on the heap, with the given class, initializing it with a NULL-termina...
#define GBL_OBJECT(self)
Casts a GblInstance to a GblObject.
#define GBL_OBJECT_CLASS(klass)
Casts a GblClass to a GblObjectClass.
#define GBL_OBJECT_TYPE
GblType UUID for GblObject.
Event base class for use with the event system.
GblClass structure for GblIEventHandler.
GblClass structure for GblObject.
Main Object-Oriented Instance with Properties, EventHandlers, and Parenting.