src/iguana/algorithms/AlgorithmFactory.cc
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Algorithm.h" | ||
| 2 | |||
| 3 | namespace iguana { | ||
| 4 | |||
| 5 | std::unordered_map<std::string, AlgorithmFactory::algo_creator_t> AlgorithmFactory::s_creators; | ||
| 6 | std::unordered_map<std::string, std::vector<std::string>> AlgorithmFactory::s_bank_to_algos; | ||
| 7 | std::unordered_map<std::string, std::vector<std::string>> AlgorithmFactory::s_algo_to_banks; | ||
| 8 | |||
| 9 | 1136 | bool AlgorithmFactory::Register(std::string const& algo_name, algo_creator_t creator, std::vector<std::string> const new_banks) noexcept | |
| 10 | { | ||
| 11 |
1/2✓ Branch 5 → 6 taken 1136 times.
✗ Branch 5 → 26 not taken.
|
1136 | if(auto it = s_creators.find(algo_name); it == s_creators.end()) { |
| 12 | 2272 | s_creators.insert({algo_name, creator}); | |
| 13 | 2272 | s_algo_to_banks.insert({algo_name, new_banks}); | |
| 14 |
2/2✓ Branch 25 → 13 taken 336 times.
✓ Branch 25 → 26 taken 1136 times.
|
1472 | for(auto const& new_bank : new_banks) { |
| 15 |
1/2✓ Branch 16 → 17 taken 336 times.
✗ Branch 16 → 22 not taken.
|
336 | if(auto it = s_bank_to_algos.find(new_bank); it == s_bank_to_algos.end()) |
| 16 | 672 | s_bank_to_algos.insert({new_bank, {}}); | |
| 17 | 336 | s_bank_to_algos.at(new_bank).push_back(algo_name); | |
| 18 | } | ||
| 19 | return true; | ||
| 20 | } | ||
| 21 | return false; | ||
| 22 | } | ||
| 23 | |||
| 24 | 60 | algo_t AlgorithmFactory::Create(std::string const& algo_name) | |
| 25 | { | ||
| 26 |
1/2✓ Branch 5 → 6 taken 60 times.
✗ Branch 5 → 10 not taken.
|
60 | if(auto it = s_creators.find(algo_name); it != s_creators.end()) |
| 27 | 60 | return it->second(); | |
| 28 | ✗ | throw std::runtime_error(fmt::format("AlgorithmFactory: algorithm with name {:?} does not exist", algo_name)); | |
| 29 | } | ||
| 30 | |||
| 31 | 217 | std::optional<std::vector<std::string>> AlgorithmFactory::GetCreatorAlgorithms(std::string const& bank_name) noexcept | |
| 32 | { | ||
| 33 |
2/2✓ Branch 5 → 6 taken 71 times.
✓ Branch 5 → 8 taken 146 times.
|
217 | if(auto it = s_bank_to_algos.find(bank_name); it != s_bank_to_algos.end()) |
| 34 | 71 | return it->second; | |
| 35 | 146 | return {}; | |
| 36 | } | ||
| 37 | |||
| 38 | 23 | std::optional<std::vector<std::string>> AlgorithmFactory::GetCreatedBanks(std::string const& algo_name) noexcept(false) | |
| 39 | { | ||
| 40 |
1/2✓ Branch 5 → 6 taken 23 times.
✗ Branch 5 → 8 not taken.
|
23 | if(auto it = s_algo_to_banks.find(algo_name); it != s_algo_to_banks.end()) |
| 41 | 23 | return it->second; | |
| 42 | ✗ | return {}; | |
| 43 | } | ||
| 44 | |||
| 45 | } | ||
| 46 |