141 lines
4.1 KiB
C++
141 lines
4.1 KiB
C++
#ifndef GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H
|
|
#define GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H
|
|
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "geodata.hpp"
|
|
#include "simdata/gate.hpp"
|
|
#include "simdata/runway.hpp"
|
|
#include "util.hpp"
|
|
|
|
namespace germanairlinesva
|
|
{
|
|
namespace file
|
|
{
|
|
namespace simdata
|
|
{
|
|
inline int scan(
|
|
const std::string runwaysFile,
|
|
const std::string gatesFile,
|
|
const std::string logFile,
|
|
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
|
&airports)
|
|
{
|
|
std::ifstream runways(runwaysFile);
|
|
if (!runways.good()) {
|
|
return 1;
|
|
}
|
|
std::ifstream gates(gatesFile);
|
|
if (!gates.good()) {
|
|
runways.close();
|
|
return 2;
|
|
}
|
|
std::ofstream log(logFile, std::fstream::trunc);
|
|
if (!log.good()) {
|
|
runways.close();
|
|
gates.close();
|
|
return 3;
|
|
}
|
|
|
|
std::string line;
|
|
std::string *currentIcao = nullptr;
|
|
std::map<std::string, std::vector<Gate>> tmpAirportGates;
|
|
std::map<std::string, std::vector<Runway>> tmpAirportRunways;
|
|
std::vector<Gate> tmpGates;
|
|
std::vector<Runway> tmpRunways;
|
|
|
|
int apCount = 0;
|
|
int validCount = 0;
|
|
|
|
log << "<FILE> " << runwaysFile << std::endl;
|
|
|
|
while (std::getline(runways, line)) {
|
|
std::vector<std::string> fields = util::split(line, ',');
|
|
// New ICAO
|
|
if (currentIcao != nullptr && *currentIcao != fields[0]) {
|
|
tmpAirportRunways[*currentIcao] = tmpRunways;
|
|
tmpRunways = std::vector<Runway>();
|
|
apCount++;
|
|
}
|
|
|
|
currentIcao = new std::string(fields[0]);
|
|
|
|
int desig = std::stoi(fields[1]);
|
|
std::string designator;
|
|
switch (desig % 10) {
|
|
case 0:
|
|
designator = std::to_string(desig / 10);
|
|
break;
|
|
case 1:
|
|
designator = std::to_string(desig / 10) + " L";
|
|
break;
|
|
case 2:
|
|
designator = std::to_string(desig / 10) + " R";
|
|
break;
|
|
case 3:
|
|
designator = std::to_string(desig / 10) + " C";
|
|
break;
|
|
}
|
|
if (desig < 100) {
|
|
designator = "0" + designator;
|
|
}
|
|
|
|
struct geodata::point start = {std::stod(fields[2]),
|
|
std::stod(fields[3])};
|
|
tmpRunways.emplace_back(designator,
|
|
start,
|
|
geodata::toMetre(std::stod(fields[8])),
|
|
geodata::toMetre(std::stod(fields[6])),
|
|
std::stod(fields[5]) + std::stod(fields[9]));
|
|
|
|
log << "\t<RUNWAY> " << line << std::endl;
|
|
}
|
|
|
|
currentIcao = nullptr;
|
|
while (std::getline(gates, line)) {
|
|
std::vector<std::string> fields = util::split(line, ',');
|
|
// New ICAO
|
|
if (currentIcao != nullptr && *currentIcao != fields[0]) {
|
|
tmpAirportGates[*currentIcao] = tmpGates;
|
|
tmpGates = std::vector<Gate>();
|
|
}
|
|
|
|
currentIcao = new std::string(fields[0]);
|
|
|
|
double width = std::stod(fields[5]);
|
|
tmpGates.emplace_back(fields[1] + fields[2],
|
|
std::stod(fields[3]),
|
|
std::stod(fields[4]),
|
|
width > 0 ? width : 20);
|
|
|
|
log << "\t<GATE> " << line << std::endl;
|
|
}
|
|
|
|
for (const auto &pair : tmpAirportRunways) {
|
|
std::string icao = pair.first;
|
|
|
|
if (!tmpAirportGates[icao].empty() && !pair.second.empty()) {
|
|
airports[icao] = {tmpAirportGates[icao], pair.second};
|
|
log << "\t<STATUS> " << icao << " committed" << std::endl;
|
|
validCount++;
|
|
} else {
|
|
log << "\t<STATUS> " << icao << " had no gates or runways"
|
|
<< std::endl;
|
|
}
|
|
}
|
|
|
|
log << "<STATUS> " << apCount << " airports found, of which "
|
|
<< validCount << " are valid" << std::endl;
|
|
|
|
return 0;
|
|
}
|
|
} // namespace simdata
|
|
} // namespace file
|
|
} // namespace germanairlinesva
|
|
|
|
#endif |