|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | STypeInfo |
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) |
| typedef bool(* | stSerializeFunc) (stype st, stgeneric val, SerWriter *w) |
| typedef bool(* | stDeserializeFunc) (stype st, stgeneric *val, SerReader *r) |
| typedef struct STypeInfo | STypeInfo |
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 bool(* stDeserializeFunc) (stype st, stgeneric *val, SerReader *r) |
Deserialize a value of this type from a serialization backend.
The counterpart to stSerializeFunc; see its notes on why this pair is format-agnostic. Any existing value at val is overwritten, not destroyed — the caller is responsible for handing over an uninitialized or already-cleared slot.
| st | Type descriptor of the value |
| val | Receives the value read |
| r | Backend to read from |
| 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:
|
Serialize a value of this type to a serialization backend.
Optional, and format-agnostic: the implementation decomposes the value into abstract data-model nodes (serWrite*, serArrBegin, ...) and the backend decides what those become on the wire. A type never asks which format it is being written to; where it genuinely must adapt, it queries a capability via serWriterCaps().
Built-in types leave this NULL — the traverser in cx/serialize/sertraverse.c handles them from its switch over STypeId_*. Only custom types (STCLASS_USER, custom opaque) need to supply one, and the single implementation serves every format.
| st | Type descriptor of the value |
| val | Value to write |
| w | Backend to write to |
Type descriptor for all runtime types in the stype system.
Each type has exactly one canonical const STypeInfo in static storage. stype is const STypeInfo* - two type values are equal if and only if they point to the same canonical descriptor (use stEq() to compare, which handles Temporary canonicalization).
Built-in type descriptors are declared as extern const STypeInfo _sti_name and accessed via stType(name) / stTypeInfo(name). Custom types are defined at file scope with stDefine(name) { ... } and declared in headers with stDeclare(name).