encoder/List: replace encoder_plugins_for_each() with a container class
This commit is contained in:
parent
040c4a8560
commit
c64b4838dc
|
@ -180,8 +180,9 @@ static void version()
|
|||
#ifdef ENABLE_ENCODER
|
||||
"\n"
|
||||
"Encoder plugins:\n");
|
||||
encoder_plugins_for_each(plugin)
|
||||
fmt::print(" {}", plugin->name);
|
||||
for (const auto &plugin : GetAllEncoderPlugins()) {
|
||||
fmt::print(" {}", plugin.name);
|
||||
}
|
||||
fmt::print("\n"
|
||||
#endif
|
||||
|
||||
|
|
|
@ -46,9 +46,10 @@ constinit const EncoderPlugin *const encoder_plugins[] = {
|
|||
const EncoderPlugin *
|
||||
encoder_plugin_get(const char *name)
|
||||
{
|
||||
encoder_plugins_for_each(plugin)
|
||||
if (strcmp(plugin->name, name) == 0)
|
||||
return plugin;
|
||||
for (const auto &plugin : GetAllEncoderPlugins()) {
|
||||
if (strcmp(plugin.name, name) == 0)
|
||||
return &plugin;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_ENCODER_LIST_HXX
|
||||
#define MPD_ENCODER_LIST_HXX
|
||||
#pragma once
|
||||
|
||||
#include "util/DereferenceIterator.hxx"
|
||||
#include "util/TerminatedArray.hxx"
|
||||
|
||||
struct EncoderPlugin;
|
||||
|
||||
extern const EncoderPlugin *const encoder_plugins[];
|
||||
|
||||
#define encoder_plugins_for_each(plugin) \
|
||||
for (const EncoderPlugin *plugin, \
|
||||
*const*encoder_plugin_iterator = &encoder_plugins[0]; \
|
||||
(plugin = *encoder_plugin_iterator) != nullptr; \
|
||||
++encoder_plugin_iterator)
|
||||
static inline auto
|
||||
GetAllEncoderPlugins() noexcept
|
||||
{
|
||||
return DereferenceContainerAdapter{TerminatedArray<const EncoderPlugin *const, nullptr>{encoder_plugins}};
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up an encoder plugin by its name.
|
||||
|
@ -23,5 +25,3 @@ extern const EncoderPlugin *const encoder_plugins[];
|
|||
*/
|
||||
const EncoderPlugin *
|
||||
encoder_plugin_get(const char *name);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue