diff options
author | lloyd <[email protected]> | 2008-11-11 18:18:03 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-11 18:18:03 +0000 |
commit | 1befa604ad62332aab1729d023c89556e63332c7 (patch) | |
tree | fa0746f956f414d0e844f6711e7762e2e5a1d9fb /src/algo_factory/algo_cache.h | |
parent | 237258e42f4b1b8c01d91518270c4a9c59a0dc47 (diff) |
Fix algo_cache to track aliases, all tests pass
Diffstat (limited to 'src/algo_factory/algo_cache.h')
-rw-r--r-- | src/algo_factory/algo_cache.h | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index ab6778d14..c6d2ebdac 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -18,13 +18,17 @@ class Algorithm_Cache { public: const T* get(const SCAN_Name& request); - void add(T* algo, const std::string& provider); + void add(T* algo, + const std::string& requested_name, + const std::string& provider); Algorithm_Cache(Mutex* m) : mutex(m) {} ~Algorithm_Cache(); private: Mutex* mutex; + std::map<std::string, std::string> aliases; std::map<std::string, std::map<std::string, T*> > algorithms; + typedef typename std::map<std::string, std::map<std::string, T*> >::iterator algorithms_iterator; typedef typename std::map<std::string, T*>::iterator provider_iterator; }; @@ -39,10 +43,20 @@ const T* Algorithm_Cache<T>::get(const SCAN_Name& request) algorithms_iterator algo = algorithms.find(request.as_string()); + // Not found? Check if a known alias + if(algo == algorithms.end()) + { + std::map<std::string, std::string>::const_iterator alias = + aliases.find(request.as_string()); + + if(alias != aliases.end()) + algo = algorithms.find(alias->second); + } + if(algo == algorithms.end()) return 0; - const std::string requested_provider = request.providers_string(); + const std::string requested_provider = request.provider(); if(requested_provider != "") { @@ -71,7 +85,9 @@ const T* Algorithm_Cache<T>::get(const SCAN_Name& request) * Add an implementation to the cache */ template<typename T> -void Algorithm_Cache<T>::add(T* algo, const std::string& provider) +void Algorithm_Cache<T>::add(T* algo, + const std::string& requested_name, + const std::string& provider) { if(!algo) return; @@ -80,6 +96,9 @@ void Algorithm_Cache<T>::add(T* algo, const std::string& provider) delete algorithms[algo->name()][provider]; algorithms[algo->name()][provider] = algo; + + if(algo->name() != requested_name && aliases.find(requested_name) == aliases.end()) + aliases[requested_name] = algo->name(); } /** |