| 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 | 1231 | 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 1231 times.
✗ Branch 5 → 26 not taken.
|
1231 | if(auto it = s_creators.find(algo_name); it == s_creators.end()) { |
| 12 | 2462 | s_creators.insert({algo_name, creator}); | |
| 13 | 2462 | s_algo_to_banks.insert({algo_name, new_banks}); | |
| 14 |
2/2✓ Branch 25 → 13 taken 328 times.
✓ Branch 25 → 26 taken 1231 times.
|
1559 | for(auto const& new_bank : new_banks) { |
| 15 |
1/2✓ Branch 16 → 17 taken 328 times.
✗ Branch 16 → 22 not taken.
|
328 | if(auto it = s_bank_to_algos.find(new_bank); it == s_bank_to_algos.end()) |
| 16 | 656 | s_bank_to_algos.insert({new_bank, {}}); | |
| 17 | 328 | s_bank_to_algos.at(new_bank).push_back(algo_name); | |
| 18 | } | ||
| 19 | return true; | ||
| 20 | } | ||
| 21 | return false; | ||
| 22 | } | ||
| 23 | |||
| 24 | 57 | algo_t AlgorithmFactory::Create(std::string const& algo_name) | |
| 25 | { | ||
| 26 |
1/2✓ Branch 5 → 6 taken 57 times.
✗ Branch 5 → 10 not taken.
|
57 | if(auto it = s_creators.find(algo_name); it != s_creators.end()) |
| 27 | 57 | return it->second(); | |
| 28 | ✗ | throw std::runtime_error(fmt::format("AlgorithmFactory: algorithm with name {:?} does not exist", algo_name)); | |
| 29 | } | ||
| 30 | |||
| 31 | 207 | std::optional<std::vector<std::string>> AlgorithmFactory::GetCreatorAlgorithms(std::string const& bank_name) noexcept | |
| 32 | { | ||
| 33 |
2/2✓ Branch 5 → 6 taken 67 times.
✓ Branch 5 → 8 taken 140 times.
|
207 | if(auto it = s_bank_to_algos.find(bank_name); it != s_bank_to_algos.end()) |
| 34 | 67 | return it->second; | |
| 35 | 140 | 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 |