59 lines
1 KiB
C
59 lines
1 KiB
C
|
|
typedef void (*pbuf_func_free_t)(void*);
|
|
|
|
#define PBUF_NONE ((void*)-1)
|
|
|
|
typedef struct {
|
|
int used;
|
|
int allocated;
|
|
int chunksize;
|
|
void** ptr;
|
|
pbuf_func_free_t func_free;
|
|
} pbuf_t;
|
|
|
|
void pbuf_init(
|
|
pbuf_t* pbuf,
|
|
int size,
|
|
int chunksize,
|
|
pbuf_func_free_t func_free);
|
|
|
|
void pbuf_destroy(pbuf_t* pbuf);
|
|
|
|
void
|
|
pbuf_clear(pbuf_t* pbuf);
|
|
|
|
void
|
|
pbuf_append(pbuf_t* pbuf, void* ptr);
|
|
|
|
void
|
|
pbuf_putat(pbuf_t* pbuf, int ix, void* obj);
|
|
|
|
void*
|
|
pbuf_getat(const pbuf_t* pbuf, int ix);
|
|
|
|
int
|
|
pbuf_size(const pbuf_t* pbuf);
|
|
|
|
typedef int (*pbuf_func_find_t)(void* obj, const void* arg);
|
|
|
|
void*
|
|
pbuf_find(
|
|
const pbuf_t* pbuf,
|
|
pbuf_func_find_t func,
|
|
const void* arg);
|
|
|
|
typedef int (*pbuf_func_sort_t)(const void* obj1, const void* obj2);
|
|
|
|
void
|
|
pbuf_sort(
|
|
pbuf_t* pbuf,
|
|
pbuf_func_sort_t func);
|
|
|
|
#define PBUF_FOREACH(element, list) { \
|
|
int pbuf_i; \
|
|
if ((void*)list != NULL) for (pbuf_i = 0; pbuf_i < (list)->used; ++pbuf_i) { \
|
|
element = (list)->ptr[pbuf_i]; \
|
|
if (!element) continue;
|
|
|
|
#define PBUF_FOREACH_END } }
|
|
|