From c04ead82ce822ef6b1d9fb4ac1e7b8a7968a5169 Mon Sep 17 00:00:00 2001 From: Daniel Semkowicz via libcamera-devel Date: Wed, 13 Jul 2022 10:43:11 +0200 Subject: ipa: module: Add getAlgorithm() method This function allows to get pointer to the algorithm of specific type from the list of loaded algorithms. Signed-off-by: Daniel Semkowicz --- src/ipa/libipa/module.cpp | 7 +++++++ src/ipa/libipa/module.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp index 77352104..7c0680fd 100644 --- a/src/ipa/libipa/module.cpp +++ b/src/ipa/libipa/module.cpp @@ -83,6 +83,13 @@ namespace ipa { * \return The list of instantiated algorithms */ +/** + * \fn Module::getAlgorithm() + * \brief Find and return the algorithm of requested type + * \tparam AlgoType Algorithm type you want to retrieve + * \return Pointer to the algorithm if found, else nullptr + */ + /** * \fn Module::createAlgorithms() * \brief Create algorithms from YAML configuration data diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index 4149a353..c4974635 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,22 @@ public: return algorithms_; } + template + AlgoType *getAlgorithm() const + { + auto isSameType = [](const std::unique_ptr> &algoPtr) { + return typeid(*algoPtr.get()) == typeid(AlgoType); + }; + + auto result = std::find_if(begin(algorithms_), end(algorithms_), isSameType); + + if (result != std::end(algorithms_)) { + return static_cast(result->get()); + } else { + return nullptr; + } + } + int createAlgorithms(Context &context, const YamlObject &algorithms) { const auto &list = algorithms.asList(); -- cgit v1.2.1