List.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef CORE_LIST_H
  2. #define CORE_LIST_H
  3. #include "core/Types.h"
  4. typedef struct {
  5. size_t length;
  6. size_t capacity;
  7. size_t dataSize;
  8. void* data;
  9. } CoreList;
  10. #define CORE_LIST(dataSize) ((CoreList){0, 0, dataSize, nullptr})
  11. void coreCopyList(CoreList* l, const CoreList* other);
  12. void coreMoveList(CoreList* l, CoreList* other);
  13. void coreDestroyList(CoreList* l);
  14. void coreListReserve(CoreList* l, size_t n);
  15. void coreShrinkList(CoreList* l);
  16. void coreResizeList(CoreList* l, size_t n);
  17. void coreResizeListPointer(CoreList* l, size_t n, const void* data);
  18. #define coreResizeListV(l, n, type, ...) \
  19. coreResizeListPointer(l, n, &(type){__VA_ARGS__})
  20. CoreList* coreListAddPointer(CoreList* l, const void* data);
  21. #define coreListAdd(l, type, ...) coreListAddPointer(l, &(type){__VA_ARGS__})
  22. CoreList* coreListAddLast(CoreList* l);
  23. void* coreListAddEmpty(CoreList* l);
  24. void* coreListGetVoidPointer(CoreList* l, size_t index);
  25. #define coreListGetPointer(l, index, type) \
  26. ((type*)coreListGetVoidPointer(l, index))
  27. #define coreListGet(l, index, type) (*coreListGetPointer(l, index, type))
  28. const void* coreListGetVoidPointerC(const CoreList* l, size_t index);
  29. #define coreListGetPointerC(l, index, type) \
  30. ((const type*)coreListGetVoidPointerC(l, index))
  31. #define coreListGetC(l, index, type) (*coreListGetPointerC(l, index, type))
  32. void* coreListLastVoidPointer(CoreList* l);
  33. #define coreListLastPointer(l, type) ((type*)coreListLastVoidPointer(l))
  34. #define coreListLast(l, type) (*coreListLastPointer(l, type))
  35. const void* coreListLastVoidPointerC(const CoreList* l);
  36. #define coreListLastPointerC(l, type) ((const type*)coreListLastVoidPointerC(l))
  37. #define coreListLastC(l, type) (*coreListLastPointerC(l, type))
  38. void coreClearList(CoreList* l);
  39. void coreListRemoveBySwap(CoreList* l, size_t index);
  40. void coreListRemove(CoreList* l, size_t index);
  41. void coreListRemoveLast(CoreList* l);
  42. size_t coreToStringList(CoreList* l, char* buffer, size_t n, CoreToString c);
  43. void coreSwapList(CoreList* a, CoreList* b);
  44. void* coreListBegin(CoreList* l);
  45. void* coreListEnd(CoreList* l);
  46. #endif