|
CX Framework
Cross-platform C utility framework
|
Provides a unified foreach macro for iterating over various container types and iterable objects. The macro expands to type-specific iteration code while presenting a consistent interface.
The foreach macro adapts to different container types, automatically handling iterator initialization, validity checking, advancement, and cleanup. The syntax varies by container type to accommodate different iteration patterns.
Iterates over elements in a dynamic array with direct indexed access. Elements are copied by assignment (shallow copy), allowing iteration over value types without pointers.
Syntax:
Parameters:
index - int32 iteration variable (0 to size-1)ElementType - Type of elements stored in the array (can be value or pointer type)element - Variable to receive each element (copied by assignment)array - The sarray to iterate (by value, not pointer)Examples:
Iterates over all entries in a hash table in insertion order. CX hashtables preserve the order in which entries were added.
Syntax:
Parameters:
iterator - htiter variable for the iteration statetable - The hashtable to iterateAccessing Values: Use htiKey(type, iterator) and htiVal(type, iterator) to copy entries from the table, or use htiKeyPtr(type, iterator) and htiValPtr(type, iterator) to get direct pointers to the stored keys and values without copying:
Iterates over chunks (runs) of contiguous bytes in a string. This efficiently handles both simple strings (single chunk) and rope strings (multiple chunks).
Syntax:
Parameters:
iterator - striter variable for the iteration statestr - The string to iterateIterator Fields:
iterator.bytes - Pointer to current run of bytesiterator.len - Length of current run in bytesiterator.off - Byte offset from string startExample:
Iterates over directory entries in a VFS, optionally matching a search pattern.
Syntax:
Parameters:
iterator - FSSearchIter variable for the iteration statevfs - VFS instance to search withinpath - Directory path to searchpattern - Wildcard pattern (e.g., "*.txt") or NULL for all entriestypefilter - Entry type filter (FS_File, FS_Directory, or 0 for all)stat - bool indicating whether to populate stat informationIterator Fields:
iterator.name - Filename (string, valid until next iteration)iterator.type - Entry type (FS_File or FS_Directory)iterator.stat - File metadata (if stat parameter was true)Example:
Iterates over key-value pairs in an SSDTree node with automatic locking. The iteration occurs within a locked transaction for thread safety.
Syntax:
Parameters:
iterator - SSDIterator* variable (managed internally)index - int32 variable to receive entry indexkey - strref variable to receive entry keyvalue - stvar* variable to receive entry valuenode - The SSDNode to iterateExample:
Note: The node is automatically locked for the duration of the iteration.
Iterates over objects implementing the Iterable interface, which provides an Iterator object for traversal.
Syntax:
Parameters:
iterator - Iterator pointer variableIteratorType - Type of the iterator classobj - Object implementing the Iterable interfaceExample:
Note: The iterator is automatically released when the loop exits.