Rename Array to GenericArray to avoid name clashes
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#define _offset_pointer(PTR, OFFSET) ((void *)((uptr)(PTR) + (OFFSET)))
|
||||
|
||||
void *_array_get(Array *array, u64 index, u64 item_size) {
|
||||
void *_array_get(GenericArray *array, u64 index, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -18,12 +18,12 @@ void *_array_get(Array *array, u64 index, u64 item_size) {
|
||||
return _offset_pointer(array->items, array->item_size * index);
|
||||
}
|
||||
|
||||
void _array_set(Array *array, u64 index, void *value, u64 item_size) {
|
||||
void _array_set(GenericArray *array, u64 index, void *value, u64 item_size) {
|
||||
void *item = _array_get(array, index, item_size);
|
||||
memcpy(item, value, array->item_size);
|
||||
}
|
||||
|
||||
void _array_append_capped(Array *array, void *value, u64 item_size) {
|
||||
void _array_append_capped(GenericArray *array, void *value, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -34,7 +34,7 @@ void _array_append_capped(Array *array, void *value, u64 item_size) {
|
||||
_array_set(array, index, value, item_size);
|
||||
}
|
||||
|
||||
void _array_extend_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
void _array_extend_capped(GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
@@ -48,7 +48,7 @@ void _array_extend_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
dst->count += copy_count;
|
||||
}
|
||||
|
||||
void _array_copy_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
void _array_copy_capped(GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
@@ -60,16 +60,16 @@ void _array_copy_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
dst->count = copy_count;
|
||||
}
|
||||
|
||||
Array *_array_append_alloc(const Allocator *allocator, Array *array, void *value, u64 item_size) {
|
||||
GenericArray *_array_append_alloc(const Allocator *allocator, GenericArray *array, void *value, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
|
||||
Array *output = array;
|
||||
GenericArray *output = array;
|
||||
|
||||
if (array->count >= array->capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2);
|
||||
output = (Array *)_array_alloc_capacity(allocator, new_capacity, array->item_size);
|
||||
output = (GenericArray *)_array_alloc_capacity(allocator, new_capacity, array->item_size);
|
||||
if (!output) {
|
||||
output = array;
|
||||
goto RETURN_ARRAY_APPEND_ALLOC;
|
||||
@@ -83,18 +83,18 @@ RETURN_ARRAY_APPEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
Array *_array_extend_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size) {
|
||||
GenericArray *_array_extend_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
|
||||
|
||||
Array *output = dst;
|
||||
GenericArray *output = dst;
|
||||
|
||||
u64 remaining_capacity = dst->capacity - dst->count;
|
||||
if (src->count >= remaining_capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2);
|
||||
output = (Array *)_array_alloc_capacity(allocator, new_capacity, dst->item_size);
|
||||
output = (GenericArray *)_array_alloc_capacity(allocator, new_capacity, dst->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
goto RETURN_ARRAY_EXTEND_ALLOC;
|
||||
@@ -108,17 +108,17 @@ RETURN_ARRAY_EXTEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
Array *_array_copy_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size) {
|
||||
GenericArray *_array_copy_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
|
||||
|
||||
Array *output = dst;
|
||||
GenericArray *output = dst;
|
||||
|
||||
if (src->count >= dst->capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2);
|
||||
output = (Array *)_array_alloc_capacity(allocator, new_capacity, src->item_size);
|
||||
output = (GenericArray *)_array_alloc_capacity(allocator, new_capacity, src->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
goto RETURN_ARRAY_COPY_ALLOC;
|
||||
@@ -131,7 +131,7 @@ RETURN_ARRAY_COPY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_array_pop(Array *array, u64 item_size) {
|
||||
void *_array_pop(GenericArray *array, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -144,7 +144,7 @@ void *_array_pop(Array *array, u64 item_size) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void _array_clear(Array *array, u64 item_size) {
|
||||
void _array_clear(GenericArray *array, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -152,12 +152,12 @@ void _array_clear(Array *array, u64 item_size) {
|
||||
array->count = 0;
|
||||
}
|
||||
|
||||
Array *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size) {
|
||||
GenericArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
Array *output = NULL;
|
||||
GenericArray *output = NULL;
|
||||
|
||||
u64 allocation_size = sizeof(Array) + item_size * capacity;
|
||||
u64 allocation_size = sizeof(GenericArray) + item_size * capacity;
|
||||
|
||||
output = wapp_mem_allocator_alloc(allocator, allocation_size);
|
||||
if (!output) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define WAPP_ARRAY_MAGIC (u64)0x57415F415252
|
||||
#define WAPP_ARRAY_MAGIC (u64)0x57415f415252
|
||||
|
||||
#define _calc_array_count(TYPE, ...) wapp_misc_utils_va_args_count(TYPE, __VA_ARGS__)
|
||||
#define _calc_array_capacity(TYPE, ...) wapp_misc_utils_u64_round_up_pow2(_calc_array_count(TYPE, __VA_ARGS__) * 2)
|
||||
@@ -61,7 +61,7 @@ BEGIN_C_LINKAGE
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
return *((ELEM_TYPE *)_array_pop((Array *)ARRAY_PTR, sizeof(ELEM_TYPE))); \
|
||||
return *((ELEM_TYPE *)_array_pop((GenericArray *)ARRAY_PTR, sizeof(ELEM_TYPE))); \
|
||||
}())
|
||||
#else
|
||||
#define wapp_array(ELEM_TYPE, ARRAY_TYPE, ...) \
|
||||
@@ -85,43 +85,53 @@ BEGIN_C_LINKAGE
|
||||
})
|
||||
#define wapp_array_pop(ELEM_TYPE, ARRAY_PTR) \
|
||||
(ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*((ELEM_TYPE *)_array_pop((Array *)ARRAY_PTR, sizeof(ELEM_TYPE))) : \
|
||||
*((ELEM_TYPE *)_array_pop((GenericArray *)ARRAY_PTR, sizeof(ELEM_TYPE))) : \
|
||||
(ELEM_TYPE){0} \
|
||||
)
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define wapp_array_get(ELEM_TYPE, ARRAY_PTR, INDEX) \
|
||||
((ELEM_TYPE *)_array_get((Array *)ARRAY_PTR, INDEX, sizeof(ELEM_TYPE)))
|
||||
((ELEM_TYPE *)_array_get((GenericArray *)ARRAY_PTR, INDEX, sizeof(ELEM_TYPE)))
|
||||
#define wapp_array_set(ELEM_TYPE, ARRAY_PTR, INDEX, VALUE_PTR) \
|
||||
_array_set((Array *)ARRAY_PTR, INDEX, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
_array_set((GenericArray *)ARRAY_PTR, INDEX, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_append_capped(ELEM_TYPE, ARRAY_PTR, VALUE_PTR) \
|
||||
_array_append_capped((Array *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
_array_append_capped((GenericArray *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_extend_capped(ELEM_TYPE, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
_array_extend_capped((Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
_array_extend_capped( \
|
||||
(GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_copy_capped(ELEM_TYPE, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
_array_copy_capped((Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
_array_copy_capped( \
|
||||
(GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_append_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, ARRAY_PTR, VALUE_PTR) \
|
||||
(ARRAY_TYPE *)_array_append_alloc(ALLOCATOR_PTR, (Array *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
(ARRAY_TYPE *)_array_append_alloc( \
|
||||
ALLOCATOR_PTR, (GenericArray *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_extend_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
(ARRAY_TYPE *)_array_extend_alloc(ALLOCATOR_PTR, (Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
(ARRAY_TYPE *)_array_extend_alloc( \
|
||||
ALLOCATOR_PTR, (GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_copy_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
(ARRAY_TYPE *)_array_copy_alloc(ALLOCATOR_PTR, (Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
(ARRAY_TYPE *)_array_copy_alloc( \
|
||||
ALLOCATOR_PTR, (GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_clear(ELEM_TYPE, ARRAY_PTR) \
|
||||
_array_clear((Array *)ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
_array_clear((GenericArray *)ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
|
||||
WAPP_DEF_ARRAY_TYPE(void, Array);
|
||||
WAPP_DEF_ARRAY_TYPE(void, GenericArray);
|
||||
|
||||
void *_array_get(Array *array, u64 index, u64 item_size);
|
||||
void _array_set(Array *array, u64 index, void *value, u64 item_size);
|
||||
void _array_append_capped(Array *array, void *value, u64 item_size);
|
||||
void _array_extend_capped(Array *dst, const Array *src, u64 item_size);
|
||||
void _array_copy_capped(Array *dst, const Array *src, u64 item_size);
|
||||
Array *_array_append_alloc(const Allocator *allocator, Array *array, void *value, u64 item_size);
|
||||
Array *_array_extend_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size);
|
||||
Array *_array_copy_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size);
|
||||
void *_array_pop(Array *array, u64 item_size);
|
||||
void _array_clear(Array *array, u64 item_size);
|
||||
Array *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
void *_array_get(GenericArray *array, u64 index, u64 item_size);
|
||||
void _array_set(GenericArray *array, u64 index, void *value, u64 item_size);
|
||||
void _array_append_capped(GenericArray *array, void *value, u64 item_size);
|
||||
void _array_extend_capped(GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
void _array_copy_capped(GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
GenericArray *_array_append_alloc(const Allocator *allocator, GenericArray *array, void *value, u64 item_size);
|
||||
GenericArray *_array_extend_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
GenericArray *_array_copy_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
void *_array_pop(GenericArray *array, u64 item_size);
|
||||
void _array_clear(GenericArray *array, u64 item_size);
|
||||
GenericArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
|
||||
// Base array types
|
||||
typedef struct str8 Str8;
|
||||
|
||||
@@ -62,7 +62,7 @@ u64 wapp_file_get_length(File *file) {
|
||||
return output;
|
||||
}
|
||||
|
||||
u64 wapp_file_read(Array *dst_buf, File *file, u64 item_count) {
|
||||
u64 wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count) {
|
||||
wapp_debug_assert(dst_buf != NULL && file != NULL,
|
||||
"`dst_buf` and `file` should not be NULL.");
|
||||
|
||||
@@ -86,7 +86,7 @@ u64 wapp_file_read(Array *dst_buf, File *file, u64 item_count) {
|
||||
return dst_buf->count;
|
||||
}
|
||||
|
||||
u64 wapp_file_write(const Array *src_buf, File *file, u64 item_count) {
|
||||
u64 wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count) {
|
||||
wapp_debug_assert(src_buf != NULL && file != NULL,
|
||||
"`src_buf` and `file` should not be NULL.");
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ File *wapp_file_open(Str8RO *filename, FileAccessMode mode);
|
||||
u64 wapp_file_get_current_position(File *file);
|
||||
i32 wapp_file_seek(File *file, u64 offset, FileSeekOrigin origin);
|
||||
u64 wapp_file_get_length(File *file);
|
||||
u64 wapp_file_read(Array *dst_buf, File *file, u64 item_count);
|
||||
u64 wapp_file_write(const Array *src_buf, File *file, u64 item_count);
|
||||
u64 wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count);
|
||||
u64 wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count);
|
||||
i32 wapp_file_flush(File *file);
|
||||
i32 wapp_file_close(File *file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user