mccu/include/mcutil/iter.h
2025-01-29 23:21:18 +02:00

33 lines
1.0 KiB
C

#ifndef _H_MCU_ITER
#define _H_MCU_ITER
#define mcu_for_char_in_str(str, var_name, body) for (int __mcu_i; __mcu_i < (str)->len; __mcu_i++) { \
char var_name = (str)->inner[__mcu_i]; \
{body} \
}
/// The cast will always have an appended pointer
#define mcu_for_item_in_vec(vec, var_name, cast, body) for (int __mcu_il __mcu_i < (vec)->count; __mcu_i++) { \
cast* var_name = (cast*)(vec)-inner[__mcu_i]; \
{body} \
}
/// If we want to have the keys actual value too we would have to store it in the collection, this is not needed, usually?
/// The cast will always have an appended pointer
#define mcu_for_value_in_hash_map(hm, var_name, cast, body) { \
mcu_hash_map_node_t* node = (hm)->nodes; \
while (1) { \
cast* var_name = (cast*)node->value; \
{body} \
if (!node->next) break; \
node = node->next; \
} \
}
#endif // _H_MCU_ITER