1
0
Fork 0

Maintenance: namespace

Clean up namespaces.
Don't use broad 'using namespace' context in header files.
Header Guards.
SPDX tags.
This commit is contained in:
scttgs0 2023-05-20 17:13:11 -05:00
parent 89043efdaa
commit fca4c7dbe2
5 changed files with 149 additions and 212 deletions

View file

@ -81,7 +81,7 @@ static std::string read_string(std::istream& in, size_t& pos)
static int PropertiesWrite(SGPropertyNode* root, std::ostream& out) static int PropertiesWrite(SGPropertyNode* root, std::ostream& out)
{ {
stringstream buffer; std::stringstream buffer;
writeProperties(buffer, root, true /*write_all*/); writeProperties(buffer, root, true /*write_all*/);
uint32_t buffer_len = buffer.str().size() + 1; uint32_t buffer_len = buffer.str().size() + 1;
writeRaw(out, buffer_len); writeRaw(out, buffer_len);

View file

@ -1,25 +1,9 @@
// AirportBuilder.hxx -- Builder to create airports based on airport data for /*
// rendering in the scenery * SPDX-FileName: AirportBuilder.cxx
// * SPDX-FileComment: Builder to create airports based on airport data for rendering in the scenery
// Written by Stuart Buchanan, started June 2020 * SPDX-FileCopyrightText: Copyright (C) 2020 Stuart Buchanan stuart13@gmail.com
// * SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2020 Stuart Buchanan stuart13@gmail.com */
//
// 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$
#include <algorithm> #include <algorithm>
@ -86,7 +70,7 @@ osgDB::ReaderWriter::ReadResult AirportBuilder::readNode(const std::string& file
if (! aptFile.isFile()) return ReadResult::FILE_NOT_HANDLED;; if (! aptFile.isFile()) return ReadResult::FILE_NOT_HANDLED;;
const string airportId = aptFile.file_base(); const std::string airportId = aptFile.file_base();
APTLoader aptLoader; APTLoader aptLoader;
const FGAirport* airport = aptLoader.loadAirportFromFile(airportId, aptFile); const FGAirport* airport = aptLoader.loadAirportFromFile(airportId, aptFile);

View file

@ -1,25 +1,10 @@
// airport.cxx -- Classes representing airports, seaports and helipads /*
// * SPDX-FileName: airport.cxx
// Written by Curtis Olson, started April 1998. * SPDX-FileComment: Classes representing airports, seaports and helipads
// Updated by Durk Talsma, started December, 2004. * SPDX-FileCopyrightText: Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
// * SPDX-FileContributor: Updated by Durk Talsma, started December, 2004
// Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt * SPDX-License-Identifier: GPL-2.0-or-later
// */
// 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$
#include <config.h> #include <config.h>
@ -1072,7 +1057,7 @@ flightgear::Transition* FGAirport::selectSIDByEnrouteTransition(FGPositioned* en
return nullptr; return nullptr;
} }
Transition *FGAirport::selectSIDByTransition(const FGRunway* runway, const string &aIdent) const Transition *FGAirport::selectSIDByTransition(const FGRunway* runway, const std::string &aIdent) const
{ {
loadProcedures(); loadProcedures();
for (auto sid : mSIDs) { for (auto sid : mSIDs) {
@ -1099,7 +1084,7 @@ flightgear::Transition* FGAirport::selectSTARByEnrouteTransition(FGPositioned* e
return nullptr; return nullptr;
} }
Transition *FGAirport::selectSTARByTransition(const FGRunway* runway, const string &aIdent) const Transition *FGAirport::selectSTARByTransition(const FGRunway* runway, const std::string &aIdent) const
{ {
loadProcedures(); loadProcedures();
for (auto star : mSTARs) { for (auto star : mSTARs) {

View file

@ -1,160 +1,141 @@
// apt_loader.hxx -- a front end loader of the apt.dat file. This loader /*
// populates the runway and basic classes. * SPDX-FileName: apt_loader.hxx
// * SPDX-FileComment: a front end loader of the apt.dat file. This loader populates the runway and basic classes.
// Written by Curtis Olson, started December 2004. * SPDX-FileCopyrightText: Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
// * SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2004 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$
#pragma once
#ifndef _FG_APT_LOADER_HXX
#define _FG_APT_LOADER_HXX
#include <string>
#include <vector>
#include <unordered_map>
#include "airport.hxx" #include "airport.hxx"
#include <string>
#include <unordered_map>
#include <vector>
#include <Navaids/positioned.hxx>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/math/SGGeod.hxx> #include <simgear/math/SGGeod.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <Navaids/positioned.hxx> #include <simgear/structure/SGSharedPtr.hxx>
class NavDataCache; class NavDataCache;
class sg_gzifstream; class sg_gzifstream;
class FGPavement; class FGPavement;
namespace flightgear namespace flightgear {
{
class APTLoader class APTLoader
{ {
public: public:
APTLoader(); APTLoader();
~APTLoader(); ~APTLoader();
// Read the specified apt.dat file into 'airportInfoMap'. // Read the specified apt.dat file into 'airportInfoMap'.
// 'bytesReadSoFar' and 'totalSizeOfAllAptDatFiles' are used for progress // 'bytesReadSoFar' and 'totalSizeOfAllAptDatFiles' are used for progress
// information. // information.
void readAptDatFile(const SGPath& aptdb_file, std::size_t bytesReadSoFar, void readAptDatFile(const SGPath& aptdb_file, std::size_t bytesReadSoFar,
std::size_t totalSizeOfAllAptDatFiles); std::size_t totalSizeOfAllAptDatFiles);
// Read all airports gathered in 'airportInfoMap' and load them into the // Read all airports gathered in 'airportInfoMap' and load them into the
// navdata cache (even in case of overlapping apt.dat files, // navdata cache (even in case of overlapping apt.dat files,
// 'airportInfoMap' has only one entry per airport). // 'airportInfoMap' has only one entry per airport).
void loadAirports(); void loadAirports();
// Load a specific airport defined in aptdb_file, and return a "rich" view // Load a specific airport defined in aptdb_file, and return a "rich" view
// of the airport including taxiways, pavement and line features. // of the airport including taxiways, pavement and line features.
const FGAirport* loadAirportFromFile(std::string id, const SGPath& aptdb_file); const FGAirport* loadAirportFromFile(std::string id, const SGPath& aptdb_file);
private: private:
struct Line struct Line {
{ Line(unsigned int number_, unsigned int rowCode_, std::string str_)
Line(unsigned int number_, unsigned int rowCode_, std::string str_) : number(number_), rowCode(rowCode_), str(str_) {}
: number(number_), rowCode(rowCode_), str(str_) { }
unsigned int number; unsigned int number;
unsigned int rowCode; // Terminology of the apt.dat spec unsigned int rowCode; // Terminology of the apt.dat spec
std::string str; std::string str;
}; };
typedef std::vector<Line> LinesList; typedef std::vector<Line> LinesList;
struct RawAirportInfo struct RawAirportInfo {
{ // apt.dat file where the airport was defined
// apt.dat file where the airport was defined SGPath file;
SGPath file; // Row code for the airport (1, 16 or 17)
// Row code for the airport (1, 16 or 17) unsigned int rowCode;
unsigned int rowCode; // Line number in the apt.dat file where the airport definition starts
// Line number in the apt.dat file where the airport definition starts unsigned int firstLineNum;
unsigned int firstLineNum; // The whitespace-separated strings comprising the first line of the airport
// The whitespace-separated strings comprising the first line of the airport // definition
// definition std::vector<std::string> firstLineTokens;
std::vector<std::string> firstLineTokens; // Subsequent lines of the airport definition (one element per line)
// Subsequent lines of the airport definition (one element per line) LinesList otherLines;
LinesList otherLines; };
};
typedef std::unordered_map<std::string, RawAirportInfo> AirportInfoMapType; typedef std::unordered_map<std::string, RawAirportInfo> AirportInfoMapType;
typedef SGSharedPtr<FGPavement> FGPavementPtr; typedef SGSharedPtr<FGPavement> FGPavementPtr;
typedef std::vector<FGPavementPtr> NodeList; typedef std::vector<FGPavementPtr> NodeList;
APTLoader(const APTLoader&); // disable copy constructor APTLoader(const APTLoader&); // disable copy constructor
APTLoader& operator=(const APTLoader&); // disable copy-assignment operator APTLoader& operator=(const APTLoader&); // disable copy-assignment operator
const FGAirport* loadAirport(const 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 // Tell whether an apt.dat line is blank or a comment line
bool isBlankOrCommentLine(const std::string& line); bool isBlankOrCommentLine(const std::string& line);
// Return a copy of 'line' with trailing '\r' char(s) removed // Return a copy of 'line' with trailing '\r' char(s) removed
std::string cleanLine(const std::string& line); std::string cleanLine(const std::string& line);
void throwExceptionIfStreamError(const sg_gzifstream& input_stream, void throwExceptionIfStreamError(const sg_gzifstream& input_stream,
const SGPath& path); const SGPath& path);
void parseAirportLine(unsigned int rowCode, void parseAirportLine(unsigned int rowCode,
const std::vector<std::string>& token);
void finishAirport(const std::string& aptDat);
void parseRunwayLine810(const std::string& aptDat, unsigned int lineNum,
const std::vector<std::string>& token); const std::vector<std::string>& token);
void parseRunwayLine850(const std::string& aptDat, unsigned int lineNum, void finishAirport(const std::string& aptDat);
const std::vector<std::string>& token); void parseRunwayLine810(const std::string& aptDat, unsigned int lineNum,
void parseWaterRunwayLine850(const std::string& aptDat, unsigned int lineNum, const std::vector<std::string>& token);
const std::vector<std::string>& token); void parseRunwayLine850(const std::string& aptDat, unsigned int lineNum,
void parseHelipadLine850(const std::string& aptDat, unsigned int lineNum, const std::vector<std::string>& token);
const std::vector<std::string>& token); void parseWaterRunwayLine850(const std::string& aptDat, unsigned int lineNum,
void parseViewpointLine(const std::string& aptDat, unsigned int lineNum, const std::vector<std::string>& token);
const std::vector<std::string>& token); void parseHelipadLine850(const std::string& aptDat, unsigned int lineNum,
void parsePavementLine850(const std::vector<std::string>& token); const std::vector<std::string>& token);
void parseNodeLine850( void parseViewpointLine(const std::string& aptDat, unsigned int lineNum,
NodeList *nodelist, const std::vector<std::string>& token);
const std::string& aptDat, unsigned int lineNum, int rowCode, void parsePavementLine850(const std::vector<std::string>& token);
const std::vector<std::string>& token); void parseNodeLine850(
NodeList* nodelist,
const std::string& aptDat, unsigned int lineNum, int rowCode,
const std::vector<std::string>& token);
void parseCommLine( void parseCommLine(
const std::string& aptDat, unsigned int lineNum, unsigned int rowCode, const std::string& aptDat, unsigned int lineNum, unsigned int rowCode,
const std::vector<std::string>& token); const std::vector<std::string>& token);
std::vector<std::string> token; std::vector<std::string> token;
AirportInfoMapType airportInfoMap; AirportInfoMapType airportInfoMap;
double rwy_lat_accum; double rwy_lat_accum;
double rwy_lon_accum; double rwy_lon_accum;
double last_rwy_heading; double last_rwy_heading;
int rwy_count; int rwy_count;
std::string last_apt_id; std::string last_apt_id;
double last_apt_elev; double last_apt_elev;
SGGeod tower; SGGeod tower;
std::string pavement_ident; std::string pavement_ident;
NodeList pavements; NodeList pavements;
NodeList airport_boundary; NodeList airport_boundary;
NodeList linear_feature; NodeList linear_feature;
// Not an airport identifier in the sense of the apt.dat spec! // Not an airport identifier in the sense of the apt.dat spec!
PositionedID currentAirportPosID; PositionedID currentAirportPosID;
NavDataCache* cache; NavDataCache* cache;
// Enum to keep track of whether we are tracking a pavement, airport boundary // Enum to keep track of whether we are tracking a pavement, airport boundary
// or linear feature when parsing the file. // or linear feature when parsing the file.
enum NodeBlock { None, Pavement, AirportBoundary, LinearFeature}; enum NodeBlock { None,
Pavement,
AirportBoundary,
LinearFeature };
}; };
bool metarDataLoad(const SGPath& path); bool metarDataLoad(const SGPath& path);
} // of namespace flighgear } // namespace flightgear
#endif // _FG_APT_LOADER_HXX

View file

@ -1,22 +1,9 @@
// dynamics.cxx - Code to manage the higher order airport ground activities /*
// Written by Durk Talsma, started December 2004. * SPDX-FileName: dynamics.cxx
// * SPDX-FileComment: Code to manage the higher order airport ground activities
// * SPDX-FileCopyrightText: Written by Durk Talsma, started December 2004
// This program is free software; you can redistribute it and/or * SPDX-License-Identifier: GPL-2.0-or-later
// 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$
#include <config.h> #include <config.h>
@ -236,8 +223,8 @@ void FGAirportDynamics::init()
groundController.init(); groundController.init();
} }
FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const string & flType, FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const std::string & flType,
const string & airline, const std::string & airline,
bool skipEmptyAirlineCode) bool skipEmptyAirlineCode)
{ {
NearbyAIObjectCache nearCache(parent()); NearbyAIObjectCache nearCache(parent());
@ -261,7 +248,7 @@ FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const stri
} }
if (!airline.empty() && !parking->getCodes().empty()) { if (!airline.empty() && !parking->getCodes().empty()) {
if (parking->getCodes().find(airline, 0) == string::npos) { if (parking->getCodes().find(airline, 0) == std::string::npos) {
continue; continue;
} }
} }
@ -302,9 +289,9 @@ bool FGAirportDynamics::hasParkings() const
} }
ParkingAssignment FGAirportDynamics::getAvailableParking(double radius, ParkingAssignment FGAirportDynamics::getAvailableParking(double radius,
const string & flType, const std::string & flType,
const string & acType, const std::string & acType,
const string & airline) const std::string & airline)
{ {
SG_UNUSED(acType); // sadly not used at the moment SG_UNUSED(acType); // sadly not used at the moment
@ -321,7 +308,7 @@ ParkingAssignment FGAirportDynamics::getAvailableParking(double radius,
} }
// fallback - ignore the airline code entirely // fallback - ignore the airline code entirely
result = innerGetAvailableParking(radius, flType, string(), false); result = innerGetAvailableParking(radius, flType, std::string(), false);
return result ? ParkingAssignment(result, this) : ParkingAssignment(); return result ? ParkingAssignment(result, this) : ParkingAssignment();
} }
@ -514,8 +501,8 @@ public:
} }
// becuase runways were sorted by score when building, they were added // because runways were sorted by score when building, they were added
// by score also, so we can use a simple algorithim to assign // by score also, so we can use a simple algorithm to assign
for (unsigned int r=0; r < runways.size(); ++r) { for (unsigned int r=0; r < runways.size(); ++r) {
if ((r % 2) == 0) { if ((r % 2) == 0) {
arrivals.push_back(runways[r]); arrivals.push_back(runways[r]);
@ -527,7 +514,7 @@ public:
std::string dump() std::string dump()
{ {
ostringstream os; std::ostringstream os;
os << runways.front()->ident(); os << runways.front()->ident();
for (unsigned int r=1; r <runways.size(); ++r) { for (unsigned int r=1; r <runways.size(); ++r) {
os << ", " << runways[r]->ident(); os << ", " << runways[r]->ident();
@ -580,7 +567,7 @@ public:
} }
}; };
string FGAirportDynamics::fallbackGetActiveRunway(int action, double heading) std::string FGAirportDynamics::fallbackGetActiveRunway(int action, double heading)
{ {
bool updateNeeded = false; bool updateNeeded = false;
if (_lastFallbackUpdate == SGTimeStamp()) { if (_lastFallbackUpdate == SGTimeStamp()) {
@ -686,16 +673,16 @@ string FGAirportDynamics::fallbackGetActiveRunway(int action, double heading)
return r->ident(); return r->ident();
} }
bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType, bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
int action, string & runway, int action, std::string & runway,
double heading) double heading)
{ {
double windSpeed; double windSpeed;
double windHeading; double windHeading;
double maxTail; double maxTail;
double maxCross; double maxCross;
string name; std::string name;
string type; std::string type;
if (!rwyPrefs.available()) { if (!rwyPrefs.available()) {
runway = fallbackGetActiveRunway(action, heading); runway = fallbackGetActiveRunway(action, heading);
@ -721,7 +708,7 @@ bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType,
windSpeed = fgGetInt("/environment/metar/base-wind-speed-kt"); //stationweather.get_wind_speed_kt(); windSpeed = fgGetInt("/environment/metar/base-wind-speed-kt"); //stationweather.get_wind_speed_kt();
windHeading = fgGetInt("/environment/metar/base-wind-dir-deg"); windHeading = fgGetInt("/environment/metar/base-wind-dir-deg");
//stationweather.get_wind_from_heading_deg(); //stationweather.get_wind_from_heading_deg();
string scheduleName; std::string scheduleName;
//cerr << "finding active Runway for : " << _ap->getId() << endl; //cerr << "finding active Runway for : " << _ap->getId() << endl;
//cerr << "Wind Heading : " << windHeading << endl; //cerr << "Wind Heading : " << windHeading << endl;
//cerr << "Wind Speed : " << windSpeed << endl; //cerr << "Wind Speed : " << windSpeed << endl;
@ -823,12 +810,12 @@ bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType,
return true; return true;
} }
string FGAirportDynamics::chooseRwyByHeading(stringVec rwys, std::string FGAirportDynamics::chooseRwyByHeading(stringVec rwys,
double heading) double heading)
{ {
double bestError = 360.0; double bestError = 360.0;
double rwyHeading, headingError; double rwyHeading, headingError;
string runway; std::string runway;
for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) { for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) {
if (!_ap->hasRunwayWithIdent(*i)) { if (!_ap->hasRunwayWithIdent(*i)) {
SG_LOG(SG_ATC, SG_WARN, "chooseRwyByHeading: runway " << *i << SG_LOG(SG_ATC, SG_WARN, "chooseRwyByHeading: runway " << *i <<
@ -850,8 +837,8 @@ string FGAirportDynamics::chooseRwyByHeading(stringVec rwys,
return runway; return runway;
} }
void FGAirportDynamics::getActiveRunway(const string & trafficType, void FGAirportDynamics::getActiveRunway(const std::string & trafficType,
int action, string & runway, int action, std::string & runway,
double heading) double heading)
{ {
bool ok = innerGetActiveRunway(trafficType, action, runway, heading); bool ok = innerGetActiveRunway(trafficType, action, runway, heading);
@ -860,7 +847,7 @@ void FGAirportDynamics::getActiveRunway(const string & trafficType,
} }
} }
string FGAirportDynamics::chooseRunwayFallback() std::string FGAirportDynamics::chooseRunwayFallback()
{ {
FGRunway *rwy = _ap->getActiveRunwayForUsage(); FGRunway *rwy = _ap->getActiveRunwayForUsage();
if (!rwy) { if (!rwy) {
@ -877,7 +864,7 @@ double FGAirportDynamics::getElevation() const
return _ap->getElevation(); return _ap->getElevation();
} }
const string FGAirportDynamics::getId() const const std::string FGAirportDynamics::getId() const
{ {
return _ap->getId(); return _ap->getId();
} }