#ifndef _NESTED_LOOPS_H #define _NESTED_LOOPS_H /* -------------------- */ /* nested_loops.h */ struct NestedLoop_List { int length; void** ptr; /* arr of ptrs */ void (*free)(struct NestedLoop_List* list); /* frees ptr */ void* free_pad; /* closure-like */ }; #define NestedLoop_PT_ARRAY 0 #define NestedLoop_PT_FUNC 1 struct NestedLoop_ArrayArg { int length; void** ptr; }; struct NestedLoop_FuncArg void (*ptr)(struct NestedLoop_List* list, void* pad); void* pad; /* closure-like */ }; struct NestedLoop_Arg { int ptr_type; /* NestedLoop_PT_* */ union { struct NestedLoop_ArrayArg array; struct NestedLoop_FuncArg func; } ptr; }; struct NestedLoop_Iter { int num_loops; struct NestedLoopArg* loops; int* indexes; struct NestedLoop_List* vals; struct NestedLoop_List list; }; void NestedLoop_no_free(void*); void NestedLoops_array_to_list( struct NestedLoop_List* list, void* array, int array_size, int elem_size ); void NestedLoops_array_to_ptr_array( void** ptr_array_ptr, void* array, int array_size, int elem_size ); void NestedLoops_free_list(struct NestedLoop_List* list); void NestedLoops_get_iter( struct NestedLoop_Iter* iter, int num_loops, struct NestedLoop_Arg* loops ); BOOL NestedLoops_fetch( struct NestedLoop_Iter* iter ); void NestedLoops_done( struct NestedLoop_Iter* iter ); #endif