#ifndef UCX_ITERATOR_H
#define UCX_ITERATOR_H
#include "common.h"
struct cx_iterator_base_s {
__attribute__ ((__nonnull__))
bool (*valid)(
void const *);
__attribute__ ((__nonnull__))
void *(*current)(
void const *);
__attribute__ ((__nonnull__))
void *(*current_impl)(
void const *);
__attribute__ ((__nonnull__))
void (*next)(
void *);
bool mutating;
bool remove;
};
#define CX_ITERATOR_BASE struct cx_iterator_base_s base
struct cx_iterator_s {
CX_ITERATOR_BASE;
void *elem_handle;
union {
void *m;
void const *c;
} src_handle;
struct {
void const *key;
void *value;
} kv_data;
size_t slot;
size_t index;
size_t elem_size;
size_t elem_count;
};
typedef struct cx_iterator_s CxIterator;
#define cxIteratorValid(iter) (iter).base.valid(&(iter))
#define cxIteratorCurrent(iter) (iter).base.current(&iter)
#define cxIteratorNext(iter) (iter).base.next(&iter)
#define cxIteratorFlagRemoval(iter) (iter).base.remove |= (iter).base.mutating
#define cx_foreach(type, elem, iter) \
for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) !=
NULL ; cxIteratorNext(iter))
__attribute__((__warn_unused_result__))
CxIterator cxIterator(
void const *array,
size_t elem_size,
size_t elem_count
);
__attribute__((__warn_unused_result__))
CxIterator cxMutIterator(
void *array,
size_t elem_size,
size_t elem_count,
bool remove_keeps_order
);
#endif