libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
Type Templates

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.

// type UUID macro (expands to GblObject_type() registration function)
#define GBL_OBJECT_TYPE (GBL_TYPEID(GblObject))
// instance function-style cast macro
#define GBL_OBJECT(instance) (GBL_CAST(instance, GblObject))
// class cast function-style cast macro
#define GBL_OBJECT_CLASS(klass) (GBL_CLASS_CAST(klass, GblObject))
// instance-to-class cast macro
#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:

// create a floating object class
// - easy cast to particular class
// lets override just its implementation of the GblIEventHandlerClass interface
// - easy cast to particular interface
GblIEventHandlerClass* pIEvent = GBL_IEVENT_HANDLER_CLASS(pClass);
// override virtual method
pIEvent->pFnEvent = [&](GblIEventHandler* pSelf, GblEvent* pEvent) {
// easy cast to particular instance type
GblObject* pSelfObj = GBL_OBJECT(pSelf);
printf("%s received an Event!", GblObject_name(pSelfObj));
if(GBL_TYPECHECK(pEvent, MyEventType)) {
// easy cast to particular event instance
MyCustomEvent* pEvent = MY_CUSTOM_EVENT(pEvent);
// do something
} else if(GBL_TYPECHECK(pEvent, MyOtherEventType)) {
// easy cast to particular event instance
SomeOtherEvent* pEvent = SOME_OTHER_EVENT(pEvent);
// do something
}
}
// easy cast from object to GblInstance base
GblInstance_sinkClass(GBL_INSTANCE(pObject));
// easy cast from object to GblBox base
GblBox_unref(GBL_BOX(pObject));
#define GBL_BOX(self)
Casts a GblInstance to GblBox.
Definition gimbal_box.h:28
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.