|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | objInstCreate(clsname) (clsname*)_objInstCreate(&objClassInfoName(clsname)) |
| #define | objInstInit(inst) _objInstInit(objInstBase(inst), (inst)->_clsinfo) |
| #define | _objinit_guaranteed _Post_equal_to_(true) |
| #define | _objfactory_guaranteed _Ret_valid_ |
| #define | _objfactory_check _Ret_opt_valid_ _Check_return_ |
Functions | |
| intptr | objDefaultCmp (void *self, void *other, uint32 flags) |
| uint32 | objDefaultHash (void *self, uint32 flags) |
Functions and macros for implementing classes and interfaces. These should only be used within class implementation files, not by code that merely uses objects.
IMPORTANT: Do not call these functions from outside class factory functions and implementation code. Regular object users should use the public API (objAcquire, objRelease, etc.).
| #define _objfactory_check _Ret_opt_valid_ _Check_return_ |
| #define _objfactory_guaranteed _Ret_valid_ |
| #define _objinit_guaranteed _Post_equal_to_(true) |
| #define objInstCreate | ( | clsname | ) | (clsname*)_objInstCreate(&objClassInfoName(clsname)) |
ClassName *objInstCreate(ClassName)
Allocate and initialize an object instance
Allocates memory for an object instance and sets up the base ObjInst fields. The instance is returned with a reference count of 1. This function does NOT call the class's init() callback - that must be done separately via objInstInit().
Only call from factory functions!
Example usage in a factory function:
| clsname | Class name |
| #define objInstInit | ( | inst | ) | _objInstInit(objInstBase(inst), (inst)->_clsinfo) |
bool objInstInit(ClassType *inst)
Call initialization callbacks for the object's class hierarchy
Recursively calls init() callbacks starting from the root parent class down to the object's actual class. Must be called at the end of factory functions, after setting up per-instance data but before returning to the caller.
If any init() returns false, construction must abort and the factory should clean up and return NULL.
| inst | Object instance to initialize |
| intptr objDefaultCmp | ( | void * | self, |
| void * | other, | ||
| uint32 | flags | ||
| ) |
Default comparison function for Sortable interface
Provides a generic comparison by comparing the raw bytes of object instances after the ObjInst header. First compares instance sizes, then performs memcmp on the data.
Use this as a fallback when a class implements Sortable but doesn't need custom comparison logic. For classes with pointers or complex data, implement a custom comparison function instead.
| self | First object to compare |
| other | Second object to compare |
| flags | Comparison flags (currently unused) |
| uint32 objDefaultHash | ( | void * | self, |
| uint32 | flags | ||
| ) |
Default hash function for Hashable interface
Provides a generic hash by running MurmurHash3 over the raw bytes of the object instance after the ObjInst header.
Use this as a fallback when a class implements Hashable but doesn't need custom hash logic. For classes with pointers or complex data, implement a custom hash function instead.
| self | Object to hash |
| flags | Hash flags (currently unused) |