|
CX Framework
Cross-platform C utility framework
|
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))) |
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 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: