/* -*-c-*-
*
- * $Id: darray.h,v 1.1 1999/10/22 22:37:26 mdw Exp $
+ * $Id: darray.h,v 1.3 1999/11/05 14:32:43 mdw Exp $
*
* Dynamically growing dense arrays
*
/*----- Revision history --------------------------------------------------*
*
* $Log: darray.h,v $
+ * Revision 1.3 1999/11/05 14:32:43 mdw
+ * Minor change in argument naming.
+ *
+ * Revision 1.2 1999/10/29 22:59:22 mdw
+ * New array adjustment macros for unsigned arguments.
+ *
* Revision 1.1 1999/10/22 22:37:26 mdw
* New dynamic array implementation replaces `dynarray.h'.
*
* Use: Declares a structure for decribing a dynamic array.
*/
-#define DA_DECL(atype, type) \
- typedef struct atype { da_base b; type *v; } atype
+#define DA_DECL(type_v, type) \
+ typedef struct type_v { da_base b; type *v; } type_v
/*----- Initialization, creation and destruction --------------------------*/
#define DA_TIDY(a) ((a)->v = da_tidy(&(a)->b, (a)->v, sizeof((a)->v[0])))
+/* --- @DA_RESET@ --- *
+ *
+ * Arguments: @a@ = pointer to array block
+ *
+ * Use: Removes all the items from the named array. This might not
+ * be a good idea. No storage is freed.
+ */
+
+#define DA_RESET(a) ((a)->b.len = 0)
+
/*----- Access operations -------------------------------------------------*/
/* --- @DA@ --- *
DA_UNSAFE_EXTEND(a, n); \
} while (0)
-/* --- @DA_EXTEND@ --- *
+/* --- @DA_UNSAFE_EXTEND@ --- *
*
* Arguments: @a@ = pointer to array block (multiply evaluated)
* @n@ = number of slots to add (multiply evaluated)
(a)->b.off -= (n); \
} while (0)
+/* --- @DA_SHRINK@ --- *
+ *
+ * Arguments: @a@ = pointer to array block (multiply evaluated)
+ * @n@ = number of slots to remove (multiply evaluated)
+ *
+ * Use: As for @DA_EXTEND@, with the sense of the argument reversed.
+ */
+
+#define DA_SHRINK(a, n) do { \
+ if ((n) > 0 && (n) > DA_LEN(a)) \
+ THROW(DAEXC_UFLOW); \
+ else if ((n) < 0 && -(n) > DA_SPARE(a)) \
+ THROW(DAEXC_OFLOW); \
+ DA_UNSAFE_SHRINK(a, n); \
+} while (0)
+
+/* --- @DA_UNSAFE_SHRINK@ --- *
+ *
+ * Arguments: @a@ = pointer to array block (multiply evaluated)
+ * @n@ = number of slots to add (multiply evaluated)
+ *
+ * Use: As for @DA_SHRINK@, only it doesn't check for errors.
+ */
+
+#define DA_UNSAFE_SHRINK(a, n) do { \
+ (a)->b.len -= (n); \
+} while (0)
+
+/* --- @DA_UNSLIDE@ --- *
+ *
+ * Arguments: @a@ = pointer to array block (multiply evaluated)
+ * @n@ = number of positions to slide the array (multiply
+ * evaluated)
+ *
+ *
+ * Use: As for @DA_SLIDE@, only in the other direction.
+ */
+
+#define DA_UNSLIDE(a, n) do { \
+ if ((n) > 0 && (n) > DA_LEN(a)) \
+ THROW(DAEXC_UFLOW); \
+ else if ((n) < 0 && -(n) > DA_OFFSET(a)) \
+ THROW(DAEXC_OFLOW); \
+ DA_UNSAFE_UNSLIDE((a), (n)); \
+} while (0)
+
+/* --- @DA_UNSAFE_UNSLIDE@ --- *
+ *
+ * Arguments: @a@ = pointer to array block (multiply evaluated)
+ * @n@ = number of positions to slide the array (multiply
+ * evaluated)
+ *
+ * Use: As for @DA_UNSLIDE@, only it doesn't check for errors.
+ */
+
+#define DA_UNSAFE_UNSLIDE(a, n) do { \
+ (a)->v += (n); \
+ (a)->b.len -= (n); \
+ (a)->b.sz -= (n); \
+ (a)->b.off += (n); \
+} while (0)
+
/*----- Stack-like operations ---------------------------------------------*/
/* --- @DA_PUSH@ --- *