diff array.h @ 9:1fbcbd58742e

move destroyall to array.h
author David A. Holland
date Sun, 19 Dec 2010 19:19:02 -0500
parents 0601b6e8e53d
children b156910b59b2
line wrap: on
line diff
--- a/array.h	Sun Dec 19 19:15:55 2010 -0500
+++ b/array.h	Sun Dec 19 19:19:02 2010 -0500
@@ -227,6 +227,24 @@
 #define DECLARRAY(T) DECLARRAY_BYTYPE(T##array, struct T)
 #define DEFARRAY(T, INLINE) DEFARRAY_BYTYPE(T##array, struct T, INLINE)
 
+#define DESTROYALL_ARRAY(T, INLINE) \
+	void T##array_destroyall(struct T##array *arr);	\
+							\
+	INLINE void					\
+	T##array_destroyall(struct T##array *arr)	\
+	{						\
+		unsigned i, num;			\
+		struct T *t;				\
+							\
+		num = T##array_num(arr);		\
+		for (i=0; i<num; i++) {			\
+			t = T##array_get(arr, i);	\
+			T##_destroy(t);			\
+		}					\
+		T##array_setsize(arr, 0);		\
+	}
+
+
 ////////////////////////////////////////////////////////////
 // basic array types