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

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)
 

Detailed Description

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:

string s1 = _S"original";
string s2 = _S"new";
stCopy(string, &s1, s2); // LEAKS "original" - should use strDup!
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392
#define stCopy(type, pdest, src,...)
Definition stype.h:1445

For managed types (strings, objects, containers), use their specific APIs for assignment operations. Use stype operations primarily for:

Typedef Documentation

◆ stCmpFunc

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.

Parameters
stType descriptor for both values
gen1First value
gen2Second value
flagsOperation flags:
  • ST_CaseInsensitive: Perform case-insensitive comparison (if applicable)
  • ST_Equality: Caller only needs equality (0/non-zero), not ordering
Returns
Negative if gen1 < gen2, zero if equal, positive if gen1 > gen2

Definition at line 1200 of file stype.h.

◆ stConvertFunc

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.

Parameters
deststDestination type descriptor
destPointer to destination
srcstSource type descriptor
srcSource value
flagsConversion flags:
  • ST_Overflow: Allow overflow/underflow (no range checking)
  • ST_Lossless: Fail if conversion loses precision
Returns
true if conversion succeeded, false otherwise

Definition at line 1252 of file stype.h.

◆ stCopyFunc

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.

Parameters
stType descriptor
destPointer to destination (must be valid for PassPtr types)
srcSource value to copy
flagsOptional operation flags

Definition at line 1230 of file stype.h.

◆ stDtorFunc

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.

Parameters
stType descriptor for the value
genPointer to the value container (invalidated after call)
flagsOptional operation flags

Definition at line 1187 of file stype.h.

◆ stHashFunc

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)

Parameters
stType descriptor
genValue to hash
flagsOperation flags:
  • ST_CaseInsensitive: Case-insensitive hash (if applicable)
Returns
32-bit hash value

Definition at line 1213 of file stype.h.