diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx index 4dfa3492a..54827b2a8 100644 --- a/src/CommandLine.cxx +++ b/src/CommandLine.cxx @@ -212,8 +212,8 @@ static void version() " archive" #endif ); - input_plugins_for_each(plugin) - fmt::print(" {}", plugin->name); + for (const InputPlugin &plugin : GetAllInputPlugins()) + fmt::print(" {}", plugin.name); fmt::print("\n\n" "Playlist plugins:\n"); diff --git a/src/input/Init.cxx b/src/input/Init.cxx index cb6ed2366..9a115512e 100644 --- a/src/input/Init.cxx +++ b/src/input/Init.cxx @@ -73,7 +73,7 @@ input_stream_global_init(const ConfigData &config, EventLoop &event_loop) void input_stream_global_finish() noexcept { - input_plugins_for_each_enabled(plugin) - if (plugin->finish != nullptr) - plugin->finish(); + for (const auto &plugin : GetEnabledInputPlugins()) + if (plugin.finish != nullptr) + plugin.finish(); } diff --git a/src/input/Open.cxx b/src/input/Open.cxx index 19d76d731..b5656688b 100644 --- a/src/input/Open.cxx +++ b/src/input/Open.cxx @@ -20,12 +20,11 @@ InputStream::Open(const char *url, Mutex &mutex) return OpenLocalInputStream(path, mutex); } - input_plugins_for_each_enabled(plugin) { - if (!plugin->SupportsUri(url)) + for (const auto &plugin : GetEnabledInputPlugins()) { + if (!plugin.SupportsUri(url)) continue; - auto is = plugin->open(url, mutex); - if (is != nullptr) + if (auto is = plugin.open(url, mutex)) return input_rewind_open(std::move(is)); } diff --git a/src/input/Registry.cxx b/src/input/Registry.cxx index 7e744a3d8..a574592e7 100644 --- a/src/input/Registry.cxx +++ b/src/input/Registry.cxx @@ -72,10 +72,11 @@ bool input_plugins_enabled[std::max(n_input_plugins, std::size_t(1))]; bool HasRemoteTagScanner(const char *uri) noexcept { - input_plugins_for_each_enabled(plugin) - if (plugin->scan_tags != nullptr && - plugin->SupportsUri(uri)) + for (const auto &plugin : GetEnabledInputPlugins()) { + if (plugin.scan_tags != nullptr && + plugin.SupportsUri(uri)) return true; + } return false; } diff --git a/src/input/Registry.hxx b/src/input/Registry.hxx index 469fb6d4d..f17934b4e 100644 --- a/src/input/Registry.hxx +++ b/src/input/Registry.hxx @@ -1,8 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_INPUT_REGISTRY_HXX -#define MPD_INPUT_REGISTRY_HXX +#pragma once + +#include "util/DereferenceIterator.hxx" +#include "util/FilteredContainer.hxx" +#include "util/TerminatedArray.hxx" /** * NULL terminated list of all input plugins which were enabled at @@ -12,18 +15,19 @@ extern const struct InputPlugin *const input_plugins[]; extern bool input_plugins_enabled[]; -#define input_plugins_for_each(plugin) \ - for (const InputPlugin *plugin, \ - *const*input_plugin_iterator = &input_plugins[0]; \ - (plugin = *input_plugin_iterator) != NULL; \ - ++input_plugin_iterator) +static inline auto +GetAllInputPlugins() noexcept +{ + return DereferenceContainerAdapter{TerminatedArray{input_plugins}}; +} -#define input_plugins_for_each_enabled(plugin) \ - input_plugins_for_each(plugin) \ - if (input_plugins_enabled[input_plugin_iterator - input_plugins]) +static inline auto +GetEnabledInputPlugins() noexcept +{ + const auto all = GetAllInputPlugins(); + return FilteredContainer{all.begin(), all.end(), input_plugins_enabled}; +} [[gnu::pure]] bool HasRemoteTagScanner(const char *uri) noexcept; - -#endif diff --git a/src/input/ScanTags.cxx b/src/input/ScanTags.cxx index ffd0a0f20..224c22c2b 100644 --- a/src/input/ScanTags.cxx +++ b/src/input/ScanTags.cxx @@ -9,12 +9,11 @@ std::unique_ptr InputScanTags(const char *uri, RemoteTagHandler &handler) { - input_plugins_for_each_enabled(plugin) { - if (plugin->scan_tags == nullptr || !plugin->SupportsUri(uri)) + for (const auto &plugin : GetEnabledInputPlugins()) { + if (plugin.scan_tags == nullptr || !plugin.SupportsUri(uri)) continue; - auto scanner = plugin->scan_tags(uri, handler); - if (scanner) + if (auto scanner = plugin.scan_tags(uri, handler)) return scanner; } diff --git a/src/ls.cxx b/src/ls.cxx index 33e3268f6..f56816172 100644 --- a/src/ls.cxx +++ b/src/ls.cxx @@ -21,10 +21,12 @@ void print_supported_uri_schemes_to_fp(FILE *fp) fmt::print(fp, " file://"); #endif std::set> protocols; - input_plugins_for_each(plugin) - plugin->ForeachSupportedUri([&](const char* uri) { + + for (const auto &plugin : GetAllInputPlugins()) { + plugin.ForeachSupportedUri([&](const char* uri) { protocols.emplace(uri); }); + } for (const DecoderPlugin &plugin : GetAllDecoderPlugins()) { if (plugin.protocols != nullptr) @@ -41,10 +43,12 @@ void print_supported_uri_schemes(Response &r) { std::set> protocols; - input_plugins_for_each_enabled(plugin) - plugin->ForeachSupportedUri([&](const char* uri) { + + for (const auto &plugin : GetEnabledInputPlugins()) { + plugin.ForeachSupportedUri([&](const char* uri) { protocols.emplace(uri); }); + } for (const auto &plugin : GetEnabledDecoderPlugins()) { if (plugin.protocols != nullptr) @@ -61,9 +65,10 @@ uri_supported_scheme(const char *uri) noexcept { assert(uri_has_scheme(uri)); - input_plugins_for_each_enabled(plugin) - if (plugin->SupportsUri(uri)) + for (const auto &plugin : GetEnabledInputPlugins()) { + if (plugin.SupportsUri(uri)) return true; + } for (const auto &plugin : GetEnabledDecoderPlugins()) { if (plugin.SupportsUri(uri))