#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 *);
__attribute__ ((__nonnull__))
bool (*flag_removal)(
void *);
bool mutating;
bool remove;
};
struct cx_mut_iterator_s {
struct cx_iterator_base_s base;
void *elem_handle;
void *src_handle;
struct {
void const *key;
void *value;
} kv_data;
size_t slot;
size_t index;
};
typedef struct cx_mut_iterator_s CxMutIterator;
struct cx_iterator_s {
struct cx_iterator_base_s base;
void *elem_handle;
void const *src_handle;
struct {
void const *key;
void *value;
} kv_data;
size_t slot;
size_t index;
};
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.flag_removal(&iter)
#define cx_foreach(type, elem, iter) \
for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) !=
NULL ; cxIteratorNext(iter))
#endif