|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | ObjIface |
Macros | |
| #define | objIfTmplName(iface) iface##_tmpl |
| #define | objIfImport(iface) extern iface objIfTmplName(iface) |
| #define | objIfCheck(iface) static_assert(((iface)->_implements, (iface)->_size, offsetof(*(iface), _parent) == offsetof(ObjIface, _parent)), "Not an interface") |
| #define | objIfBase(iface) ((ObjIface*)((iface)->_implements, (iface)->_parent, (iface)->_size, (iface))) |
Typedefs | |
| typedef struct ObjIface | ObjIface |
Interfaces define contracts that classes implement. An interface is a list of function pointers representing methods that fulfill a specific contract. Interfaces support inheritance, allowing child interfaces to extend parent interfaces.
The ObjIface structure serves dual purposes depending on context:
Template Form - The publicly declared master copy of an interface:
Implementation Form - A statically scoped instance used during class definition:
Example from a .cxh file:
This generates a template Printable_tmpl and implementation structures automatically.
| #define objIfBase | ( | iface | ) | ((ObjIface*)((iface)->_implements, (iface)->_parent, (iface)->_size, (iface))) |
ObjIface *objIfBase(InterfaceType *iface)
Cast an interface pointer to base ObjIface type
| iface | Pointer to any interface structure |
Definition at line 88 of file objiface.h.
| #define objIfCheck | ( | iface | ) | static_assert(((iface)->_implements, (iface)->_size, offsetof(*(iface), _parent) == offsetof(ObjIface, _parent)), "Not an interface") |
void objIfCheck(InterfaceType *iface)
Compile-time check that a pointer is to a valid interface structure
| iface | Pointer to interface structure to validate |
Definition at line 80 of file objiface.h.
| #define objIfImport | ( | iface | ) | extern iface objIfTmplName(iface) |
Import an external interface template declaration
| iface | Interface type name |
Definition at line 73 of file objiface.h.
| #define objIfTmplName | ( | iface | ) | iface##_tmpl |
Construct interface template name from interface type name
| iface | Interface type name (e.g., Printable) |
Definition at line 67 of file objiface.h.
Core interface structure
This structure has different interpretations based on context. See the Interfaces overview for detailed explanation of template vs implementation forms.
Definition at line 46 of file objiface.h.