CLibs
|
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Macros | |
#define | foreach_uni(TYPE, ITEM_NAME, INITIALIZER, ACCESSOR, SIZE) |
#define | foreach_arr(ITEM_TYPE, ITEM_NAME, ARRAY, COUNT) |
#define | foreach_str(ITEM_NAME, STRING) |
#define | foreach_ls(TYPE, ITEM_NAME, LIST) |
#define | foreach_set(ENTRY_NAME, SET) |
#define | foreach_que(ENTRY_NAME, QUEUE) |
#define foreach_arr | ( | ITEM_TYPE, | |
ITEM_NAME, | |||
ARRAY, | |||
COUNT ) |
Iterates over an array.
Stores each array member in a new variable (only visible in the scope of the foreach loop).
ITEM_TYPE | C-keyword (or typedef/…) of the type of the array items and the new variable |
ITEM_NAME | name of the new variable |
ARRAY | array of type TYPE[ COUNT ] |
COUNT | number of elements in array |
#define foreach_ls | ( | TYPE, | |
ITEM_NAME, | |||
LIST ) |
Iterates over a list.
Stores each list member in a new variable.
TYPE | type of the new variable and items in the list |
ITEM_NAME | name of the new variable |
LIST | a valid List * |
#define foreach_que | ( | ENTRY_NAME, | |
QUEUE ) |
Iterates over a queue.
"Retrieves" a const struct queue_node struct (see src/structs/queue.h); use queue_node_get_data() to retrieve data from the item
Example
QUEUE | valid struct fifo_queue * |
#define foreach_set | ( | ENTRY_NAME, | |
SET ) |
Iterates over a set.
Retrieves a const SetEnumeratedEntry struct (see src/structs/set.h); in short, SetEnumeratedEntry contains a field struct set_item *item with the desired data
SET | a valid Set * |
#define foreach_str | ( | ITEM_NAME, | |
STRING ) |
Iterates over a string.
Stores each character of the string in a new variable of type const char.
ITEM_NAME | name of the new variable |
STRING | string |
#define foreach_uni | ( | TYPE, | |
ITEM_NAME, | |||
INITIALIZER, | |||
ACCESSOR, | |||
SIZE ) |
Universal foreach macro
TYPE | type of the item |
ITEM_NAME | name of the variable created and assigned in the loop |
INITIALIZER | runs on the first pass through the loop |
ACCESSOR | runs every other time (index variable is foreach_index_ITEM_NAME) |
SIZE | number of elements in the structure |