CObject
|
Data Structures | |
struct | CClass |
First variables in every object's memory allocation. More... | |
struct | CObject |
Base class. More... | |
struct | CInterface |
Base interface. More... | |
Functions | |
void * | CObjectCast_ (void *super_reference, const char *file_name, int line_num) |
void | CVTable (void *self, const void *vtable) |
const void * | CGetVTable (void *self_) |
void | CInterface::CInterface (void *self, void *iface, const void *vtable) |
Methods used by all classes to implement object oriented back bone.
const void* CGetVTable | ( | void * | self_ | ) |
This is used to get a pointer to the objects vtable. When calling a virtual method, this should always be used over _VTable_Key( ). For example, say we have a class inheritance chain like such: struct Square :: struct Point :: struct CObject Due to polymorphism, having a reference to an object of type struct Point does not guarentee that objects virtual table is given by Point_VTable_Key( ). We might have an instance of struct Square, and the correct virtual table is Square_VTable_Key( ). There is no way of knowing. Using this method guarentees we will get a pointer to the correct virtual table.
This method should only be used in a wrapper function for calling virtual methods. For example, say struct Point has a method struct Point::move.
Then, application code simply calls Point_Move, which has the more cumbersome code for actually finding and calling the virtual method.
This method works on references to objects and interfaces.
self_ | A pointer to the object whos virtual table is needed. |
void CInterface | ( | void * | self, |
void * | iface, | ||
const void * | vtable | ||
) |
This is the constructor for interfaces. All implementing classes must call this in their constructor AFTER mapping their virtual table with CVTable( ). This method will setup the interfaces data such that one can back track from the interface reference, param iface, to the object reference, param self, and find the offset into the class' virtual table where the implemented interface methods are located.
self | This is a pointer to the object whose class is implementing the interface. |
iface | This is a pointer to the interface instance within the classes declaration. For example, if param self is of type struct A, and struct A implements interface struct I, then this parameter would be a pointer to A::I. |
vtable | This is a pointer to the interfaces virtual table. For example, say, param self is of type struct A, which implements interface struct I, and we are calling this constructor to construct A::I. struct A's vtable, struct A_VT, will contain an instance of struct I's vtable, struct I_VT. This would be a pointer to A_VT::I_VT. |
void* CObjectCast_ | ( | void * | super_reference, |
const char * | file_name, | ||
int | line_num | ||
) |
This is used to cast an object. It must only be used in virtual method definitions. The usage would be this, say we are overriding the destructor, the destructors declaration looks like this void (*)( struct CObject* ). However, we are overriding the method in class struct ArrayList. We know we the input to the method is from an object of that type. This method will cast the input pointer to that type.
The method has a macro wrapper to simply its call signature, CCast( ), which only takes one input, the object refernce.
void* CCast( void* );
super_reference | Reference to cast. |
file_name | Name of the file casting is done in - for debugging. |
line_num | Line number in the file casting is done - for debugging. |
void CVTable | ( | void * | self, |
const void * | vtable | ||
) |
Used within a classes constructor to give the object instance the location of the class' virtual table. This must always be called after constructing the super class and before constructing any interfaces. For example,
self | The object which needs a virtual table reference. |
vtable | The pointer to the class' virtual table. |