1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 13:11:54 +00:00
TegraExplorer/source/utils/vector.h

41 lines
1.3 KiB
C
Raw Normal View History

#pragma once
#include <utils/types.h>
2021-07-09 21:56:13 +01:00
#pragma pack(1)
typedef struct {
void* data;
u32 capacity;
u32 count;
2021-06-24 12:01:33 +01:00
u8 elemSz;
// 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))
#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)
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);
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);
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);