/** * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. * 内部基础模块,所有参数合法性由调用者保证 */ #ifndef VECTOR_H_ #define VECTOR_H_ #include "c_base.h" #ifdef __cplusplus extern "C" { #endif typedef struct { size_t itemSize; size_t size; size_t capacity; uint8_t *data; FnDestroy pfnDestroyItem; } Vector; #define NewVector(objType) CreateVector(sizeof(objType)) // itemSize 不能为0,请调用者保证 void InitVector(Vector *vector, size_t itemSize); static inline void SetVectorDestroyItem(Vector *vector, FnDestroy pfnDestroyItem) { vector->pfnDestroyItem = pfnDestroyItem; }; void DeInitVector(Vector *vector); // itemSize 不能为0,请调用者保证 Vector *CreateVector(size_t itemSize); void DestroyVector(Vector *vector); void ClearVector(Vector *vector); static inline size_t VectorSize(const Vector *vector) { return vector->size; }; size_t ReSizeVector(Vector *vector, size_t size); size_t CapacityVector(Vector *vector, size_t capacity); void *EmplaceVector(Vector *vector, size_t index, void *data); void *EmplaceBackVector(Vector *vector, void *data); void *EmplaceHeadVector(Vector *vector, void *data); void RemoveVector(Vector *vector, size_t index); void MoveVector(Vector *src, Vector *desc); void *VectorAt(Vector *vector, size_t index); const void *ConstVectorAt(const Vector *vector, size_t index); #ifdef __cplusplus } #endif #endif