gtranslationTable
Loading...
Searching...
No Matches
gtranslationTable.cc
Go to the documentation of this file.
1// gtranslationTable
2#include "gtranslationTable.h"
4
5
6// See header for API docs.
7std::string GTranslationTable::formTTKey(const std::vector<int> &identity) const {
8 // Defensive check: an empty identity cannot form a meaningful key.
9 // Returning an empty key also prevents accidental insertion under an ambiguous identifier.
10 if (identity.empty()) {
11 log->warning("Empty identity vector provided to formTTKey");
12 return "";
13 }
14
15 // Build a hyphen-separated key (e.g. "1-2-3-4").
16 std::ostringstream oss;
17 for (size_t i = 0; i < identity.size(); ++i) {
18 oss << identity[i];
19 if (i != identity.size() - 1)
20 oss << "-";
21 }
22 return oss.str();
23}
24
25
26// See header for API docs.
27void GTranslationTable::addGElectronicWithIdentity(const std::vector<int> &identity, const GElectronic &gtron) {
28 std::string ttKey = formTTKey(identity);
29 const bool inserted = tt.try_emplace(ttKey, gtron).second;
30
31 if (!inserted) {
32 log->warning("Key <" + ttKey + "> already present in TT map");
33 }
34
35 // Level 1: typical "milestone" message indicating a configuration registration was attempted.
36 log->info(1, inserted ? "Added" : "Preserved", " GElectronic with identity <", ttKey, "> in TT map");
37
38 // Debug: print the entire table content for troubleshooting configuration/key issues.
39 log->debug(NORMAL, "Translation Table:");
40 for (auto &thisItem: tt) {
41 log->debug(NORMAL, guts::GTAB, "<", thisItem.first, "> ⇢ ", thisItem.second);
42 }
43}
44
45
46// See header for API docs.
47const GElectronic& GTranslationTable::getElectronics(const std::vector<int> &identity) const {
48 std::string ttKey = formTTKey(identity);
49 auto search = tt.find(ttKey);
50
51 if (search == tt.end()) {
52 log->error(gtranslationTable::EC__TTNOTFOUNDINTT, "Key <", ttKey, "> not found in TT map");
53 }
54
55 log->debug(NORMAL, "Retrieved Electronic using key <", ttKey, "> in TT map: ", search->second);
56 return search->second;
57}
std::shared_ptr< GLogger > log
const GElectronic & getElectronics(const std::vector< int > &identity) const
Retrieves the electronics configuration associated with a given identity vector.
void addGElectronicWithIdentity(const std::vector< int > &identity, const GElectronic &gtron)
Registers an electronics configuration for a given identity vector.
NORMAL
Conventions (primarily exit/error codes) for the Translation Table module.
constexpr int EC__TTNOTFOUNDINTT
Error code used when a translation table entry is not found for a given key.
constexpr char GTAB[]