summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-05-09 10:44:38 -0600
committerTavian Barnes <tavianator@gmail.com>2011-05-09 10:44:38 -0600
commitc151fc1f157062ec273594505644f7794a047100 (patch)
tree814cb87e5582be274e264f357359f61317aa5de2 /libdimension
parent176a720808ada729661f8dea5e41045050f0e701 (diff)
downloaddimension-c151fc1f157062ec273594505644f7794a047100.tar.xz
Add dmnsn_copy_list() function.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/dimension/list.h9
-rw-r--r--libdimension/list.c17
2 files changed, 24 insertions, 2 deletions
diff --git a/libdimension/dimension/list.h b/libdimension/dimension/list.h
index e8bbfd6..70c944c 100644
--- a/libdimension/dimension/list.h
+++ b/libdimension/dimension/list.h
@@ -104,11 +104,18 @@ dmnsn_new_list(size_t obj_size)
void dmnsn_delete_list(dmnsn_list *list);
/**
+ * Copy a list.
+ * @param[in] list The list to copy.
+ * @return A list containing the same elements as \p list.
+ */
+dmnsn_list *dmnsn_copy_list(const dmnsn_list *list);
+
+/**
* Construct a list from an array.
* @param[in] array The array to copy.
* @return A list with the same contents as \p array.
*/
-dmnsn_list *dmnsn_list_from_array(const dmnsn_array *array);
+dmnsn_list *dmnsn_list_from_array(const dmnsn_array *array);
/**
* Construct an array from a list.
diff --git a/libdimension/list.c b/libdimension/list.c
index 0574744..a44e8f0 100644
--- a/libdimension/list.c
+++ b/libdimension/list.c
@@ -26,6 +26,21 @@
#include "dimension.h"
dmnsn_list *
+dmnsn_copy_list(const dmnsn_list *list)
+{
+ dmnsn_list *copy = dmnsn_new_list(list->obj_size);
+
+ for (dmnsn_list_iterator *i = dmnsn_list_first(list);
+ i != NULL;
+ i = dmnsn_list_next(i))
+ {
+ dmnsn_list_push(copy, dmnsn_list_at(i));
+ }
+
+ return copy;
+}
+
+dmnsn_list *
dmnsn_list_from_array(const dmnsn_array *array)
{
dmnsn_list *list = dmnsn_new_list(array->obj_size);
@@ -46,7 +61,7 @@ dmnsn_array_from_list(const dmnsn_list *list)
i != NULL;
i = dmnsn_list_next(i))
{
- dmnsn_array_push(array, i->ptr);
+ dmnsn_array_push(array, dmnsn_list_at(i));
}
return array;