input/Registry: replace the input_plugins_for_each macros with a container class
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user