|
CX Framework
Cross-platform C utility framework
|
Typedefs | |
| typedef void(* | stDtorFunc) (stype st, stgeneric *gen, flags_t flags) |
| typedef intptr(* | stCmpFunc) (stype st, stgeneric gen1, stgeneric gen2, flags_t flags) |
| typedef uint32(* | stHashFunc) (stype st, stgeneric gen, flags_t flags) |
| typedef void(* | stCopyFunc) (stype st, _stCopyDest_Anno_(st) stgeneric *dest, stgeneric src, flags_t flags) |
| typedef bool(* | stConvertFunc) (stype destst, _stCopyDest_Anno_(destst) stgeneric *dest, stype srcst, stgeneric src, flags_t flags) |
Function pointers for runtime-dispatched operations on typed values. These enable generic algorithms to work with any type that provides the required operations.
IMPORTANT: These are LOW LEVEL operations. In particular, stCopy and stConvert OVERWRITE the destination without checking. This allows them to efficiently initialize uninitialized memory, but caution is required with object types to avoid leaking memory.
Example leak scenario:
For managed types (strings, objects, containers), use their specific APIs for assignment operations. Use stype operations primarily for:
| typedef intptr(* stCmpFunc) (stype st, stgeneric gen1, stgeneric gen2, flags_t flags) |
intptr stCmpFunc(stype st, stgeneric gen1, stgeneric gen2, [flags])
Comparison function returning ordering of two values.
| st | Type descriptor for both values |
| gen1 | First value |
| gen2 | Second value |
| flags | Operation flags:
|
| typedef bool(* stConvertFunc) (stype destst, _stCopyDest_Anno_(destst) stgeneric *dest, stype srcst, stgeneric src, flags_t flags) |
bool stConvertFunc(stype destst, stgeneric* dest, stype srcst, stgeneric src, [flags])
Type conversion function attempting to convert from one type to another.
WARNING: Overwrites destination without destroying existing value.
May fail if conversion is not possible, out of range, or would lose precision (depending on flags). The source type is responsible for implementing conversions to other types.
| destst | Destination type descriptor |
| dest | Pointer to destination |
| srcst | Source type descriptor |
| src | Source value |
| flags | Conversion flags:
|
| typedef void(* stCopyFunc) (stype st, _stCopyDest_Anno_(st) stgeneric *dest, stgeneric src, flags_t flags) |
void stCopyFunc(stype st, stgeneric* dest, stgeneric src, [flags])
Deep copy function that duplicates a value.
WARNING: Overwrites destination without destroying existing value. Use only on uninitialized memory or after calling stDestroy on dest.
For reference-counted types (strings, objects), increments the reference count. For value types, performs a bitwise copy. For complex types, may perform deep duplication.
| st | Type descriptor |
| dest | Pointer to destination (must be valid for PassPtr types) |
| src | Source value to copy |
| flags | Optional operation flags |
| typedef void(* stDtorFunc) (stype st, stgeneric *gen, flags_t flags) |
void stDtorFunc(stype st, stgeneric* gen, [flags])
Destructor function for releasing resources owned by a typed value.
Called when a value is being removed from a container or otherwise destroyed. Responsible for freeing memory, decrementing reference counts, and any other cleanup required by the type.
| st | Type descriptor for the value |
| gen | Pointer to the value container (invalidated after call) |
| flags | Optional operation flags |
| typedef uint32(* stHashFunc) (stype st, stgeneric gen, flags_t flags) |
uint32 stHashFunc(stype st, stgeneric gen, [flags])
Hash function computing a 32-bit hash value for use in hash tables.
Must satisfy: if stCmp(a,b)==0, then stHash(a)==stHash(b)
| st | Type descriptor |
| gen | Value to hash |
| flags | Operation flags:
|