From 74904b9cf2fe163c0ae1d53fb73b19826b256812 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 21 Oct 2013 22:02:19 +0200 Subject: DecoderList: reimplement _for_each() with function object --- src/DecoderList.hxx | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/DecoderList.hxx') 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 +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 +static inline void +decoder_plugins_for_each(F f) +{ + for (auto i = decoder_plugins; *i != nullptr; ++i) + f(**i); +} + +template +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 -- cgit v1.2.3