2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 * @short_description: A utility function to filter GLists.
25 * <title>Filtering a list</title>
28 * GstObject *result = NULL;
30 * node = gst_filter_run (list, (GstFilterFunc) my_filter, TRUE, NULL);
32 * result = GST_OBJECT (node->data);
33 * gst_object_ref (result);
39 #include "gst_private.h"
40 #include <gst/gstfilter.h>
44 * @list: a linked list
45 * @func: (scope call): the function to execute for each item
46 * @first: flag to stop execution after a successful item
47 * @user_data: (closure): user data
49 * Iterates over the elements in @list, calling @func with the
50 * list item data for each item. If @func returns TRUE, @data is
51 * prepended to the list of results returned. If @first is true,
52 * the search is halted after the first result is found.
54 * Since gst_filter_run() knows nothing about the type of @data, no
55 * reference will be taken (if @data refers to an object) and no copy of
56 * @data wil be made in any other way when prepending @data to the list of
59 * Returns: (transfer container): the list of results. Free with g_list_free()
60 * when no longer needed (the data contained in the list is a flat copy
61 * and does need to be unreferenced or freed).
63 #ifndef GST_REMOVE_DEPRECATED
64 #ifdef GST_DISABLE_DEPRECATED
65 typedef gboolean (*GstFilterFunc) (gpointer obj, gpointer user_data);
66 GList *gst_filter_run (const GList * list, GstFilterFunc func, gboolean first,
70 gst_filter_run (const GList * list, GstFilterFunc func, gboolean first,
73 const GList *walk = list;
78 gpointer data = walk->data;
80 walk = g_list_next (walk);
83 res = func (data, user_data);
86 result = g_list_prepend (result, data);
95 #endif /* GST_REMOVE_DEPRECATED */