Blame iterator.h

Packit 4511e4
#ifndef ITERATOR_H
Packit 4511e4
#define ITERATOR_H
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Generic constants related to iterators.
Packit 4511e4
 */
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * The attempt to advance the iterator was successful; the iterator
Packit 4511e4
 * reflects the new current entry.
Packit 4511e4
 */
Packit 4511e4
#define ITER_OK 0
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * The iterator is exhausted and has been freed.
Packit 4511e4
 */
Packit 4511e4
#define ITER_DONE -1
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * The iterator experienced an error. The iteration has been aborted
Packit 4511e4
 * and the iterator has been freed.
Packit 4511e4
 */
Packit 4511e4
#define ITER_ERROR -2
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Return values for selector functions for merge iterators. The
Packit 4511e4
 * numerical values of these constants are important and must be
Packit 4511e4
 * compatible with ITER_DONE and ITER_ERROR.
Packit 4511e4
 */
Packit 4511e4
enum iterator_selection {
Packit 4511e4
	/* End the iteration without an error: */
Packit 4511e4
	ITER_SELECT_DONE = ITER_DONE,
Packit 4511e4
Packit 4511e4
	/* Report an error and abort the iteration: */
Packit 4511e4
	ITER_SELECT_ERROR = ITER_ERROR,
Packit 4511e4
Packit 4511e4
	/*
Packit 4511e4
	 * The next group of constants are masks that are useful
Packit 4511e4
	 * mainly internally.
Packit 4511e4
	 */
Packit 4511e4
Packit 4511e4
	/* The LSB selects whether iter0/iter1 is the "current" iterator: */
Packit 4511e4
	ITER_CURRENT_SELECTION_MASK = 0x01,
Packit 4511e4
Packit 4511e4
	/* iter0 is the "current" iterator this round: */
Packit 4511e4
	ITER_CURRENT_SELECTION_0 = 0x00,
Packit 4511e4
Packit 4511e4
	/* iter1 is the "current" iterator this round: */
Packit 4511e4
	ITER_CURRENT_SELECTION_1 = 0x01,
Packit 4511e4
Packit 4511e4
	/* Yield the value from the current iterator? */
Packit 4511e4
	ITER_YIELD_CURRENT = 0x02,
Packit 4511e4
Packit 4511e4
	/* Discard the value from the secondary iterator? */
Packit 4511e4
	ITER_SKIP_SECONDARY = 0x04,
Packit 4511e4
Packit 4511e4
	/*
Packit 4511e4
	 * The constants that a selector function should usually
Packit 4511e4
	 * return.
Packit 4511e4
	 */
Packit 4511e4
Packit 4511e4
	/* Yield the value from iter0: */
Packit 4511e4
	ITER_SELECT_0 = ITER_CURRENT_SELECTION_0 | ITER_YIELD_CURRENT,
Packit 4511e4
Packit 4511e4
	/* Yield the value from iter0 and discard the one from iter1: */
Packit 4511e4
	ITER_SELECT_0_SKIP_1 = ITER_SELECT_0 | ITER_SKIP_SECONDARY,
Packit 4511e4
Packit 4511e4
	/* Discard the value from iter0 without yielding anything this round: */
Packit 4511e4
	ITER_SKIP_0 = ITER_CURRENT_SELECTION_1 | ITER_SKIP_SECONDARY,
Packit 4511e4
Packit 4511e4
	/* Yield the value from iter1: */
Packit 4511e4
	ITER_SELECT_1 = ITER_CURRENT_SELECTION_1 | ITER_YIELD_CURRENT,
Packit 4511e4
Packit 4511e4
	/* Yield the value from iter1 and discard the one from iter0: */
Packit 4511e4
	ITER_SELECT_1_SKIP_0 = ITER_SELECT_1 | ITER_SKIP_SECONDARY,
Packit 4511e4
Packit 4511e4
	/* Discard the value from iter1 without yielding anything this round: */
Packit 4511e4
	ITER_SKIP_1 = ITER_CURRENT_SELECTION_0 | ITER_SKIP_SECONDARY
Packit 4511e4
};
Packit 4511e4
Packit 4511e4
#endif /* ITERATOR_H */