]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/gary.h
Imported tableprinter module
[libucw.git] / ucw / gary.h
index 6610e7997b1fe9039e6fd89c205b89dd30b9559e..ffcabafb41749cadbecd9632aefb51c2460ed7d4 100644 (file)
@@ -10,6 +10,7 @@
 #include <ucw/alloc.h>
 
 #ifdef CONFIG_UCW_CLEAN_ABI
+#define gary_empty_hdr ucw_gary_empty_hdr
 #define gary_fix ucw_gary_fix
 #define gary_init ucw_gary_init
 #define gary_push_helper ucw_gary_push_helper
@@ -27,17 +28,58 @@ struct gary_hdr {
 #define GARY_HDR(ptr) ((struct gary_hdr *)((byte*)(ptr) - GARY_HDR_SIZE))
 #define GARY_BODY(ptr) ((byte *)(ptr) + GARY_HDR_SIZE)
 
+/**
+ * Create a new growing array, initially containing @n elements,
+ * and let @ptr point to its first element. The memory used by the
+ * array is allocated by <<basics:xmalloc()>>.
+ **/
 #define GARY_INIT(ptr, n) (ptr) = gary_init(sizeof(*(ptr)), (n), &ucw_allocator_std)
+
+/**
+ * Create a growing array like GARY_INIT() does, but all newly
+ * allocated elements will be automatically zeroed.
+ **/
 #define GARY_INIT_ZERO(ptr, n) (ptr) = gary_init(sizeof(*(ptr)), (n), &ucw_allocator_zeroed)
+
+/**
+ * Create a growing array like GARY_INIT() does, but based upon the given
+ * <<alloc:,generic allocator>>.
+ **/
 #define GARY_INIT_ALLOC(ptr, n, a) (ptr) = gary_init(sizeof(*(ptr)), (n), (a))
+
+/**
+ * Create a growing array, initially containing 0 elements, but with enough
+ * space to keep @n of them without needing reallocation. The @ptr variable
+ * will point to the first element of the array.
+ **/
 #define GARY_INIT_SPACE(ptr, n) do { GARY_INIT(ptr, n); (GARY_HDR(ptr))->num_elts = 0; } while (0)
+
+/** A combination of GARY_INIT_ZERO() and GARY_INIT_SPACE(). **/
 #define GARY_INIT_SPACE_ZERO(ptr, n) do { GARY_INIT_ZERO(ptr, n); (GARY_HDR(ptr))->num_elts = 0; } while (0)
+
+/** A combination of GARY_INIT_ALLOC() and GARY_INIT_SPACE(). **/
 #define GARY_INIT_SPACE_ALLOC(ptr, n, a) do { GARY_INIT_ALLOC(ptr, n, a); (GARY_HDR(ptr))->num_elts = 0; } while (0)
+
+/** Destroy a growing array and free memory used by it. If @ptr is NULL, nothing happens. **/
 #define GARY_FREE(ptr) gary_free(ptr)
+
+/** Return the current number elements of the given growing array. **/
 #define GARY_SIZE(ptr) (GARY_HDR(ptr)->num_elts)
+
+/**
+ * Resize the given growing array to @n elements.
+ * The @ptr can change, if the array has to be re-allocated.
+ **/
 #define GARY_RESIZE(ptr, n) ((ptr) = gary_set_size((ptr), (n)))
-#define GARY_INIT_OR_RESIZE(ptr, n) (ptr) = (ptr) ? gary_set_size((ptr), (n)) : gary_init(sizeof(*(ptr)), (n), 0)
 
+/** Create a new growing array, or resize it if it already exists. **/
+#define GARY_INIT_OR_RESIZE(ptr, n) (ptr) = (ptr) ? gary_set_size((ptr), (n)) : gary_init(sizeof(*(ptr)), (n), &ucw_allocator_std)
+
+/**
+ * Push @n elements to a growing array. That is, make space for @n more elements
+ * at the end of the array and return a pointer to the first of these elements.
+ * The @ptr can change, if the array has to be re-allocated.
+ **/
 #define GARY_PUSH_MULTI(ptr, n) ({                                     \
   struct gary_hdr *_h = GARY_HDR(ptr);                                 \
   typeof(*(ptr)) *_c = &(ptr)[_h->num_elts];                           \
@@ -46,10 +88,30 @@ struct gary_hdr {
   if (_h->num_elts > _h->have_space)                                   \
     (ptr) = gary_push_helper((ptr), _n, (byte **) &_c);                        \
   _c; })
+
+/**
+ * Push a single element at the end of a growing array and return a pointer to it.
+ * The @ptr can change, if the array has to be re-allocated.
+ **/
 #define GARY_PUSH(ptr) GARY_PUSH_MULTI(ptr, 1)
 
+/**
+ * Pop @n elements from the end of a growing array.
+ * The @ptr can change, if the array has to be re-allocated.
+ **/
 #define GARY_POP_MULTI(ptr, n) GARY_HDR(ptr)->num_elts -= (n)
+
+/**
+ * Pop a single element from the end of a growing array.
+ * The @ptr can change, if the array has to be re-allocated.
+ **/
 #define GARY_POP(ptr) GARY_POP_MULTI(ptr, 1)
+
+/**
+ * Fix size of a growing array, returning all unused memory to the
+ * system (or more precisely, to the underlying allocator).
+ * The @ptr can change.
+ **/
 #define GARY_FIX(ptr) (ptr) = gary_fix((ptr))
 
 /* Internal functions */