HOPS
HOPS class reference
MHO_StationIdentifier.hh
Go to the documentation of this file.
1 #ifndef MHO_StationIdentifier_HH__
2 #define MHO_StationIdentifier_HH__
3 
4 #include <map>
5 #include <set>
6 #include <string>
7 
8 #include "MHO_Message.hh"
9 #include "MHO_StationIdentity.hh"
10 #include "MHO_Tokenizer.hh"
11 
12 namespace hops
13 {
14 
25 {
26  public:
33 
34  int Insert(MHO_StationIdentity station_identity)
35  {
36  std::string name = station_identity.GetStationName();
37  std::string code = station_identity.GetStationCode();
38  std::string mk4id = station_identity.GetStationMk4Id();
39 
40  bool name_present = (fCode2Name.find(name) != fCode2Name.end());
41  bool code_present = (fCode2Name.find(code) != fCode2Name.end());
42  bool mk4id_present = (fCode2Name.find(mk4id) != fCode2Name.end());
43 
44  if(!name_present && (code_present || mk4id_present))
45  {
46  msg_warn("utilities", "station: " << name << " shares a code or mk4id with another station" << eom);
47  return -1;
48  }
49 
50  if(!name_present && !code_present && !mk4id_present)
51  {
52  msg_debug("utilities", "inserting station identity: " << station_identity.as_string() << eom);
53  fCode2Name[name] = name;
54  fCode2Name[code] = name;
55  fCode2Name[mk4id] = name;
56  fName2Code[name] = code;
57  fName2Mk4ID[name] = mk4id;
58  fStationIds.push_back(station_identity);
59  }
60  //success
61  return 0;
62  }
63 
64  int Insert(const std::string& name, const std::string& code, const std::string& mk4id)
65  {
67  tmp.SetAll(name, code, mk4id);
68  return Insert(tmp);
69  }
70 
71  std::string CanonicalStationName(std::string code) const
72  {
73  auto it = fCode2Name.find(code);
74  if(it != fCode2Name.end())
75  {
76  return it->second;
77  }
78  else
79  {
80  msg_warn("utilities", "cannot locate cannonical station name for: <" << code << ">" << eom);
81  return code; //return the same value that was submitted
82  }
83  }
84 
85  std::string StationMk4IDFromName(std::string name) const
86  {
87  auto it = fName2Mk4ID.find(name);
88  if(it != fName2Mk4ID.end())
89  {
90  return it->second;
91  }
92  else
93  {
94  msg_warn("utilities", "cannot locate mk4 id from cannonical station name: <" << name << ">" << eom);
95  return name; //return the same value that was submitted
96  }
97  }
98 
99  std::string StationCodeFromName(std::string name) const
100  {
101  auto it = fName2Code.find(name);
102  if(it != fName2Code.end())
103  {
104  return it->second;
105  }
106  else
107  {
108  msg_warn("utilities", "cannot locate station code from cannonical station name: <" << name << ">" << eom);
109  return name; //return the same value that was submitted
110  }
111  }
112 
113  private:
114  //private for singleton
116  virtual ~MHO_StationIdentifier();
117 
118  std::vector< MHO_StationIdentity > fStationIds;
119  std::set< std::string > fCodeSet;
120  std::map< std::string, std::string > fCode2Name; // 1 char, 2 char, name -> proper name
121  std::map< std::string, std::string > fName2Code; //name -> 2 char code
122  std::map< std::string, std::string > fName2Mk4ID; //name -> 1 char mk4 id
123 };
124 
125 } // namespace hops
126 
127 #endif
#define msg_debug(xKEY, xCONTENT)
Definition: MHO_Message.hh:291
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:248
Class MHO_StationIdentifier Handles the mapping of two character and one character mk4ids to station ...
Definition: MHO_StationIdentifier.hh:25
int Insert(const std::string &name, const std::string &code, const std::string &mk4id)
Definition: MHO_StationIdentifier.hh:64
std::string StationCodeFromName(std::string name) const
Definition: MHO_StationIdentifier.hh:99
static MHO_StationIdentifier & GetInstance()
Getter for singleton instance (thread-safe, C++11 function-local static)
Definition: MHO_StationIdentifier.cc:15
std::string StationMk4IDFromName(std::string name) const
Definition: MHO_StationIdentifier.hh:85
std::string CanonicalStationName(std::string code) const
Definition: MHO_StationIdentifier.hh:71
int Insert(MHO_StationIdentity station_identity)
Definition: MHO_StationIdentifier.hh:34
Class MHO_StationIdentity - a class to store, associate, and compare 1-char, 2-char,...
Definition: MHO_StationIdentity.hh:29
std::string GetStationMk4Id() const
Definition: MHO_StationIdentity.hh:161
std::string GetStationCode() const
Definition: MHO_StationIdentity.hh:157
std::string GetStationName() const
Definition: MHO_StationIdentity.hh:153
void SetAll(const std::string &name, const std::string &code, const std::string &mk4id)
Definition: MHO_StationIdentity.hh:163
std::string as_string() const
Definition: MHO_StationIdentity.hh:107
Definition: MHO_AdhocFlagging.hh:18