#ifndef GERMANAIRLINESVA_FILE_SIMULATORDATABASE_H #define GERMANAIRLINESVA_FILE_SIMULATORDATABASE_H #include #include #include #include #include #include #include #include "simdata/gate.h" #include "simdata/runway.h" #include "simdata/simDatabase.h" /* * Header * * CHAR[5] | UINT8 * --------+-------- * VGAS | VERSION */ /* * Airport * * UINT8 | CHAR[] | UINT16 | GATE[] | UINT8 | RUNWAY[] * --------+--------+----------+--------+---------+--------- * STRLEN | ICAO | NUMGATES | GATES | NUMRWYS | RUNWAYS */ namespace germanairlinesva { namespace file { namespace simdata { static inline void toFile(const SimDatabase &database, const std::string &file) { std::ofstream out(file, std::fstream::binary); // File Header, Last member is version std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1}; out.write(reinterpret_cast(header), 6); database.toFile(out); out.close(); } static inline const SimDatabase readVersion1(std::ifstream &in) { SimDatabase database; std::uint16_t numAirports = read(in); for (int i = 0; i < numAirports; i++) { // ICAO std::string icao = readString(in); // Gates std::uint16_t numGates = read(in); for (int j = 0; j < numGates; j++) { std::string designator = readString(in); struct germanairlinesva::geodata::point center = read(in); std::uint8_t radius = read(in); database.addGate(icao, designator, center, radius); } // Runways std::uint8_t numRunways = read(in); for (int j = 0; j < numRunways; j++) { std::string designator = readString(in); // Bounds struct germanairlinesva::geodata::box bounds = read(in); std::uint8_t width = read(in); std::uint16_t length = read(in); std::uint16_t trueHeading = read(in); database .addRunway(icao, designator, bounds, width, length, trueHeading); } } in.close(); return database; } static inline const SimDatabase fromFile(const std::string &file) { std::ifstream in(file, std::ifstream::binary); // File Header char ident[5]; in.read(ident, 5); if (strcmp(ident, "VGAS") != 0) { throw std::invalid_argument("Wrong file"); } std::uint8_t version = read(in); if (version == 1) { return readVersion1(in); } in.close(); return SimDatabase(); } } // namespace simdata } // namespace file } // namespace germanairlinesva #endif