From bd79354f32266f60f94150bbf60e537ed1ba3dd0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 26 Aug 2021 17:24:14 +0200 Subject: [PATCH] filter/TwoFilters: add ChainFilters() --- src/filter/plugins/TwoFilters.hxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/filter/plugins/TwoFilters.hxx b/src/filter/plugins/TwoFilters.hxx index 28fa31948..d5fa77cd2 100644 --- a/src/filter/plugins/TwoFilters.hxx +++ b/src/filter/plugins/TwoFilters.hxx @@ -65,4 +65,23 @@ public: std::unique_ptr Open(AudioFormat &audio_format) override; }; +/** + * Create a #PreparedTwoFilters instance, but only if both parameters + * are not nullptr. + */ +template +static std::unique_ptr +ChainFilters(F &&first, S &&second, N &&second_name) noexcept +{ + if (!second) + return std::forward(first); + + if (!first) + return std::forward(second); + + return std::make_unique(std::forward(first), + std::forward(second), + std::forward(second_name)); +} + #endif