#ifndef UCX_COLLECTION_H
#define UCX_COLLECTION_H
#include "allocator.h"
#include "iterator.h"
#include "compare.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CX_STORE_POINTERS 0
struct cx_collection_s {
CxAllocator
const *allocator;
cx_compare_func cmpfunc;
size_t elem_size;
size_t size;
cx_destructor_func simple_destructor;
cx_destructor_func2 advanced_destructor;
void *destructor_data;
bool store_pointer;
};
#define CX_COLLECTION_BASE struct cx_collection_s collection
#define cxDefineDestructor(c, destr) \
(c)->collection.simple_destructor = (cx_destructor_func) destr
#define cxDefineAdvancedDestructor(c, destr, data) \
(c)->collection.advanced_destructor = (cx_destructor_func2) destr; \
(c)->collection.destructor_data = data
#define cx_invoke_simple_destructor(c, e) \
(c)->collection.simple_destructor((c)->collection.store_pointer ? (*((
void **) (e))) : (e))
#define cx_invoke_advanced_destructor(c, e) \
(c)->collection.advanced_destructor((c)->collection.destructor_data, \
(c)->collection.store_pointer ? (*((
void **) (e))) : (e))
#define cx_invoke_destructor(c, e) \
if ((c)->collection.simple_destructor) cx_invoke_simple_destructor(c,e); \
if ((c)->collection.advanced_destructor) cx_invoke_advanced_destructor(c,e)
#ifdef __cplusplus
}
#endif
#endif