aboutsummaryrefslogtreecommitdiffstats
path: root/src/DecoderList.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-21 22:02:19 +0200
committerMax Kellermann <max@duempel.org>2013-10-21 22:02:19 +0200
commit74904b9cf2fe163c0ae1d53fb73b19826b256812 (patch)
tree5c7ee7cc1358b897d5734c14bba2f8c704e1c861 /src/DecoderList.hxx
parent82059645f18e4a8aa734e0a376d10bb52fc1cc7d (diff)
downloadmpd-74904b9cf2fe163c0ae1d53fb73b19826b256812.tar.gz
mpd-74904b9cf2fe163c0ae1d53fb73b19826b256812.tar.xz
mpd-74904b9cf2fe163c0ae1d53fb73b19826b256812.zip
DecoderList: reimplement _for_each() with function object
Diffstat (limited to 'src/DecoderList.hxx')
-rw-r--r--src/DecoderList.hxx38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/DecoderList.hxx b/src/DecoderList.hxx
index c199caa4f..51aeb1d71 100644
--- a/src/DecoderList.hxx
+++ b/src/DecoderList.hxx
@@ -25,16 +25,6 @@ struct DecoderPlugin;
extern const struct DecoderPlugin *const decoder_plugins[];
extern bool decoder_plugins_enabled[];
-#define decoder_plugins_for_each(plugin) \
- for (const struct DecoderPlugin *plugin, \
- *const*decoder_plugin_iterator = &decoder_plugins[0]; \
- (plugin = *decoder_plugin_iterator) != nullptr; \
- ++decoder_plugin_iterator)
-
-#define decoder_plugins_for_each_enabled(plugin) \
- decoder_plugins_for_each(plugin) \
- if (decoder_plugins_enabled[decoder_plugin_iterator - decoder_plugins])
-
/* interface for using plugins */
/**
@@ -60,4 +50,32 @@ void decoder_plugin_init_all(void);
/* this is where we "unload" all the "plugins" */
void decoder_plugin_deinit_all(void);
+template<typename F>
+static inline const DecoderPlugin *
+decoder_plugins_find(F f)
+{
+ for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
+ if (decoder_plugins_enabled[i] && f(*decoder_plugins[i]))
+ return decoder_plugins[i];
+
+ return nullptr;
+}
+
+template<typename F>
+static inline void
+decoder_plugins_for_each(F f)
+{
+ for (auto i = decoder_plugins; *i != nullptr; ++i)
+ f(**i);
+}
+
+template<typename F>
+static inline void
+decoder_plugins_for_each_enabled(F f)
+{
+ for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
+ if (decoder_plugins_enabled[i])
+ f(*decoder_plugins[i]);
+}
+
#endif