extract PTK_LIST_STATIC_INIT into PTK_ARRAY

This commit is contained in:
jacekpoz 2024-08-11 21:07:53 +02:00
parent 276138043d
commit 2b5be4c732
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 21 additions and 9 deletions

18
src/ptk_array.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef PTK_PTK_ARRAY_H_
#define PTK_PTK_ARRAY_H_
#define PTK_ARRAY(T) struct PtkArray_##T
#define PTK_ARRAY_DEFINE(T) \
PTK_ARRAY(T) {\
T *data;\
uint32_t size;\
}\
#define PTK_ARRAY_NEW(T, ...) \
(PTK_ARRAY(T)){\
.data = (T []) __VA_ARGS__ ,\
.size = sizeof((T []) __VA_ARGS__) / sizeof(T),\
}
#endif // PTK_PTK_ARRAY_H_

View file

@ -37,13 +37,6 @@ bool _remove_at_PtkList(void *data, uint32_t *size, size_t index, size_t element
.allocated = _size,\
}
#define PTK_LIST_STATIC_INIT(T, ...) \
(PTK_LIST(T)){\
.data = (T []) __VA_ARGS__ ,\
.size = sizeof((T []) __VA_ARGS__) / sizeof(T),\
.allocated = sizeof((T []) __VA_ARGS__) / sizeof(T),\
}
#define PTK_LIST_FREE(list) \
free(list.data)

View file

@ -6,6 +6,7 @@
#include <ptk_log.h>
#include <ptk_option.h>
#include <ptk_array.h>
#include <ptk_list.h>
#include <stdio.h>
#include <string.h>
@ -18,7 +19,7 @@ PTK_OPTION_DEFINE(uint32_t);
PTK_LIST_DEFINE(VkSurfaceFormatKHR);
PTK_LIST_DEFINE(VkPresentModeKHR);
PTK_LIST_DEFINE(VkFramebuffer);
PTK_LIST_DEFINE(VkVertexInputAttributeDescription);
PTK_ARRAY_DEFINE(VkVertexInputAttributeDescription);
PTK_LIST_DEFINE(VkExtensionProperties);
PTK_LIST_DEFINE(VkQueueFamilyProperties);
PTK_OPTION_DEFINE(VkShaderModule);
@ -85,7 +86,7 @@ static const VkVertexInputBindingDescription m_vertex_binding_description = {
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
};
PTK_LIST(VkVertexInputAttributeDescription) m_vertex_attribute_descriptions = PTK_LIST_STATIC_INIT(VkVertexInputAttributeDescription, {
PTK_ARRAY(VkVertexInputAttributeDescription) m_vertex_attribute_descriptions = PTK_ARRAY_NEW(VkVertexInputAttributeDescription, {
(VkVertexInputAttributeDescription){
.location = 0,
.binding = 0,