This commit is contained in:
2025-12-14 00:38:55 +00:00
parent 217382b3cb
commit e9aebeccbf

View File

@@ -50,41 +50,41 @@ BEGIN_C_LINKAGE
\
return (TYPE *)(header + 1); \
}())
#define wapp_array_pop(TYPE, ARRAY_PTR) \
(ARRAY_PTR != NULL && _array_count((u8 *)ARRAY_PTR, sizeof(TYPE)) > 0 ? \
*((TYPE *)_array_pop((u8 *)ARRAY_PTR, sizeof(TYPE))) : \
TYPE{} \
#define wapp_array_pop(TYPE, ARRAY_PTR) \
(ARRAY_PTR != NULL && _array_count((u8 *)ARRAY_PTR, sizeof(TYPE)) > 0 ? \
*((TYPE *)_array_pop((u8 *)ARRAY_PTR, sizeof(TYPE))) : \
TYPE{} \
)
#else
#define _stack_array(TYPE, SIZE) struct { ArrayHeader header; TYPE items[SIZE]; }
#define wapp_array(TYPE, ...) \
(TYPE *)( \
(_stack_array(TYPE, _calc_array_capacity(TYPE, __VA_ARGS__))){ \
.header = { \
.magic = WAPP_ARRAY_MAGIC, \
.count = _calc_array_count(TYPE, __VA_ARGS__), \
.capacity = _calc_array_capacity(TYPE, __VA_ARGS__), \
.item_size = sizeof(TYPE), \
}, \
.items = {__VA_ARGS__}, \
}.items \
#define wapp_array(TYPE, ...) \
(TYPE *)( \
(_stack_array(TYPE, _calc_array_capacity(TYPE, __VA_ARGS__))){ \
.header = { \
.magic = WAPP_ARRAY_MAGIC, \
.count = _calc_array_count(TYPE, __VA_ARGS__), \
.capacity = _calc_array_capacity(TYPE, __VA_ARGS__), \
.item_size = sizeof(TYPE), \
}, \
.items = {__VA_ARGS__}, \
}.items \
)
#define wapp_array_with_capacity(TYPE, CAPACITY) \
(TYPE *)( \
(_stack_array(TYPE, CAPACITY)){ \
.header = { \
.magic = WAPP_ARRAY_MAGIC, \
.count = 0, \
.capacity = CAPACITY, \
.item_size = sizeof(TYPE), \
}, \
.items = {0}, \
}.items \
#define wapp_array_with_capacity(TYPE, CAPACITY) \
(TYPE *)( \
(_stack_array(TYPE, CAPACITY)){ \
.header = { \
.magic = WAPP_ARRAY_MAGIC, \
.count = 0, \
.capacity = CAPACITY, \
.item_size = sizeof(TYPE), \
}, \
.items = {0}, \
}.items \
)
#define wapp_array_pop(TYPE, ARRAY_PTR) \
(ARRAY_PTR != NULL && _array_count((u8 *)ARRAY_PTR, sizeof(TYPE)) > 0 ? \
*((TYPE *)_array_pop((u8 *)ARRAY_PTR, sizeof(TYPE))) : \
(TYPE){0} \
#define wapp_array_pop(TYPE, ARRAY_PTR) \
(ARRAY_PTR != NULL && _array_count((u8 *)ARRAY_PTR, sizeof(TYPE)) > 0 ? \
*((TYPE *)_array_pop((u8 *)ARRAY_PTR, sizeof(TYPE))) : \
(TYPE){0} \
)
#endif // !WAPP_PLATFORM_CPP