Go to the source code of this file.
|
| #define | DEFINE_SET_TYPE(typ, inner) |
| | Defines a set type containing an array of the specified inner type.
|
| |
| #define | DEFINE_SET_FREE_STATIC(typ) |
| | Defines a static function to free a set of the specified type.
|
| |
| #define | DEFINE_SET_ALLOC_STATIC(typ) |
| | Defines a static function to allocate a set of the specified type and count of inner items.
|
| |
| #define | DEFINE_SET_FOR_EACH_STATIC(typ) |
| | Defines a static function to iterate over each item in a set of the provided type, invoking the specified function on each contained item.
|
| |
| #define | SET_AT(name, index) |
| | Safely retrieves a pointer to the item at the specified index in the set. If the set is NULL, the items pointer is NULL, or the index is out of bounds, NULL is returned.
|
| |
◆ DEFINE_SET_ALLOC_STATIC
| #define DEFINE_SET_ALLOC_STATIC |
( |
|
typ | ) |
|
Value: static typ* typ##_alloc(int count) { \
void* items = NULL; \
if (count > 0) { \
items = je_calloc(count, sizeof(typ##_inner_item)); \
if (!items) return NULL; \
} \
typ* set = je_malloc(sizeof(typ)); \
if (!set) { \
je_free(items); \
return NULL; \
} \
set->count = count; \
set->items = items; \
return set; \
}
Defines a static function to allocate a set of the specified type and count of inner items.
- Parameters
-
| typ | The name of the set type |
| inner | The inner item type contained in the set. If the count is less than or equal to zero, the items pointer will be set to NULL but a set will still be allocated and returned. |
◆ DEFINE_SET_FOR_EACH_STATIC
| #define DEFINE_SET_FOR_EACH_STATIC |
( |
|
typ | ) |
|
Value: static void typ##_for_each(typ* set, void (*func)(typ##_inner_item*)) { \
for (int i = 0; set && set->items && i < set->count; i++) \
func(&set->items[i]); \
}
Defines a static function to iterate over each item in a set of the provided type, invoking the specified function on each contained item.
- Parameters
-
| typ | The name of the set type |
◆ DEFINE_SET_FREE_STATIC
| #define DEFINE_SET_FREE_STATIC |
( |
|
typ | ) |
|
Value: static void typ##_free(typ* set) { \
if (!set) return; \
je_free(set->items); \
je_free(set); \
}
Defines a static function to free a set of the specified type.
- Parameters
-
| typ | The name of the set type |
◆ DEFINE_SET_TYPE
| #define DEFINE_SET_TYPE |
( |
|
typ, |
|
|
|
inner |
|
) |
| |
Value: typedef inner typ##_inner_item; \
typedef struct { \
int count; \
typ##_inner_item* items; \
} typ;
Defines a set type containing an array of the specified inner type.
- Parameters
-
| typ | The name of the set type to define |
| inner | The inner item type contained in the set |
◆ SET_AT
| #define SET_AT |
( |
|
name, |
|
|
|
index |
|
) |
| |
Value: (name != NULL && name->items != NULL && index >= 0 && index < name->count \
? &(name)->items[index] \
: NULL)
Safely retrieves a pointer to the item at the specified index in the set. If the set is NULL, the items pointer is NULL, or the index is out of bounds, NULL is returned.
- Parameters
-
| name | The name of the set variable |
| index | The index of the item to retrieve |