Refactor
This commit is contained in:
parent
910afad3b5
commit
25c4d8474d
@ -20,10 +20,10 @@ namespace germanairlinesva_simdata
|
||||
|
||||
void makeAirport(
|
||||
const std::string &kind,
|
||||
std::ifstream *infile,
|
||||
std::ifstream &infile,
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
*airports,
|
||||
std::ofstream *logfile);
|
||||
&airports,
|
||||
std::ofstream &logfile);
|
||||
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields);
|
||||
void makeRunway(std::vector<Runway> *runways,
|
||||
std::vector<std::string> fields);
|
||||
|
||||
@ -27,7 +27,7 @@ namespace germanairlinesva_simdata
|
||||
|
||||
// Default
|
||||
logfile << "<FILE> " << defaultFile << std::endl;
|
||||
makeAirport("DEFAULT", &base, &airports, &logfile);
|
||||
makeAirport("DEFAULT", base, airports, logfile);
|
||||
base.close();
|
||||
|
||||
std::string line;
|
||||
@ -47,7 +47,7 @@ namespace germanairlinesva_simdata
|
||||
std::ifstream pack(path);
|
||||
if (pack.good()) {
|
||||
logfile << "<FILE> " << path << std::endl;
|
||||
makeAirport("CUSTOM", &pack, &airports, &logfile);
|
||||
makeAirport("CUSTOM", pack, airports, logfile);
|
||||
pack.close();
|
||||
} else {
|
||||
pack.close();
|
||||
@ -66,10 +66,10 @@ namespace germanairlinesva_simdata
|
||||
|
||||
void makeAirport(
|
||||
const std::string &kind,
|
||||
std::ifstream *infile,
|
||||
std::ifstream &infile,
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
*airports,
|
||||
std::ofstream *logfile)
|
||||
&airports,
|
||||
std::ofstream &logfile)
|
||||
{
|
||||
std::string line;
|
||||
std::string *currentIcao = nullptr;
|
||||
@ -79,7 +79,7 @@ namespace germanairlinesva_simdata
|
||||
int apCount = 0;
|
||||
int validCount = 0;
|
||||
|
||||
while (std::getline(*infile, line)) {
|
||||
while (std::getline(infile, line)) {
|
||||
std::vector<std::string> fields = germanairlinesva_util::split(line, ' ');
|
||||
fields = germanairlinesva_util::select_T<std::string>(
|
||||
fields,
|
||||
@ -91,54 +91,52 @@ namespace germanairlinesva_simdata
|
||||
// Write to file if ICAO is valid, and we have gates and runways
|
||||
if (currentIcao != nullptr && !tmpRunways.empty() &&
|
||||
!tmpGates.empty()) {
|
||||
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
|
||||
airports[*currentIcao] = {tmpGates, tmpRunways};
|
||||
validCount += 1;
|
||||
*logfile << "\t<STATUS> " << *currentIcao << " committed"
|
||||
<< std::endl;
|
||||
logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
|
||||
} else if (currentIcao != nullptr) {
|
||||
*logfile << "\t<STATUS> " << *currentIcao
|
||||
<< " had no gates or runways" << std::endl;
|
||||
logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
|
||||
<< std::endl;
|
||||
}
|
||||
tmpGates = std::vector<Gate>();
|
||||
tmpRunways = std::vector<Runway>();
|
||||
currentIcao = new std::string(fields[4]);
|
||||
apCount += 1;
|
||||
*logfile << "\t<" << kind << "> " << line << std::endl;
|
||||
logfile << "\t<" << kind << "> " << line << std::endl;
|
||||
} else if (currentIcao != nullptr && fields[0] == "15") {
|
||||
makeGate15(&tmpGates, fields);
|
||||
*logfile << "\t\t<GATE OLD> " << line << std::endl;
|
||||
logfile << "\t\t<GATE OLD> " << line << std::endl;
|
||||
} else if (fields[0] == "16" || fields[0] == "17") {
|
||||
// Write to file if ICAO is valid, and we have gates and runways
|
||||
if (currentIcao != nullptr && !tmpRunways.empty() &&
|
||||
!tmpGates.empty()) {
|
||||
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
|
||||
airports[*currentIcao] = {tmpGates, tmpRunways};
|
||||
validCount += 1;
|
||||
*logfile << "\t<STATUS> " << *currentIcao << " committed"
|
||||
<< std::endl;
|
||||
logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
|
||||
} else if (currentIcao != nullptr) {
|
||||
*logfile << "\t<STATUS> " << *currentIcao
|
||||
<< " had no gates or runways" << std::endl;
|
||||
logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
|
||||
<< std::endl;
|
||||
}
|
||||
tmpGates = std::vector<Gate>();
|
||||
tmpRunways = std::vector<Runway>();
|
||||
currentIcao = nullptr;
|
||||
*logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
|
||||
logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
|
||||
} else if (currentIcao != nullptr && fields[0] == "100") {
|
||||
makeRunway(&tmpRunways, fields);
|
||||
*logfile << "\t\t<RUNWAY> " << line << std::endl;
|
||||
logfile << "\t\t<RUNWAY> " << line << std::endl;
|
||||
} else if (currentIcao != nullptr && fields[0] == "1300") {
|
||||
makeGate1300(&tmpGates, fields);
|
||||
*logfile << "\t\t<GATE> " << line << std::endl;
|
||||
logfile << "\t\t<GATE> " << line << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
|
||||
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
|
||||
airports[*currentIcao] = {tmpGates, tmpRunways};
|
||||
validCount += 1;
|
||||
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
|
||||
logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
|
||||
}
|
||||
*logfile << "<STATUS> " << apCount << " airports found, of which "
|
||||
<< validCount << " are valid" << std::endl;
|
||||
logfile << "<STATUS> " << apCount << " airports found, of which "
|
||||
<< validCount << " are valid" << std::endl;
|
||||
}
|
||||
|
||||
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields)
|
||||
|
||||
@ -105,18 +105,16 @@ namespace germanairlinesva_util
|
||||
nullptr,
|
||||
PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptAcquireContext returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
toLog("CryptAcquireContext returned with error " +
|
||||
std::to_string(GetLastError()));
|
||||
|
||||
CloseHandle(hFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptCreateHash returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
toLog("CryptCreateHash returned with error " +
|
||||
std::to_string(GetLastError()));
|
||||
|
||||
CloseHandle(hFile);
|
||||
CryptReleaseContext(hProv, 0);
|
||||
@ -129,9 +127,8 @@ namespace germanairlinesva_util
|
||||
}
|
||||
|
||||
if (!CryptHashData(hHash, rgbFile, cbRead, 0)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptHashData returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
toLog("CryptHashData returned with error " +
|
||||
std::to_string(GetLastError()));
|
||||
|
||||
CryptReleaseContext(hProv, 0);
|
||||
CryptDestroyHash(hHash);
|
||||
@ -141,9 +138,7 @@ namespace germanairlinesva_util
|
||||
}
|
||||
|
||||
if (!bResult) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "ReadFile returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
toLog("ReadFile returned with error " + std::to_string(GetLastError()));
|
||||
|
||||
CryptReleaseContext(hProv, 0);
|
||||
CryptDestroyHash(hHash);
|
||||
@ -155,9 +150,8 @@ namespace germanairlinesva_util
|
||||
if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) {
|
||||
to_hex((char *)rgbHash, lastHash);
|
||||
} else {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptGetHashParam returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
toLog("CryptGetHashParam returned with error " +
|
||||
std::to_string(GetLastError()));
|
||||
}
|
||||
|
||||
CryptDestroyHash(hHash);
|
||||
|
||||
@ -33,8 +33,8 @@ namespace germanairlinesva_websocket
|
||||
|
||||
public:
|
||||
Websocket(std::string host,
|
||||
std::string user,
|
||||
std::function<void(const std::string)> toLog);
|
||||
std::string user,
|
||||
std::function<void(const std::string)> toLog);
|
||||
~Websocket();
|
||||
void onClientMessageCallback(const ix::WebSocketMessagePtr &msg);
|
||||
void sendData(data &d);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user