|
CX Framework
Cross-platform C utility framework
|
Modules | |
| Keyed Variant Lookup | |
Data Structures | |
| struct | stvlist |
Macros | |
| #define | stvlInitSA(list, vararray) _stvlInitSA(list, (vararray).a) |
| #define | stvlNext(list, type, pvar) _stvlNext(list, stCheckedPtrArg(type, pvar)) |
| #define | stvlNextPtr(list) _stvlNextPtr(list, stType(ptr)) |
| #define | stvlNextObj(list, class) objDynCast(class, (ObjInst*)_stvlNextPtr(list, stType(object))) |
| #define | stvlAt(list, idx, type) (_stvlAt((list), (idx), stType(type)).st_##type) |
| #define | stvlAtPtr(list, idx) (_stvlAt((list), (idx), stType(ptr)).st_ptr) |
| #define | stvlAtObj(list, idx, class) objDynCast(class, (ObjInst*)_stvlAt((list), (idx), stType(object)).st_object) |
Typedefs | |
| typedef struct stvlist | stvlist |
Functions | |
| void | stvlInit (stvlist *list, int count, stvar *vars) |
| void | stvlRewind (stvlist *list) |
Iterator pattern for processing arrays of variants with type-safe extraction.
The variant list walker provides a cursor-based interface for sequentially extracting typed values from an array of variants, commonly used for implementing type-safe variadic functions.
Example usage pattern:
| #define stvlAt | ( | list, | |
| idx, | |||
| type | |||
| ) | (_stvlAt((list), (idx), stType(type)).st_##type) |
type stvlAt(stvlist *list, int idx, type)
Read a variant by position, without disturbing the walker.
Positions count from 0 and skip keyed variants, the same ones stvlNext() skips, so adding a keyed argument never shifts a positional one. The value is borrowed from the list: strings and objects read this way must not be destroyed or released. A type too large to fit in a variant, such as suid, comes back as a pointer to the stored value.
Use this where the position of each variant is fixed, such as the captured variables of a closure. A position that is out of range or holds a different type is a programming error, and yields zero. For optional arguments, use stvlNext(), which reports whether it found one.
| list | Pointer to list walker (not modified) |
| idx | Position among the unkeyed variants |
| type | Type of the variant at that position |
Example:
| #define stvlAtObj | ( | list, | |
| idx, | |||
| class | |||
| ) | objDynCast(class, (ObjInst*)_stvlAt((list), (idx), stType(object)).st_object) |
ClassName* stvlAtObj(stvlist *list, int idx, ClassName)
Read an object variant by position and dynamic-cast it. As stvlAt(); the reference is borrowed.
| list | Pointer to list walker (not modified) |
| idx | Position among the unkeyed variants |
| class | Target class name for dynamic cast |
| #define stvlAtPtr | ( | list, | |
| idx | |||
| ) | (_stvlAt((list), (idx), stType(ptr)).st_ptr) |
void* stvlAtPtr(stvlist *list, int idx)
Read a ptr variant by position. As stvlAt().
| list | Pointer to list walker (not modified) |
| idx | Position among the unkeyed variants |
| #define stvlInitSA | ( | list, | |
| vararray | |||
| ) | _stvlInitSA(list, (vararray).a) |
void stvlInitSA(stvlist *list, sa_stvar vararray)
Initialize variant list walker from an sarray of variants.
Sets up the list structure to iterate over a dynamic array (sarray) of variants. The count is extracted automatically from the array metadata.
| list | Pointer to list structure to initialize |
| vararray | Dynamic array of variants (sa_stvar or similar) |
Example:
| #define stvlNext | ( | list, | |
| type, | |||
| pvar | |||
| ) | _stvlNext(list, stCheckedPtrArg(type, pvar)) |
bool stvlNext(stvlist *list, type, type *pvar)
Extract next variant of specified type from list.
Searches forward from the current cursor position for the next variant matching the specified type. If found, copies the value to the output parameter, advances the cursor past that variant, and returns true. If no matching variant is found, returns false and leaves the cursor unchanged.
This allows flexible argument ordering in variadic functions where arguments can be provided in any order.
| list | Pointer to list walker |
| type | Type name to search for (e.g., int32, string) |
| pvar | Pointer to variable to receive the value |
Example:
| #define stvlNextObj | ( | list, | |
| class | |||
| ) | objDynCast(class, (ObjInst*)_stvlNextPtr(list, stType(object))) |
ClassName* stvlNextObj(stvlist *list, ClassName)
Extract next object variant from list with runtime type checking.
Searches for the next variant containing an object, performs a dynamic cast to the specified class type, advances the cursor, and returns the typed object pointer. Returns NULL if no compatible object is found.
| list | Pointer to list walker |
| class | Target class name for dynamic cast |
Example:
| #define stvlNextPtr | ( | list | ) | _stvlNextPtr(list, stType(ptr)) |
void* stvlNextPtr(stvlist *list)
Extract next pointer-type variant from list.
Searches for the next variant containing a generic pointer (ptr type), advances the cursor, and returns the pointer value. Returns NULL if no pointer variant is found.
| list | Pointer to list walker |
Example:
Variant list walker structure.
Maintains a cursor position for iterating through an array of variants. Initialized with stvlInit() or stvlInitSA(), then accessed with the various stvlNext*() functions.
void stvlInit(stvlist *list, int count, stvar *vars)
Initialize variant list walker from array and count.
Sets up the list structure to iterate over a raw array of variants, typically from a variadic function's argument list. Resets the cursor to the beginning.
| list | Pointer to list structure to initialize |
| count | Number of variants in array |
| vars | Pointer to variant array |
Example:
| void stvlRewind | ( | stvlist * | list | ) |
void stvlRewind(stvlist *list)
Reset list walker cursor to beginning.
Resets the cursor to position 0, allowing the same variant array to be walked multiple times or re-scanned for different argument combinations.
| list | Pointer to list walker to rewind |
Example: