|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | ObjClassInfo |
| struct | ClassSet |
| struct | ObjInst |
| struct | ObjInst_WeakRef |
Macros | |
| #define | objClassInfoName(cname) cname##_clsinfo |
| #define | Weak(clsname) clsname##_WeakRef |
| #define | ObjInst(inst) ((ObjInst*)(unused_noeval(&((inst)->_is_ObjInst)), (inst))) |
| #define | ObjInst_WeakRef(ref) ((ObjInst_WeakRef*)(unused_noeval(&((ref)->_is_ObjInst_WeakRef)), (ref))) |
| #define | objInstBase(inst) ObjInst(inst) |
| #define | objWeakRefBase(ref) ObjInst_WeakRef(ref) |
| #define | objClsInfo(inst) (inst->_clsinfo) |
| #define | objAcquire(inst) (_objAcquire(objInstBase(inst)), (inst)) |
| #define | objRelease(pinst) (unused_noeval(&((*(pinst))->_is_ObjInst)), _objRelease((ObjInst**)(pinst))) |
| #define | objClassIf(clsname, ifname) ((ifname*)_objClassIf(&objClassInfoName(clsname), objIfBase(&objIfTmplName(ifname)))) |
| #define | objInstIf(inst, ifname) ((ifname*)_objInstIf(objInstBase(inst), objIfBase(&objIfTmplName(ifname)))) |
| #define | objGetWeak(clsname, inst) ((Weak(clsname)*)_objGetWeak((ObjInst*)clsname(inst))) |
| #define | objCloneWeak(ref) (_objCloneWeak(objWeakRefBase(ref))) |
| #define | objDestroyWeak(pref) (unused_noeval(&((*(pref))->_is_ObjInst_WeakRef)), _objDestroyWeak((ObjInst_WeakRef**)(pref))) |
| #define | objAcquireFromWeak(clsname, ref) ((clsname*)_objAcquireFromWeak((ObjInst_WeakRef*)Weak(clsname)(ref))) |
| #define | objDynCast(clsname, inst) ((clsname*)_objDynCast(objInstBase(inst), &objClassInfoName(clsname))) |
| #define | objAcquireFromWeakDyn(clsname, ref) ((clsname*)_objAcquireFromWeakDyn(objWeakRefBase(ref), &objClassInfoName(clsname))) |
Typedefs | |
| typedef struct ObjClassInfo | ObjClassInfo |
| typedef struct ObjInst | ObjInst |
| typedef struct ClassSet | ClassSet |
| typedef struct ObjInst_WeakRef | ObjInst_WeakRef |
Functions | |
| ObjClassInfo * | classSetFind (const ClassSet *cs, strref name) |
| void | _objDestroy (ObjInst *inst) |
Classes are the concrete types in the object system that store per-instance data and implement interfaces. Each class has associated runtime metadata (ObjClassInfo) that describes its structure, inheritance relationships, and interface implementations.
Classes support:
Classes are defined in .cxh files and the build system generates the boilerplate code.
| #define objAcquire | ( | inst | ) | (_objAcquire(objInstBase(inst)), (inst)) |
ClassType *objAcquire(ClassType *inst)
Increment the reference count of an object
Use this when storing an additional reference to an object. Each objAcquire() must be paired with a corresponding objRelease(). Does nothing if inst is NULL.
Example:
| inst | Pointer to object instance (may be NULL) |
Definition at line 234 of file objclass.h.
| #define objAcquireFromWeak | ( | clsname, | |
| ref | |||
| ) | ((clsname*)_objAcquireFromWeak((ObjInst_WeakRef*)Weak(clsname)(ref))) |
ClassName *objAcquireFromWeak(ClassName, Weak(ClassName) *ref)
Attempt to acquire the object referenced by a weak reference
If the object still exists, increments its reference count and returns it. If the object has been destroyed, returns NULL. The caller is responsible for calling objRelease() on the returned object.
Example:
| clsname | Class name for type casting |
| ref | Weak reference (may be NULL) |
Definition at line 366 of file objclass.h.
| #define objAcquireFromWeakDyn | ( | clsname, | |
| ref | |||
| ) | ((clsname*)_objAcquireFromWeakDyn(objWeakRefBase(ref), &objClassInfoName(clsname))) |
ClassName *objAcquireFromWeakDyn(ClassName, Weak(BaseClass) *ref)
Acquire from weak reference with runtime type checking
Combines objAcquireFromWeak() and objDynCast(). Attempts to acquire the object and verify it's compatible with the requested class type. Returns NULL if the object was destroyed or is not compatible with the target class.
| clsname | Class name to cast to |
| ref | Weak reference (may be NULL) |
Definition at line 405 of file objclass.h.
| #define objClassIf | ( | clsname, | |
| ifname | |||
| ) | ((ifname*)_objClassIf(&objClassInfoName(clsname), objIfBase(&objIfTmplName(ifname)))) |
InterfaceType *objClassIf(ClassName, InterfaceName)
Get interface implementation from a class (without instance)
Queries whether a class implements a specific interface and returns the populated interface structure if it does. Useful for accessing interface methods when you don't have an instance.
| clsname | Class name (e.g., Document) |
| ifname | Interface name (e.g., Printable) |
Definition at line 272 of file objclass.h.
| #define objClassInfoName | ( | cname | ) | cname##_clsinfo |
Construct class info variable name from class name
| cname | Class name |
Definition at line 96 of file objclass.h.
| #define objCloneWeak | ( | ref | ) | (_objCloneWeak(objWeakRefBase(ref))) |
WeakRefType *objCloneWeak(WeakRefType *ref)
Increment the reference count of a weak reference
Creates an additional reference to the same weak reference object. Each objCloneWeak() must be paired with objDestroyWeak().
| ref | Weak reference to clone (may be NULL) |
Definition at line 322 of file objclass.h.
| #define objClsInfo | ( | inst | ) | (inst->_clsinfo) |
ObjClassInfo *objClsInfo(ClassType *inst)
Get the class metadata for an object instance
| inst | Pointer to any class instance |
Definition at line 203 of file objclass.h.
| #define objDestroyWeak | ( | pref | ) | (unused_noeval(&((*(pref))->_is_ObjInst_WeakRef)), _objDestroyWeak((ObjInst_WeakRef**)(pref))) |
void objDestroyWeak(WeakRefType **pref)
Release a weak reference
Decrements the weak reference's own reference count. When the count reaches zero, the weak reference object itself is destroyed. The pointer is set to NULL.
Example:
| pref | Pointer to weak reference pointer (automatically set to NULL) |
Definition at line 340 of file objclass.h.
| #define objDynCast | ( | clsname, | |
| inst | |||
| ) | ((clsname*)_objDynCast(objInstBase(inst), &objClassInfoName(clsname))) |
ClassName *objDynCast(ClassName, ClassType *inst)
Safely cast an object to a different class type with runtime checking
Checks if the object is an instance of the specified class or any of its subclasses. Returns the object cast to the requested type if compatible, NULL otherwise.
Example:
| clsname | Class name to cast to |
| inst | Object instance to cast (may be NULL) |
Definition at line 389 of file objclass.h.
Weak(ClassName) *objGetWeak(ClassName, ClassType *inst)
Get a weak reference to an object
Creates a weak reference if one doesn't exist, or returns the existing weak reference. Weak references allow observing an object without owning it. The returned weak reference has its own reference count and must be destroyed with objDestroyWeak().
| clsname | Class name for type casting |
| inst | Object instance |
Definition at line 310 of file objclass.h.
| #define ObjInst | ( | inst | ) | ((ObjInst*)(unused_noeval(&((inst)->_is_ObjInst)), (inst))) |
ObjInst *ObjInst(ClassType *inst)
Cast a class instance pointer to base ObjInst type
| inst | Pointer to any class instance |
Definition at line 170 of file objclass.h.
| #define ObjInst_WeakRef | ( | ref | ) | ((ObjInst_WeakRef*)(unused_noeval(&((ref)->_is_ObjInst_WeakRef)), (ref))) |
ObjInst_WeakRef *ObjInst_WeakRef(WeakRefType *ref)
Cast a weak reference pointer to base ObjInst_WeakRef type
| ref | Pointer to any weak reference |
Definition at line 178 of file objclass.h.
| #define objInstBase | ( | inst | ) | ObjInst(inst) |
ObjInst *objInstBase(ClassType *inst)
Alias for ObjInst() cast
| inst | Pointer to any class instance |
Definition at line 187 of file objclass.h.
| #define objInstIf | ( | inst, | |
| ifname | |||
| ) | ((ifname*)_objInstIf(objInstBase(inst), objIfBase(&objIfTmplName(ifname)))) |
InterfaceType *objInstIf(ClassType *inst, InterfaceName)
Query an object for a specific interface implementation
Returns the populated interface if the object implements it, NULL otherwise. Always check the return value before using the interface to ensure the object supports it.
Example:
| inst | Object instance (may be NULL) |
| ifname | Interface name |
Definition at line 295 of file objclass.h.
| #define objRelease | ( | pinst | ) | (unused_noeval(&((*(pinst))->_is_ObjInst)), _objRelease((ObjInst**)(pinst))) |
void objRelease(ClassType **pinst)
Decrement reference count and destroy object if it reaches zero
This is the primary way to release ownership of an object. The pointer is automatically set to NULL after the call. If the reference count reaches zero, the object's destroy() callback (if any) is called, followed by memory deallocation. Does nothing if *pinst is NULL.
CRITICAL: Pass a pointer-to-pointer, not a pointer. The object pointer will be set to NULL.
Example:
| pinst | Pointer to object pointer (automatically set to NULL) |
Definition at line 257 of file objclass.h.
| #define objWeakRefBase | ( | ref | ) | ObjInst_WeakRef(ref) |
ObjInst_WeakRef *objWeakRefBase(WeakRefType *ref)
Alias for ObjInst_WeakRef() cast
| ref | Pointer to any weak reference |
Definition at line 195 of file objclass.h.
| #define Weak | ( | clsname | ) | clsname##_WeakRef |
Construct weak reference type name from class name
| clsname | Class name |
Definition at line 162 of file objclass.h.
A named set of classes: the declared vocabulary of a dynamic object slot
This is the class counterpart of StructSet. A member declared object[SomeSet] holds an instance of any class in the set, and the set is what turns the wire name back into a class when the document is read — without the consumer having to register a resolver for it.
cxautogen emits one of these per classset declaration in a .cxh, with the entries sorted by wire name so the lookup is a binary search. Every class in a set must carry a wire name, which means it must be [serialize] or implement Serializable; cxautogen rejects the declaration otherwise, since a class with no name could never be resolved back.
| typedef struct ObjClassInfo ObjClassInfo |
Runtime metadata for a class
This structure contains all the information needed to manage a class at runtime, including its size, inheritance relationships, interface implementations, and lifecycle callbacks. One instance exists per class for the lifetime of the program.
The structure is divided into two sections:
Definition at line 31 of file objclass.h.
Base structure for all object instances
ObjInst is the implicit base class for all objects in the CX object system. Every class instance begins with these fields, allowing generic handling of objects regardless of their specific class type.
The structure uses a union trick with _is_ObjInst to enable compile-time type checking in macros while maintaining C compatibility.
Definition at line 32 of file objclass.h.
| typedef struct ObjInst_WeakRef ObjInst_WeakRef |
Weak reference structure
Allows observing an object without owning it. When the object is destroyed, the weak reference's _inst pointer is set to NULL, allowing safe detection of destruction. Multiple weak references can point to the same object.
| void _objDestroy | ( | ObjInst * | inst | ) |
Internal object destruction function - DO NOT CALL DIRECTLY!
This function is called internally when an object's reference count reaches zero. Always use objRelease() instead, which properly manages reference counting.
| ObjClassInfo * classSetFind | ( | const ClassSet * | cs, |
| strref | name | ||
| ) |
Looks up a class by its wire name in a ClassSet using binary search.
| cs | The ClassSet to search (must have entries sorted by name) |
| name | The class name to look up |
Note that membership is by exact class: a derived class does not satisfy a set that names only its base, because the set is the list of concrete types the slot may hold and reading one back constructs exactly the class the name resolves to.