aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/engine.h16
-rw-r--r--src/eng_base.cpp13
2 files changed, 17 insertions, 12 deletions
diff --git a/include/engine.h b/include/engine.h
index 9009f01fb..76147f347 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -28,7 +28,7 @@ class Engine
{
public:
virtual T* get(const std::string&) const = 0;
- virtual void add(T* algo) const = 0;
+ virtual void add(T* algo, const std::string& = "") const = 0;
virtual ~Algorithm_Cache() {}
};
@@ -75,14 +75,18 @@ class Engine
find_bc_pad(const std::string&) const;
template<typename T>
- T* lookup_algo(const Algorithm_Cache<T>* cache,
- const std::string& name,
- const Engine* engine,
- T* (Engine::*find)(const std::string& name) const) const
+ const T* lookup_algo(const Algorithm_Cache<T>* cache,
+ const std::string& name,
+ const Engine* engine,
+ T* (Engine::*find)(const std::string&) const) const
{
T* algo = cache->get(name);
if(!algo)
- cache->add(algo = (engine->*find)(name));
+ {
+ algo = (engine->*find)(name);
+ if(algo)
+ cache->add(algo, name);
+ }
return algo;
}
diff --git a/src/eng_base.cpp b/src/eng_base.cpp
index a726fd762..c8aa4430c 100644
--- a/src/eng_base.cpp
+++ b/src/eng_base.cpp
@@ -25,17 +25,19 @@ class Algorithm_Cache_Impl : public Engine::Algorithm_Cache<T>
return search_map(mappings, name);
}
- void add(T* algo) const
+ void add(T* algo, const std::string& index_name = "") const
{
if(!algo)
return;
Mutex_Holder lock(mutex);
- const std::string algo_name = algo->name();
- if(mappings.find(algo_name) != mappings.end())
- delete mappings[algo_name];
- mappings[algo_name] = algo;
+ const std::string name =
+ (index_name != "" ? index_name : algo->name());
+
+ if(mappings.find(name) != mappings.end())
+ delete mappings[name];
+ mappings[name] = algo;
}
Algorithm_Cache_Impl()
@@ -59,7 +61,6 @@ class Algorithm_Cache_Impl : public Engine::Algorithm_Cache<T>
mutable std::map<std::string, T*> mappings;
};
-
}
/*************************************************