1 #ifndef _LIST_STRUCT_H_ 2 #define _LIST_STRUCT_H_ 3 4 /*---------------------------------------------------------------------- 5 * list_struct.h - for creating and destroying lists 6 * 7 * I tried to follow Bob's structure and element naming style. 8 * 9 * Rick Reynolds - December 6, 2004 10 *----------------------------------------------------------------------*/ 11 12 /* value lists include number used, number allocated, and the list */ 13 typedef struct { int num,nall; float * list; } float_list; 14 typedef struct { int num,nall; int * list; } int_list; 15 typedef struct { int num,nall; short * list; } short_list; 16 typedef struct { int num,nall,alloc; char ** list; } string_list; 17 18 /* pointer lists also include an element length field (# elements allocated) */ 19 typedef struct { int num,nall; float ** list; } floatp_list; 20 typedef struct { int num,nall; int ** list; } intp_list; 21 typedef struct { int num,nall; short ** list; } shortp_list; 22 typedef struct { int num,nall; void ** list; } voidp_list; 23 24 /* create lists of the requested number of elements */ 25 int init_float_list ( float_list * d_list, int nel ); 26 int init_int_list ( int_list * d_list, int nel ); 27 int init_short_list ( short_list * d_list, int nel ); 28 int init_string_list ( string_list * d_list, int nel, int alloc ); 29 30 /* create nel lists, of length len */ 31 int init_floatp_list ( floatp_list * d_list, int nel ); 32 int init_intp_list ( intp_list * d_list, int nel ); 33 int init_shortp_list ( shortp_list * d_list, int nel ); 34 int init_voidp_list ( voidp_list * d_list, int nel ); 35 36 /* add to lists, possibly increment length */ 37 int add_to_float_list ( float_list * d_list, float val, int inc_size ); 38 int add_to_int_list ( int_list * d_list, int val, int inc_size ); 39 int add_to_string_list( string_list * d_list, char * val, int inc_size ); 40 41 /* resize list allocation*/ 42 int resize_int_list ( int_list * L, int len ); 43 44 /* add to lists, possibly increment length */ 45 int extend_int_list ( int_list * Ldest, int_list * Lsrc ); 46 int extend_str_list ( int_list * Ldest, int_list * Lsrc ); 47 48 /* other */ 49 50 /* free simple lists and clear structures */ 51 int free_float_list ( float_list * d_list ); 52 int free_int_list ( int_list * d_list ); 53 int free_short_list ( short_list * d_list ); 54 int free_string_list ( string_list * d_list ); 55 56 int clear_float_list ( float_list * d_list ); 57 int clear_int_list ( int_list * d_list ); 58 int clear_string_list( string_list * d_list ); 59 60 /* free list lists, and clear structures */ 61 int free_floatp_list ( floatp_list * d_list ); 62 int free_intp_list ( intp_list * d_list ); 63 int free_shortp_list ( shortp_list * d_list ); 64 int free_voidp_list ( voidp_list * d_list ); 65 66 #endif 67