1
0
Fork 0

Maintenance: apt_loader

SPDX tags.
parameter to loadAirportFormFile() changed to const&.
parameter to Line() ctor changed to const&.
parameter to loadAirport() changed to const&.
member variable initialization.
++prefix for complex types.
virtual dtor.
This commit is contained in:
scttgs0 2023-05-23 00:56:19 -05:00
parent 2c40595d3c
commit cda2337041
2 changed files with 691 additions and 718 deletions

View file

@ -1,65 +1,46 @@
// apt_loader.cxx -- a front end loader of the apt.dat file. This loader
// populates the runway and basic classes.
//
// Written by Curtis Olson, started August 2000.
//
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
/*
* SPDX-FileName: apt_loader.cxx
* SPDX-FileComment: a front end loader of the apt.dat file. This loader populates the runway and basic classes.
* SPDX-FileCopyrightText: Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "apt_loader.hxx"
#include <simgear/compiler.h>
#include <algorithm>
#include <cerrno>
#include <cstddef> // std::size_t
#include <ctype.h> // isspace()
#include <iostream>
#include <sstream> // std::istringstream
#include <stdlib.h> // atof(), atoi()
#include <string.h> // memchr()
#include <ctype.h> // isspace()
#include <cerrno>
#include <string>
#include <utility> // std::pair, std::move()
#include <vector>
#include <simgear/compiler.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iostreams/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/misc/sg_path.hxx>
#include <cstddef> // std::size_t
#include <string>
#include <vector>
#include <utility> // std::pair, std::move()
#include "airport.hxx"
#include "runways.hxx"
#include "pavement.hxx"
#include <ATC/CommStation.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/positioned.hxx>
#include <ATC/CommStation.hxx>
#include <iostream>
#include <sstream> // std::istringstream
#include "airport.hxx"
#include "apt_loader.hxx"
#include "pavement.hxx"
#include "runways.hxx"
using std::vector;
using std::string;
using std::vector;
namespace strutils = simgear::strutils;
@ -76,14 +57,14 @@ static FGPositioned::Type fptypeFromRobinType(unsigned int aType)
}
}
namespace flightgear
{
namespace flightgear {
APTLoader::APTLoader()
: last_apt_id(""),
last_apt_elev(0.0),
currentAirportPosID(0),
cache(NavDataCache::instance())
{ }
{
}
APTLoader::~APTLoader() {}
@ -143,8 +124,7 @@ void APTLoader::readAptDatFile(const SGPath &aptdb_file,
unsigned int aptDatFormatVersion =
strutils::readNonNegativeInt<unsigned int>(fields[0]);
SG_LOG(SG_GENERAL, SG_INFO,
"apt.dat format version (" << apt_dat << "): " <<
aptDatFormatVersion);
"apt.dat format version (" << apt_dat << "): " << aptDatFormatVersion);
}
}
} // end of the apt.dat header
@ -160,8 +140,7 @@ void APTLoader::readAptDatFile(const SGPath &aptdb_file,
if ((line_num % 100) == 0) {
// every 100 lines
unsigned int percent = ((bytesReadSoFar + in.approxOffset()) * 100)
/ totalSizeOfAllAptDatFiles;
unsigned int percent = ((bytesReadSoFar + in.approxOffset()) * 100) / totalSizeOfAllAptDatFiles;
cache->setRebuildPhaseProgress(
NavDataCache::REBUILD_READING_APT_DAT_FILES, percent);
}
@ -191,8 +170,7 @@ void APTLoader::readAptDatFile(const SGPath &aptdb_file,
if (skipAirport) {
SG_LOG(SG_GENERAL, SG_INFO,
apt_dat << ":" << line_num << ": skipping airport " <<
currentAirportId << " (already defined earlier)" );
apt_dat << ":" << line_num << ": skipping airport " << currentAirportId << " (already defined earlier)");
} else {
// We haven't seen this airport yet in any apt.dat file
RawAirportInfo& airportInfo = insertRetval.first->second;
@ -223,7 +201,7 @@ void APTLoader::loadAirports()
// Loop over all airports found in all apt.dat files
for (AirportInfoMapType::const_iterator it = airportInfoMap.begin();
it != airportInfoMap.end(); it++) {
it != airportInfoMap.end(); ++it) {
// Full path to the apt.dat file this airport info comes from
const string aptDat = it->second.file.utf8Str();
@ -247,7 +225,7 @@ void APTLoader::loadAirports()
}
// Parse and return specific apt.dat file containing a single airport.
const FGAirport* APTLoader::loadAirportFromFile(std::string id, const SGPath& aptdb_file)
const FGAirport* APTLoader::loadAirportFromFile(const std::string& id, const SGPath& aptdb_file)
{
std::size_t bytesReadSoFar = 10;
std::size_t totalSizeOfAllAptDatFiles = 100;
@ -263,7 +241,7 @@ static bool isCommLine(const int code)
return ((code >= 50) && (code <= 56)) || ((code >= 1050) && (code <= 1056));
}
const FGAirport* APTLoader::loadAirport(const string aptDat, const std::string airportID, RawAirportInfo* airport_info, bool createFGAirport)
const FGAirport* APTLoader::loadAirport(const string& aptDat, const std::string& airportID, RawAirportInfo* airport_info, bool createFGAirport)
{
// The first line for this airport was already split over whitespace, but
// remains to be parsed for the most part.
@ -274,7 +252,7 @@ const FGAirport* APTLoader::loadAirport(const string aptDat, const std::string a
// Loop over the second and subsequent lines
for (LinesList::const_iterator linesIt = lines.begin();
linesIt != lines.end(); linesIt++) {
linesIt != lines.end(); ++linesIt) {
// Beware that linesIt->str may end with an '\r' character, see above!
unsigned int rowCode = linesIt->rowCode;
@ -329,8 +307,7 @@ const FGAirport* APTLoader::loadAirport(const string aptDat, const std::string a
case None:
std::ostringstream oss;
string cleanedLine = cleanLine(linesIt->str);
oss << aptDat << ":" << linesIt->number << ": unexpected row code " <<
rowCode;
oss << aptDat << ":" << linesIt->number << ": unexpected row code " << rowCode;
SG_LOG(SG_GENERAL, SG_ALERT, oss.str() << " (" << cleanedLine << ")");
throw sg_format_exception(oss.str(), cleanedLine);
break;
@ -400,8 +377,8 @@ std::string APTLoader::cleanLine(const std::string& line)
// Lines obtained from readAptDatFile() may end with \r, which can be quite
// confusing when printed to the terminal.
for (std::string::reverse_iterator it = res.rbegin();
it != res.rend() && *it == '\r'; /* empty */)
{ // The beauty of C++ iterators...
it != res.rend() && *it == '\r';
/* empty */) { // The beauty of C++ iterators...
it = std::string::reverse_iterator(res.erase((it + 1).base()));
}
@ -429,8 +406,7 @@ void APTLoader::finishAirport(const string& aptDat)
if (!rwy_count) {
currentAirportPosID = 0;
SG_LOG( SG_GENERAL, SG_ALERT, "Error in '" << aptDat <<
"': no runways for " << last_apt_id << ", skipping." );
SG_LOG(SG_GENERAL, SG_ALERT, "Error in '" << aptDat << "': no runways for " << last_apt_id << ", skipping.");
return;
}
@ -475,8 +451,8 @@ void APTLoader::parseRunwayLine810(const string& aptDat, unsigned int lineNum,
{
if (token.size() < 11) {
SG_LOG(SG_GENERAL, SG_WARN,
aptDat << ":" << lineNum << ": invalid v810 runway line " <<
"(row code 10): at least 11 fields are required" );
aptDat << ":" << lineNum << ": invalid v810 runway line "
<< "(row code 10): at least 11 fields are required");
return;
}
@ -513,16 +489,14 @@ void APTLoader::parseRunwayLine810(const string& aptDat, unsigned int lineNum,
} else {
// (pair of) runways
string rwy_displ_threshold = token[6];
vector<string> displ
= simgear::strutils::split( rwy_displ_threshold, "." );
vector<string> displ = simgear::strutils::split(rwy_displ_threshold, ".");
double displ_thresh1 = atof(displ[0].c_str());
double displ_thresh2 = atof(displ[1].c_str());
displ_thresh1 *= SG_FEET_TO_METER;
displ_thresh2 *= SG_FEET_TO_METER;
string rwy_stopway = token[7];
vector<string> stop
= simgear::strutils::split( rwy_stopway, "." );
vector<string> stop = simgear::strutils::split(rwy_stopway, ".");
double stopway1 = atof(stop[0].c_str());
double stopway2 = atof(stop[1].c_str());
stopway1 *= SG_FEET_TO_METER;
@ -552,8 +526,8 @@ void APTLoader::parseRunwayLine850(const string& aptDat, unsigned int lineNum,
{
if (token.size() < 26) {
SG_LOG(SG_GENERAL, SG_WARN,
aptDat << ":" << lineNum << ": invalid v850 runway line " <<
"(row code 100): at least 26 fields are required" );
aptDat << ":" << lineNum << ": invalid v850 runway line "
<< "(row code 100): at least 26 fields are required");
return;
}
@ -632,8 +606,8 @@ void APTLoader::parseWaterRunwayLine850(const string& aptDat,
{
if (token.size() < 9) {
SG_LOG(SG_GENERAL, SG_WARN,
aptDat << ":" << lineNum << ": invalid v850 water runway line " <<
"(row code 101): at least 9 fields are required" );
aptDat << ":" << lineNum << ": invalid v850 water runway line "
<< "(row code 101): at least 9 fields are required");
return;
}
@ -681,8 +655,8 @@ void APTLoader::parseHelipadLine850(const string& aptDat, unsigned int lineNum,
{
if (token.size() < 12) {
SG_LOG(SG_GENERAL, SG_WARN,
aptDat << ":" << lineNum << ": invalid v850 helipad line " <<
"(row code 102): at least 12 fields are required" );
aptDat << ":" << lineNum << ": invalid v850 helipad line "
<< "(row code 102): at least 12 fields are required");
return;
}
@ -751,9 +725,8 @@ void APTLoader::parseNodeLine850(NodeList *nodelist,
if (token.size() < minNbTokens[rowCode - 111]) {
SG_LOG(SG_GENERAL, SG_WARN,
aptDat << ":" << lineNum << ": invalid v850 node line " <<
"(row code " << rowCode << "): at least " <<
minNbTokens[rowCode-111] << " fields are required" );
aptDat << ":" << lineNum << ": invalid v850 node line "
<< "(row code " << rowCode << "): at least " << minNbTokens[rowCode - 111] << " fields are required");
return;
}
@ -802,13 +775,13 @@ void APTLoader::parseCommLine(const string& aptDat,
{
if (token.size() < 3) {
SG_LOG(SG_GENERAL, SG_WARN,
aptDat << ":" << lineNum << ": invalid Comm Frequency line " <<
"(row code " << rowCode << "): at least 3 fields are required" );
aptDat << ":" << lineNum << ": invalid Comm Frequency line "
<< "(row code " << rowCode << "): at least 3 fields are required");
return;
} else if (rwy_count <= 0) {
SG_LOG(SG_GENERAL, SG_ALERT,
aptDat << ":" << lineNum << ": no runways, skipping Comm " <<
"Frequency line for " << last_apt_id );
aptDat << ":" << lineNum << ": no runways, skipping Comm "
<< "Frequency line for " << last_apt_id);
// There used to be no 'return' here. Not sure how useful this is, but
// clearly this code block doesn't make sense without it, so here it is.
return;
@ -859,10 +832,8 @@ void APTLoader::parseCommLine(const string& aptDat,
switch (rowCode) {
case 50:
ty = FGPositioned::FREQ_AWOS;
for (size_t i = 2; i < token.size(); ++i)
{
if (token[i] == "ATIS")
{
for (size_t i = 2; i < token.size(); ++i) {
if (token[i] == "ATIS") {
ty = FGPositioned::FREQ_ATIS;
break;
}
@ -913,4 +884,4 @@ bool metarDataLoad(const SGPath& metar_file)
return true;
}
} // of namespace flightgear
} // namespace flightgear

View file

@ -7,7 +7,6 @@
#pragma once
#include "airport.hxx"
#include <string>
#include <unordered_map>
#include <vector>
@ -18,18 +17,21 @@
#include <simgear/misc/sg_path.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include "airport.hxx"
class NavDataCache;
class sg_gzifstream;
class FGPavement;
namespace flightgear {
class APTLoader
{
public:
APTLoader();
~APTLoader();
virtual ~APTLoader();
// Read the specified apt.dat file into 'airportInfoMap'.
// 'bytesReadSoFar' and 'totalSizeOfAllAptDatFiles' are used for progress
@ -43,11 +45,11 @@ public:
// Load a specific airport defined in aptdb_file, and return a "rich" view
// of the airport including taxiways, pavement and line features.
const FGAirport* loadAirportFromFile(std::string id, const SGPath& aptdb_file);
const FGAirport* loadAirportFromFile(const std::string& id, const SGPath& aptdb_file);
private:
struct Line {
Line(unsigned int number_, unsigned int rowCode_, std::string str_)
Line(unsigned int number_, unsigned int rowCode_, const std::string& str_)
: number(number_), rowCode(rowCode_), str(str_) {}
unsigned int number;
@ -78,7 +80,7 @@ private:
APTLoader(const APTLoader&); // disable copy constructor
APTLoader& operator=(const APTLoader&); // disable copy-assignment operator
const FGAirport* loadAirport(const std::string aptDat, const std::string airportID, RawAirportInfo* airport_info, bool createFGAirport = false);
const FGAirport* loadAirport(const std::string& aptDat, const std::string& airportID, RawAirportInfo* airport_info, bool createFGAirport = false);
// Tell whether an apt.dat line is blank or a comment line
bool isBlankOrCommentLine(const std::string& line);
@ -111,10 +113,10 @@ private:
std::vector<std::string> token;
AirportInfoMapType airportInfoMap;
double rwy_lat_accum;
double rwy_lon_accum;
double last_rwy_heading;
int rwy_count;
double rwy_lat_accum{0.0};
double rwy_lon_accum{0.0};
double last_rwy_heading{0.0};
int rwy_count{0};
std::string last_apt_id;
double last_apt_elev;
SGGeod tower;