#ifndef UCX_ITERATOR_H
#define UCX_ITERATOR_H
#include "common.h"
struct cx_iterator_base_s {
__attribute__ ((__nonnull__))
bool (*valid)(
const void *);
__attribute__ ((__nonnull__))
void *(*current)(
const void *);
__attribute__ ((__nonnull__))
void *(*current_impl)(
const void *);
__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;
const void *c;
} src_handle;
struct {
const void *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 cxIteratorRef(iter) &((iter).base)
#define cx_foreach(type, elem, iter) \
for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) !=
NULL ; cxIteratorNext(iter))
__attribute__((__warn_unused_result__))
CxIterator cxIterator(
const void *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