2020-12-23 16:39:22 +00:00
|
|
|
#pragma once
|
|
|
|
#include <utils/types.h>
|
|
|
|
|
2021-07-09 21:56:13 +01:00
|
|
|
#pragma pack(1)
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
typedef struct {
|
|
|
|
void* data;
|
|
|
|
u32 capacity;
|
|
|
|
u32 count;
|
2021-06-24 12:01:33 +01:00
|
|
|
u8 elemSz;
|
2020-12-23 16:39:22 +00:00
|
|
|
// u32 typeTag;
|
|
|
|
} Vector_t;
|
|
|
|
|
2021-07-09 21:56:13 +01:00
|
|
|
#pragma pack()
|
|
|
|
|
2020-12-28 13:51:59 +00:00
|
|
|
#define FREE(x) free(x); x = NULL;
|
|
|
|
|
2021-06-24 20:26:36 +01:00
|
|
|
#define vecAddElem(v, elem) _vecAdd(v, &elem, sizeof(elem))
|
|
|
|
#define vecAddElement(v, elem) _vecAdd(v, &elem, sizeof(elem))
|
|
|
|
#define vecAdd(vec, element) _vecAdd(vec, &element, sizeof(element))
|
2020-12-23 16:39:22 +00:00
|
|
|
#define vecDefArray(type, varName, vec) type varName = (type)((vec).data)
|
|
|
|
#define vecGetArray(type, vec) (type)((vec).data)
|
|
|
|
#define vecPDefArray(type, varName, vec) type varName = (type)((vec)->data)
|
|
|
|
#define vecPGetArray(type, vec) (type)((vec)->data)
|
2020-12-28 13:51:59 +00:00
|
|
|
#define vecFreePtr(vec) FREE(vec->data)
|
|
|
|
#define vecFree(vec) FREE(vec.data)
|
|
|
|
#define vecGetCapacity(vec) (vec.capacity / vec.elemSz)
|
|
|
|
|
|
|
|
#define vecGetArrayPtr(vec, type) (type)((vec)->data)
|
2020-12-23 16:39:22 +00:00
|
|
|
|
2021-06-24 12:01:33 +01:00
|
|
|
#define vecForEach(type, varname, vecPtr) for (type varname = vecPtr->data; ((u8*)varname - (u8*)vecPtr->data) < (vecPtr->count * vecPtr->elemSz); varname++)
|
|
|
|
|
|
|
|
Vector_t newVec(u8 typesz, u32 preallocate);
|
2020-12-23 16:39:22 +00:00
|
|
|
Vector_t vecFromArray(void* array, u32 count, u32 typesz);
|
2021-06-24 20:26:36 +01:00
|
|
|
bool _vecAdd(Vector_t* v, void* elem, u8 sz);
|
2021-01-01 17:30:51 +00:00
|
|
|
Vector_t vecCopy(Vector_t* orig);
|
2021-06-24 12:01:33 +01:00
|
|
|
Vector_t vecCopyOffset(Vector_t* orig, u32 offset);
|
|
|
|
|
|
|
|
void* getStackEntry(Vector_t* stack);
|
|
|
|
void* popStackEntry(Vector_t* stack);
|
|
|
|
void vecRem(Vector_t * vec, int idx);
|