@@ -18,6 +18,9 @@ class ValueNode;
namespace ipa {
+template<typename _Module>
+class AlgorithmFactoryBase;
+
template<typename _Module>
class Algorithm
{
@@ -59,6 +62,15 @@ public:
[[maybe_unused]] ControlList &metadata)
{
}
+
+ const std::string &name() const
+ {
+ return name_;
+ }
+
+private:
+ std::string name_;
+ friend class AlgorithmFactoryBase<_Module>;
};
template<typename _Module>
@@ -77,6 +89,11 @@ public:
virtual std::unique_ptr<Algorithm<_Module>> create() const = 0;
+ void injectName(Algorithm<_Module> *instance) const
+ {
+ instance->name_ = name();
+ }
+
private:
std::string name_;
};
@@ -94,7 +111,9 @@ public:
std::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override
{
- return std::make_unique<_Algorithm>();
+ auto instance = std::make_unique<_Algorithm>();
+ AlgorithmFactoryBase<typename _Algorithm::Module>::injectName(instance.get());
+ return instance;
}
};
When algorithms are handled it is helpful to be able to deduce the name an algorithm was registered with from the algorithm instance. Allow that by injecting the name into the instance after construction. ToDo: - We could as well force every algorithm to implement name() and could then drop this clunky logic. But maybe there are other reasons for this kind of registry. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> --- src/ipa/libipa/algorithm.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)