CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Interfaces

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
 

Detailed Description

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:

interface Printable {
void print();
void println();
}
class Document implements Printable {
string content;
}

This generates a template Printable_tmpl and implementation structures automatically.

Macro Definition Documentation

◆ objIfBase

#define objIfBase (   iface)    ((ObjIface*)((iface)->_implements, (iface)->_parent, (iface)->_size, (iface)))

ObjIface *objIfBase(InterfaceType *iface)

Cast an interface pointer to base ObjIface type

Parameters
ifacePointer to any interface structure
Returns
Base ObjIface pointer (performs validation through comma operator)

Definition at line 88 of file objiface.h.

◆ objIfCheck

#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

Parameters
ifacePointer to interface structure to validate

Definition at line 80 of file objiface.h.

◆ objIfImport

#define objIfImport (   iface)    extern iface objIfTmplName(iface)

Import an external interface template declaration

Parameters
ifaceInterface type name
Returns
Expands to extern declaration for the interface template

Definition at line 73 of file objiface.h.

◆ objIfTmplName

#define objIfTmplName (   iface)    iface##_tmpl

Construct interface template name from interface type name

Parameters
ifaceInterface type name (e.g., Printable)
Returns
Expands to the template variable name (e.g., Printable_tmpl)

Definition at line 67 of file objiface.h.

Typedef Documentation

◆ ObjIface

typedef struct ObjIface ObjIface

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.