}
// output properties of a structure to a file.
-// list_foreach func, so "out" is the last parameter!
+// list_foreach_fn_2 func, so "out" is the last parameter!
static void caveset_save_cave_func(GdCave *cave, GdPtrArray *out)
{
GdCave *default_cave;
gd_caveset_data_free(default_caveset);
gd_ptr_array_add(out, getStringCopy("Levels=5"));
- list_foreach(gd_caveset, (list_fn)caveset_save_cave_func, out);
+ list_foreach_fn_2(gd_caveset, (list_fn_2) caveset_save_cave_func, out);
gd_ptr_array_add(out, getStringCopy("[/game]"));
gd_ptr_array_add(out, getStringCopy("[/BDCFF]"));
gd_cave_map_free(cave->hammered_reappear);
// free objects
- list_foreach(cave->objects, (list_fn) free, NULL);
+ list_foreach_fn_1(cave->objects, (list_fn_1) free);
list_free(cave->objects);
// free replays
- list_foreach(cave->replays, (list_fn) gd_replay_free, NULL);
+ list_foreach_fn_1(cave->replays, (list_fn_1) gd_replay_free);
list_free(cave->replays);
// freeing main pointer
gd_cave_free(rendered);
// forget objects
- list_foreach(cave->objects, (list_fn) free, NULL);
+ list_foreach_fn_1(cave->objects, (list_fn_1) free);
cave->objects = NULL;
}
{
if (gd_caveset)
{
- list_foreach(gd_caveset, (list_fn) gd_cave_free, NULL);
+ list_foreach_fn_1(gd_caveset, (list_fn_1) gd_cave_free);
list_free(gd_caveset);
gd_caveset = NULL;
}
}
/**
- * list_foreach:
+ * list_foreach_fn_1:
+ * @list: a #List, this must point to the top of the list
+ * @func: (scope call): the function to call with each element's data
+ *
+ * Calls a function for each element of a #List.
+ *
+ * It is safe for @func to remove the element from @list, but it must
+ * not modify any part of the list after that element.
+ */
+/**
+ * list_fn_1:
+ * @data: the element's data
+ *
+ * Specifies the type of functions passed to list_foreach_fn_1().
+ */
+void
+list_foreach_fn_1 (List *list, list_fn_1 func)
+{
+ while (list)
+ {
+ List *next = list->next;
+
+ (*func) (list->data);
+ list = next;
+ }
+}
+
+/**
+ * list_foreach_fn_2:
* @list: a #List, this must point to the top of the list
* @func: (scope call): the function to call with each element's data
* @user_data: user data to pass to the function
* not modify any part of the list after that element.
*/
/**
- * list_fn:
+ * list_fn_2:
* @data: the element's data
- * @user_data: user data passed to list_foreach() or slist_foreach()
+ * @user_data: user data passed to list_foreach_fn_2()
*
- * Specifies the type of functions passed to list_foreach() and
- * slist_foreach().
+ * Specifies the type of functions passed to list_foreach_fn_2().
*/
void
-list_foreach (List *list, list_fn func, void *user_data)
+list_foreach_fn_2 (List *list, list_fn_2 func, void *user_data)
{
while (list)
{
};
-typedef void (*list_fn) (void *data, void *userdata);
+typedef void (*list_fn_1) (void *data);
+typedef void (*list_fn_2) (void *data, void *userdata);
typedef void *(*list_copy_fn) (const void *data, void *userdata);
/* Doubly linked lists */
List *list_last(List *list);
List *list_first(List *list);
unsigned int list_length(List *list);
-void list_foreach(List *list, list_fn func, void *user_data);
+void list_foreach_fn_1(List *list, list_fn_1 func);
+void list_foreach_fn_2(List *list, list_fn_2 func, void *user_data);
void *list_nth_data(List *list, unsigned int n);
#define list_previous(list) ((list) ? (((List *)(list))->prev) : NULL)