From 12613356fc64e8ed94e709accfb1f3b5e3b5bd33 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 1 Feb 2013 18:11:24 +0100 Subject: filter/Chain: use std::forward_list instead of GSList --- src/filter/ChainFilterPlugin.cxx | 61 +++++++++++++--------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) (limited to 'src/filter') diff --git a/src/filter/ChainFilterPlugin.cxx b/src/filter/ChainFilterPlugin.cxx index 51eb4b6f6..dabfb0ae6 100644 --- a/src/filter/ChainFilterPlugin.cxx +++ b/src/filter/ChainFilterPlugin.cxx @@ -27,17 +27,24 @@ #include +#include + #include struct ChainFilter { /** the base class */ struct filter base; - GSList *children; + std::list children; - ChainFilter():children(nullptr) { + ChainFilter() { filter_init(&base, &chain_filter_plugin); } + + ~ChainFilter() { + for (auto i : children) + filter_free(i); + } }; static inline GQuark @@ -55,22 +62,11 @@ chain_filter_init(G_GNUC_UNUSED const struct config_param *param, return &chain->base; } -static void -chain_free_child(gpointer data, G_GNUC_UNUSED gpointer user_data) -{ - struct filter *filter = (struct filter *)data; - - filter_free(filter); -} - static void chain_filter_finish(struct filter *_filter) { ChainFilter *chain = (ChainFilter *)_filter; - g_slist_foreach(chain->children, chain_free_child, NULL); - g_slist_free(chain->children); - delete chain; } @@ -81,23 +77,17 @@ chain_filter_finish(struct filter *_filter) static void chain_close_until(ChainFilter *chain, const struct filter *until) { - GSList *i = chain->children; - - while (true) { - /* this assertion fails if #until does not exist - (anymore) */ - assert(i != NULL); - - if (i->data == until) + for (auto filter : chain->children) { + if (filter == until) /* don't close this filter */ - break; + return; /* close this filter */ - struct filter *filter = (struct filter *)i->data; filter_close(filter); - - i = g_slist_next(i); } + + /* this assertion fails if #until does not exist (anymore) */ + assert(false); } static const struct audio_format * @@ -133,9 +123,7 @@ chain_filter_open(struct filter *_filter, struct audio_format *in_audio_format, ChainFilter *chain = (ChainFilter *)_filter; const struct audio_format *audio_format = in_audio_format; - for (GSList *i = chain->children; i != NULL; i = g_slist_next(i)) { - struct filter *filter = (struct filter *)i->data; - + for (auto filter : chain->children) { audio_format = chain_open_child(filter, audio_format, error_r); if (audio_format == NULL) { /* rollback, close all children */ @@ -148,20 +136,13 @@ chain_filter_open(struct filter *_filter, struct audio_format *in_audio_format, return audio_format; } -static void -chain_close_child(gpointer data, G_GNUC_UNUSED gpointer user_data) -{ - struct filter *filter = (struct filter *)data; - - filter_close(filter); -} - static void chain_filter_close(struct filter *_filter) { ChainFilter *chain = (ChainFilter *)_filter; - g_slist_foreach(chain->children, chain_close_child, NULL); + for (auto filter : chain->children) + filter_close(filter); } static const void * @@ -171,9 +152,7 @@ chain_filter_filter(struct filter *_filter, { ChainFilter *chain = (ChainFilter *)_filter; - for (GSList *i = chain->children; i != NULL; i = g_slist_next(i)) { - struct filter *filter = (struct filter *)i->data; - + for (auto filter : chain->children) { /* feed the output of the previous filter as input into the current one */ src = filter_filter(filter, src, src_size, &src_size, error_r); @@ -210,5 +189,5 @@ filter_chain_append(struct filter *_chain, struct filter *filter) { ChainFilter *chain = (ChainFilter *)_chain; - chain->children = g_slist_append(chain->children, filter); + chain->children.push_back(filter); } -- cgit v1.2.3