Skip to content

Commit

Permalink
output/Registry: replace output_plugins_for_each() with a container c…
Browse files Browse the repository at this point in the history
…lass
  • Loading branch information
MaxKellermann committed Jul 12, 2024
1 parent 29747a2 commit cf5970a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/CommandLine.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ static void version()
#endif
"\n\n"
"Output plugins:\n");
audio_output_plugins_for_each(plugin)
fmt::print(" {}", plugin->name);
for (const auto &plugin : GetAllAudioOutputPlugins()) {
fmt::print(" {}", plugin.name);
}
fmt::print("\n"

#ifdef ENABLE_ENCODER
Expand Down
10 changes: 5 additions & 5 deletions src/output/Init.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ audio_output_detect()
{
LogInfo(output_domain, "Attempt to detect audio output device");

audio_output_plugins_for_each(plugin) {
if (plugin->test_default_device == nullptr)
for (const auto &plugin : GetAllAudioOutputPlugins()) {
if (plugin.test_default_device == nullptr)
continue;

FmtInfo(output_domain,
"Attempting to detect a {:?} audio device",
plugin->name);
if (ao_plugin_test_default_device(plugin))
return plugin;
plugin.name);
if (ao_plugin_test_default_device(&plugin))
return &plugin;
}

throw std::runtime_error("Unable to detect an audio device");
Expand Down
7 changes: 4 additions & 3 deletions src/output/Registry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ constinit const AudioOutputPlugin *const audio_output_plugins[] = {
const AudioOutputPlugin *
GetAudioOutputPluginByName(const char *name) noexcept
{
audio_output_plugins_for_each(plugin)
if (StringIsEqual(plugin->name, name))
return plugin;
for (const auto &plugin : GetAllAudioOutputPlugins()) {
if (StringIsEqual(plugin.name, name))
return &plugin;
}

return nullptr;
}
19 changes: 10 additions & 9 deletions src/output/Registry.hxx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project

#ifndef MPD_OUTPUT_LIST_HXX
#define MPD_OUTPUT_LIST_HXX
#pragma once

#include "util/DereferenceIterator.hxx"
#include "util/TerminatedArray.hxx"

struct AudioOutputPlugin;

extern const AudioOutputPlugin *const audio_output_plugins[];

static inline auto
GetAllAudioOutputPlugins() noexcept
{
return DereferenceContainerAdapter{TerminatedArray<const AudioOutputPlugin *const, nullptr>{audio_output_plugins}};
}

[[gnu::pure]]
const AudioOutputPlugin *
GetAudioOutputPluginByName(const char *name) noexcept;

#define audio_output_plugins_for_each(plugin) \
for (const AudioOutputPlugin *plugin, \
*const*output_plugin_iterator = &audio_output_plugins[0]; \
(plugin = *output_plugin_iterator) != nullptr; ++output_plugin_iterator)

#endif

0 comments on commit cf5970a

Please sign in to comment.