36#ifndef UCX_COLLECTION_H
37#define UCX_COLLECTION_H
46#define CX_STORE_POINTERS 0
118#define CX_COLLECTION_BASE struct cx_collection_s collection
126#define cxCollectionSize(c) ((c)->collection.size)
136#define cxCollectionElementSize(c) ((c)->collection.elem_size)
145#define cxCollectionStoresPointers(c) ((c)->collection.store_pointer)
155#define cx_ref(c, elem) (cxCollectionStoresPointers(c) ? ((void*)&(elem)) : (elem))
164#define cx_deref(c, elem) (cxCollectionStoresPointers(c) ? *((void**)(elem)) : (elem))
178#define cxCollectionSorted(c) ((c)->collection.sorted || (c)->collection.size == 0)
190#define cxSetCompareFunc(c, func) \
191 (c)->collection.simple_cmp = (cx_compare_func)(func); \
192 (c)->collection.advanced_cmp = NULL
201#define cxSetAdvancedCompareFunc(c, func, data) \
202 (c)->collection.advanced_cmp = (cx_compare_func2) func; \
203 (c)->collection.cmp_data = data
215#define cx_invoke_simple_compare_func(c, left, right) \
216 (c)->collection.simple_cmp(left, right)
228#define cx_invoke_advanced_compare_func(c, left, right) \
229 (c)->collection.advanced_cmp(left, right, (c)->collection.cmp_data)
242#define cx_invoke_compare_func(c, left, right) \
243 (((c)->collection.advanced_cmp) ? \
244 cx_invoke_advanced_compare_func(c,left,right) : \
245 cx_invoke_simple_compare_func(c,left,right))
253#define cxSetDestructor(c, destr) \
254 (c)->collection.simple_destructor = (cx_destructor_func) destr
263#define cxSetAdvancedDestructor(c, destr, data) \
264 (c)->collection.advanced_destructor = (cx_destructor_func2) destr; \
265 (c)->collection.destructor_data = data
279#define cx_invoke_simple_destructor(c, e) \
280 (c)->collection.simple_destructor((c)->collection.store_pointer ? (*((void **) (e))) : (e))
294#define cx_invoke_advanced_destructor(c, e) \
295 (c)->collection.advanced_destructor((c)->collection.destructor_data, \
296 (c)->collection.store_pointer ? (*((void **) (e))) : (e))
311#define cx_invoke_destructor(c, e) \
312 if ((c)->collection.simple_destructor) cx_invoke_simple_destructor(c,e); \
313 if ((c)->collection.advanced_destructor) cx_invoke_advanced_destructor(c,e)
328#define cx_invoke_destructor_raw(c, e) \
329 if ((c)->collection.simple_destructor) (c)->collection.simple_destructor(e); \
330 if ((c)->collection.advanced_destructor) (c)->collection.advanced_destructor((c)->collection.destructor_data, e)
Interface for custom allocators.
void(* cx_destructor_func2)(void *data, void *memory)
Function pointer type for destructor functions.
Definition allocator.h:116
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
void(* cx_destructor_func)(void *memory)
Function pointer type for destructor functions.
Definition allocator.h:103
A collection of simple compare functions.
int(* cx_compare_func)(const void *left, const void *right)
A comparator function comparing two arbitrary values.
Definition compare.h:53
int(* cx_compare_func2)(const void *left, const void *right, void *data)
A comparator function comparing two arbitrary values.
Definition compare.h:60
Interface for iterator implementations.
Base attributes of a collection.
Definition collection.h:51
bool sorted
Indicates if this collection is guaranteed to be sorted.
Definition collection.h:104
const CxAllocator * allocator
The allocator to use.
Definition collection.h:55
cx_compare_func simple_cmp
A two-argument comparator function for the elements.
Definition collection.h:67
cx_destructor_func simple_destructor
An optional simple destructor for the collection's elements.
Definition collection.h:83
size_t elem_size
The size of each element.
Definition collection.h:59
bool store_pointer
Indicates if this list is supposed to store pointers instead of copies of the actual objects.
Definition collection.h:99
cx_compare_func2 advanced_cmp
A three-argument comparator function for the elements.
Definition collection.h:72
size_t size
The number of currently stored elements.
Definition collection.h:63
cx_destructor_func2 advanced_destructor
An optional advanced destructor for the collection's elements.
Definition collection.h:90
void * cmp_data
A pointer to custom data for the advanced_cmp function.
Definition collection.h:76
void * destructor_data
The pointer to additional data that is passed to the advanced destructor.
Definition collection.h:94