project_files/frontlib/util/list.h
changeset 7316 f7b49b2c5d84
parent 7314 6171f0bad318
child 10017 de822cd3df3a
equal deleted inserted replaced
7314:6171f0bad318 7316:f7b49b2c5d84
    38  * The function returns 0 on success and leaves the array unchanged on error.
    38  * The function returns 0 on success and leaves the array unchanged on error.
    39  */
    39  */
    40 #define GENERATE_STATIC_LIST_INSERT(fname, type) \
    40 #define GENERATE_STATIC_LIST_INSERT(fname, type) \
    41 	static int fname(type **listptr, int *listSizePtr, type element, int pos) { \
    41 	static int fname(type **listptr, int *listSizePtr, type element, int pos) { \
    42 		int result = -1; \
    42 		int result = -1; \
    43 		if(!listptr || !listSizePtr || pos < 0 || pos > *listSizePtr) { \
    43 		if(!log_badargs_if4(listptr==NULL, listSizePtr==NULL, pos < 0, pos > *listSizePtr)) { \
    44 			flib_log_e("Invalid parameter in "#fname); \
       
    45 		} else { \
       
    46 			type *newList = flib_realloc(*listptr, ((*listSizePtr)+1)*sizeof(type)); \
    44 			type *newList = flib_realloc(*listptr, ((*listSizePtr)+1)*sizeof(type)); \
    47 			if(newList) { \
    45 			if(newList) { \
    48 				memmove(newList + (pos+1), newList + pos, ((*listSizePtr)-pos)*sizeof(type)); \
    46 				memmove(newList + (pos+1), newList + pos, ((*listSizePtr)-pos)*sizeof(type)); \
    49 				newList[pos] = element; \
    47 				newList[pos] = element; \
    50 				(*listSizePtr)++; \
    48 				(*listSizePtr)++; \
    63  * The function returns 0 on success and leaves the array unchanged on error.
    61  * The function returns 0 on success and leaves the array unchanged on error.
    64  */
    62  */
    65 #define GENERATE_STATIC_LIST_DELETE(fname, type) \
    63 #define GENERATE_STATIC_LIST_DELETE(fname, type) \
    66 	static int fname(type **listPtr, int *listSizePtr, int pos) { \
    64 	static int fname(type **listPtr, int *listSizePtr, int pos) { \
    67 		int result = -1; \
    65 		int result = -1; \
    68 		if(!listPtr || !listSizePtr || pos < 0 || pos >= *listSizePtr) { \
    66 		if(!log_badargs_if4(listPtr==NULL, listSizePtr==NULL, pos < 0, pos >= *listSizePtr)) { \
    69 			flib_log_e("Invalid parameter in "#fname); \
       
    70 		} else { \
       
    71 			memmove((*listPtr) + pos, (*listPtr) + (pos+1), ((*listSizePtr)-(pos+1))*sizeof(type)); \
    67 			memmove((*listPtr) + pos, (*listPtr) + (pos+1), ((*listSizePtr)-(pos+1))*sizeof(type)); \
    72 			(*listSizePtr)--; \
    68 			(*listSizePtr)--; \
    73 			\
    69 			\
    74 			size_t newCharSize = (*listSizePtr)*sizeof(type); \
    70 			size_t newCharSize = (*listSizePtr)*sizeof(type); \
    75 			type *newList = flib_realloc((*listPtr), newCharSize); \
    71 			type *newList = flib_realloc((*listPtr), newCharSize); \