diff options
author | Max Kellermann <max@duempel.org> | 2013-02-01 18:11:24 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-02-01 18:14:06 +0100 |
commit | 12613356fc64e8ed94e709accfb1f3b5e3b5bd33 (patch) | |
tree | a1afd2dec3fe1058266b3198b4198869e53a327d /src/filter | |
parent | 3894450b10baeaa17c871cb5dc1a0961e0726fae (diff) | |
download | mpd-12613356fc64e8ed94e709accfb1f3b5e3b5bd33.tar.gz mpd-12613356fc64e8ed94e709accfb1f3b5e3b5bd33.tar.xz mpd-12613356fc64e8ed94e709accfb1f3b5e3b5bd33.zip |
filter/Chain: use std::forward_list instead of GSList
Diffstat (limited to 'src/filter')
-rw-r--r-- | src/filter/ChainFilterPlugin.cxx | 61 |
1 files changed, 20 insertions, 41 deletions
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 <glib.h> +#include <list> + #include <assert.h> struct ChainFilter { /** the base class */ struct filter base; - GSList *children; + std::list<struct filter *> children; - ChainFilter():children(nullptr) { + ChainFilter() { filter_init(&base, &chain_filter_plugin); } + + ~ChainFilter() { + for (auto i : children) + filter_free(i); + } }; static inline GQuark @@ -56,21 +63,10 @@ chain_filter_init(G_GNUC_UNUSED const struct config_param *param, } 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 */ @@ -149,19 +137,12 @@ chain_filter_open(struct filter *_filter, struct audio_format *in_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); } |