gtranslationTable
gtranslationTable.cc
Go to the documentation of this file.
1 // gtranslationTable
2 #include "gtranslationTable.h"
4 
5 
15 std::string GTranslationTable::formTTKey(const std::vector<int> &identity) const {
16  // Check for an empty identity vector to avoid undefined behavior.
17  if (identity.empty()) {
18  log->warning("Empty identity vector provided to formTTKey");
19  return "";
20  }
21 
22  std::ostringstream oss;
23  for (size_t i = 0; i < identity.size(); ++i) {
24  oss << identity[i];
25  if (i != identity.size() - 1)
26  oss << "-";
27  }
28  return oss.str();
29 }
30 
31 
40 void GTranslationTable::addGElectronicWithIdentity(const std::vector<int> &identity, const GElectronic &gtron) {
41  std::string ttKey = formTTKey(identity);
42  auto search = tt.find(ttKey);
43 
44  if (search == tt.end()) {
45  // Insert the new key-value pair
46  tt[ttKey] = gtron;
47  } else {
48  log->warning("Key <" + ttKey + "> already present in TT map");
49  }
50 
51  log->info(1, "Added GElectronic with identity <", ttKey, "> to TT map");
52 
53  log->debug(NORMAL, "Translation Table:");
54  for (auto &thisItem: tt) {
55  log->debug(NORMAL, GTAB, "<", thisItem.first, "> ⇢ ", thisItem.second);
56  }
57 }
58 
59 
68 GElectronic GTranslationTable::getElectronics(const std::vector<int> &identity) const {
69  std::string ttKey = formTTKey(identity);
70  auto search = tt.find(ttKey);
71 
72  if (search != tt.end()) {
73  log->debug(NORMAL, "Found key <", ttKey, "> in TT map");
74  return search->second;
75  } else {
76  log->error(EC__TTNOTFOUNDINTT, "Key <", ttKey, "> not found in TT map");
77  }
78 }
79 
GElectronic getElectronics(const std::vector< int > &identity) const
Retrieves the GElectronic configuration for the provided identity.
void addGElectronicWithIdentity(const std::vector< int > &identity, const GElectronic &gtron)
Adds a GElectronic configuration with the provided identity.
#define EC__TTNOTFOUNDINTT