1 /**** 2 DIAMOND protein aligner 3 Copyright (C) 2020 QIAGEN A/S (Aarhus, Denmark) 4 Code developed by Patrick Ettenhuber <patrick.ettenhuber@qiagen.com> 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 ****/ 19 20 #pragma once 21 #include "cluster.h" 22 #include "mcl.h" 23 #include "multi_step_cluster.h" 24 25 namespace Workflow { namespace Cluster{ 26 class ClusterRegistryStatic{ 27 std::map<std::string, ClusteringAlgorithm*> regMap; 28 public: ClusterRegistryStatic()29 ClusterRegistryStatic(){ 30 // To include new clustering algorithms add them into regMap 31 regMap[MultiStep::get_key()] = new MultiStep(); 32 regMap[MCL::get_key()] = new MCL(); 33 } ~ClusterRegistryStatic()34 ~ClusterRegistryStatic(){ 35 for(auto it = regMap.begin(); it != regMap.end(); it++){ 36 delete it->second; 37 it->second = nullptr; 38 } 39 } get(string key)40 ClusteringAlgorithm* get(string key) const{ 41 auto ca = regMap.find(key); 42 if(ca == regMap.end()){ 43 throw std::runtime_error("Clustering algorithm not found."); 44 } 45 return ca->second; 46 } has(string key)47 bool has(string key) const{ 48 return regMap.find(key) != regMap.end(); 49 } getKeys()50 vector<string> getKeys() const{ 51 vector<string> keys; 52 for(auto it = regMap.begin(); it != regMap.end(); it++){ 53 keys.push_back(it->first); 54 } 55 return keys; 56 } 57 58 }; 59 60 class ClusterRegistry{ 61 private: 62 static const ClusterRegistryStatic reg; 63 public: get(string key)64 static ClusteringAlgorithm* get(string key){ 65 return reg.get(key); 66 } has(string key)67 static bool has(string key){ 68 return reg.has(key); 69 } getKeys()70 static vector<string> getKeys(){ 71 return reg.getKeys(); 72 } 73 }; 74 75 }} 76