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
30 // Explicitly check presence so we can preserve the original entry and log a warning
31 // instead of overwriting silently.
32 auto search = tt.find(ttKey);
33
34 if (search == tt.end()) {
35 // Insert the new key-value pair.
36 tt[ttKey] = gtron;
37 } else {
38 log->warning("Key <" + ttKey + "> already present in TT map");
39 }
40
41 // Level 1: typical "milestone" message indicating a configuration registration occurred.
42 log->info(1, "Added GElectronic with identity <", ttKey, "> to TT map");
43
44 // Debug: print the entire table content for troubleshooting configuration/key issues.
45 log->debug(NORMAL, "Translation Table:");
46 for (auto &thisItem: tt) {
47 log->debug(NORMAL, GTAB, "<", thisItem.first, "> ⇢ ", thisItem.second);
48 }
49}
50
51
52// See header for API docs.
53GElectronic GTranslationTable::getElectronics(const std::vector<int> &identity) const {
54 std::string ttKey = formTTKey(identity);
55 auto search = tt.find(ttKey);
56
57 if (search != tt.end()) {
58 log->debug(NORMAL, "Retrieved Electronic using key <", ttKey, "> in TT map: ", search->second);
59 return search->second;
60 } else {
61 log->error(EC__TTNOTFOUNDINTT, "Key <", ttKey, "> not found in TT map");
62 }
63}
std::shared_ptr< GLogger > log
void warning(Args &&... args) const
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) 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.
#define EC__TTNOTFOUNDINTT
Error code used when a translation table entry is not found for a given key.
#define GTAB