diff options
author | Max Kellermann <max@duempel.org> | 2013-12-29 16:18:33 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-29 16:59:57 +0100 |
commit | df4db509047766235063f98f0ddd61cbf221fea5 (patch) | |
tree | 15c755558141ec7e0d5945cd8506bf8345c3e2d6 /src | |
parent | decc4002a02d07c12b360929dc62b5ffcae37582 (diff) | |
download | mpd-df4db509047766235063f98f0ddd61cbf221fea5.tar.gz mpd-df4db509047766235063f98f0ddd61cbf221fea5.tar.xz mpd-df4db509047766235063f98f0ddd61cbf221fea5.zip |
DecoderList: add function decoder_plugins_supports_suffix()
Replaces decoder_plugin_from_suffix().
Diffstat (limited to '')
-rw-r--r-- | src/DecoderList.cxx | 45 | ||||
-rw-r--r-- | src/DecoderList.hxx | 21 | ||||
-rw-r--r-- | src/SongUpdate.cxx | 4 | ||||
-rw-r--r-- | src/UpdateSong.cxx | 4 |
4 files changed, 20 insertions, 54 deletions
diff --git a/src/DecoderList.cxx b/src/DecoderList.cxx index dbad3dd57..b077da035 100644 --- a/src/DecoderList.cxx +++ b/src/DecoderList.cxx @@ -118,43 +118,6 @@ static constexpr unsigned num_decoder_plugins = /** which plugins have been initialized successfully? */ bool decoder_plugins_enabled[num_decoder_plugins]; -static unsigned -decoder_plugin_index(const struct DecoderPlugin *plugin) -{ - unsigned i = 0; - - while (decoder_plugins[i] != plugin) - ++i; - - return i; -} - -static unsigned -decoder_plugin_next_index(const struct DecoderPlugin *plugin) -{ - return plugin == 0 - ? 0 /* start with first plugin */ - : decoder_plugin_index(plugin) + 1; -} - -const struct DecoderPlugin * -decoder_plugin_from_suffix(const char *suffix, - const struct DecoderPlugin *plugin) -{ - if (suffix == nullptr) - return nullptr; - - for (unsigned i = decoder_plugin_next_index(plugin); - decoder_plugins[i] != nullptr; ++i) { - plugin = decoder_plugins[i]; - if (decoder_plugins_enabled[i] && - plugin->SupportsSuffix(suffix)) - return plugin; - } - - return nullptr; -} - const struct DecoderPlugin * decoder_plugin_from_name(const char *name) { @@ -213,3 +176,11 @@ void decoder_plugin_deinit_all(void) plugin.Finish(); }); } + +bool +decoder_plugins_supports_suffix(const char *suffix) +{ + return decoder_plugins_try([suffix](const DecoderPlugin &plugin){ + return plugin.SupportsSuffix(suffix); + }); +} diff --git a/src/DecoderList.hxx b/src/DecoderList.hxx index 3cfaaae7b..2ca8eb794 100644 --- a/src/DecoderList.hxx +++ b/src/DecoderList.hxx @@ -20,6 +20,8 @@ #ifndef MPD_DECODER_LIST_HXX #define MPD_DECODER_LIST_HXX +#include "Compiler.h" + struct DecoderPlugin; extern const struct DecoderPlugin *const decoder_plugins[]; @@ -27,17 +29,6 @@ extern bool decoder_plugins_enabled[]; /* interface for using plugins */ -/** - * Find the next enabled decoder plugin which supports the specified suffix. - * - * @param suffix the file name suffix - * @param plugin the previous plugin, or nullptr to find the first plugin - * @return a plugin, or nullptr if none matches - */ -const struct DecoderPlugin * -decoder_plugin_from_suffix(const char *suffix, - const struct DecoderPlugin *plugin); - const struct DecoderPlugin * decoder_plugin_from_name(const char *name); @@ -86,4 +77,12 @@ decoder_plugins_for_each_enabled(F f) f(*decoder_plugins[i]); } +/** + * Is there at least once #DecoderPlugin that supports the specified + * file name suffix? + */ +gcc_pure gcc_nonnull_all +bool +decoder_plugins_supports_suffix(const char *suffix); + #endif diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx index 377b2fb7c..1e1bb2ff5 100644 --- a/src/SongUpdate.cxx +++ b/src/SongUpdate.cxx @@ -107,7 +107,6 @@ bool Song::UpdateFileInArchive() { const char *suffix; - const struct DecoderPlugin *plugin; assert(IsFile()); @@ -117,8 +116,7 @@ Song::UpdateFileInArchive() if (suffix == nullptr) return false; - plugin = decoder_plugin_from_suffix(suffix, nullptr); - if (plugin == nullptr) + if (!decoder_plugins_supports_suffix(suffix)) return false; delete tag; diff --git a/src/UpdateSong.cxx b/src/UpdateSong.cxx index 4101d6231..dc49c7a84 100644 --- a/src/UpdateSong.cxx +++ b/src/UpdateSong.cxx @@ -105,9 +105,7 @@ update_song_file(Directory &directory, const char *name, const char *suffix, const struct stat *st) { - const struct DecoderPlugin *plugin = - decoder_plugin_from_suffix(suffix, nullptr); - if (plugin == nullptr) + if (!decoder_plugins_supports_suffix(suffix)) return false; update_song_file2(directory, name, st, suffix); |