input/Registry: replace the input_plugins_for_each macros with a container class
This commit is contained in:
parent
49edb16de0
commit
fb87e19bae
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<const InputPlugin *const, nullptr>{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
|
||||
|
|
|
@ -9,12 +9,11 @@
|
|||
std::unique_ptr<RemoteTagScanner>
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
17
src/ls.cxx
17
src/ls.cxx
|
@ -21,10 +21,12 @@ void print_supported_uri_schemes_to_fp(FILE *fp)
|
|||
fmt::print(fp, " file://");
|
||||
#endif
|
||||
std::set<std::string, std::less<>> 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<std::string, std::less<>> 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))
|
||||
|
|
Loading…
Reference in New Issue