From fca4c7dbe2348ee5798d3bd5c78f44bacb32e288 Mon Sep 17 00:00:00 2001 From: scttgs0 Date: Sat, 20 May 2023 17:13:11 -0500 Subject: [PATCH] Maintenance: namespace Clean up namespaces. Don't use broad 'using namespace' context in header files. Header Guards. SPDX tags. --- src/Aircraft/continuous.cxx | 2 +- src/Airports/AirportBuilder.cxx | 30 +---- src/Airports/airport.cxx | 33 ++--- src/Airports/apt_loader.hxx | 227 +++++++++++++++----------------- src/Airports/dynamics.cxx | 69 ++++------ 5 files changed, 149 insertions(+), 212 deletions(-) diff --git a/src/Aircraft/continuous.cxx b/src/Aircraft/continuous.cxx index bc8eaa959..0741e025b 100644 --- a/src/Aircraft/continuous.cxx +++ b/src/Aircraft/continuous.cxx @@ -81,7 +81,7 @@ static std::string read_string(std::istream& in, size_t& pos) static int PropertiesWrite(SGPropertyNode* root, std::ostream& out) { - stringstream buffer; + std::stringstream buffer; writeProperties(buffer, root, true /*write_all*/); uint32_t buffer_len = buffer.str().size() + 1; writeRaw(out, buffer_len); diff --git a/src/Airports/AirportBuilder.cxx b/src/Airports/AirportBuilder.cxx index d6cfb63e5..f18382f53 100644 --- a/src/Airports/AirportBuilder.cxx +++ b/src/Airports/AirportBuilder.cxx @@ -1,25 +1,9 @@ -// AirportBuilder.hxx -- Builder to create airports based on airport data for -// rendering in the scenery -// -// Written by Stuart Buchanan, started June 2020 -// -// 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$ +/* + * SPDX-FileName: AirportBuilder.cxx + * SPDX-FileComment: Builder to create airports based on airport data for rendering in the scenery + * SPDX-FileCopyrightText: Copyright (C) 2020 Stuart Buchanan stuart13@gmail.com + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include @@ -86,7 +70,7 @@ osgDB::ReaderWriter::ReadResult AirportBuilder::readNode(const std::string& file if (! aptFile.isFile()) return ReadResult::FILE_NOT_HANDLED;; - const string airportId = aptFile.file_base(); + const std::string airportId = aptFile.file_base(); APTLoader aptLoader; const FGAirport* airport = aptLoader.loadAirportFromFile(airportId, aptFile); diff --git a/src/Airports/airport.cxx b/src/Airports/airport.cxx index 4b7401a39..74853f47c 100644 --- a/src/Airports/airport.cxx +++ b/src/Airports/airport.cxx @@ -1,25 +1,10 @@ -// airport.cxx -- Classes representing airports, seaports and helipads -// -// Written by Curtis Olson, started April 1998. -// Updated by Durk Talsma, started December, 2004. -// -// Copyright (C) 1998 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: airport.cxx + * SPDX-FileComment: Classes representing airports, seaports and helipads + * SPDX-FileCopyrightText: Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt + * SPDX-FileContributor: Updated by Durk Talsma, started December, 2004 + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include @@ -1072,7 +1057,7 @@ flightgear::Transition* FGAirport::selectSIDByEnrouteTransition(FGPositioned* en return nullptr; } -Transition *FGAirport::selectSIDByTransition(const FGRunway* runway, const string &aIdent) const +Transition *FGAirport::selectSIDByTransition(const FGRunway* runway, const std::string &aIdent) const { loadProcedures(); for (auto sid : mSIDs) { @@ -1099,7 +1084,7 @@ flightgear::Transition* FGAirport::selectSTARByEnrouteTransition(FGPositioned* e return nullptr; } -Transition *FGAirport::selectSTARByTransition(const FGRunway* runway, const string &aIdent) const +Transition *FGAirport::selectSTARByTransition(const FGRunway* runway, const std::string &aIdent) const { loadProcedures(); for (auto star : mSTARs) { diff --git a/src/Airports/apt_loader.hxx b/src/Airports/apt_loader.hxx index 9fb578c3d..f789d8580 100644 --- a/src/Airports/apt_loader.hxx +++ b/src/Airports/apt_loader.hxx @@ -1,160 +1,141 @@ -// apt_loader.hxx -- a front end loader of the apt.dat file. This loader -// populates the runway and basic classes. -// -// Written by Curtis Olson, started December 2004. -// -// 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$ +/* + * SPDX-FileName: apt_loader.hxx + * 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 + */ +#pragma once -#ifndef _FG_APT_LOADER_HXX -#define _FG_APT_LOADER_HXX - -#include -#include -#include #include "airport.hxx" +#include +#include +#include +#include #include -#include #include #include -#include +#include + class NavDataCache; class sg_gzifstream; class FGPavement; -namespace flightgear -{ +namespace flightgear { class APTLoader { public: - APTLoader(); - ~APTLoader(); + APTLoader(); + ~APTLoader(); - // Read the specified apt.dat file into 'airportInfoMap'. - // 'bytesReadSoFar' and 'totalSizeOfAllAptDatFiles' are used for progress - // information. - void readAptDatFile(const SGPath& aptdb_file, std::size_t bytesReadSoFar, - std::size_t totalSizeOfAllAptDatFiles); - // Read all airports gathered in 'airportInfoMap' and load them into the - // navdata cache (even in case of overlapping apt.dat files, - // 'airportInfoMap' has only one entry per airport). - void loadAirports(); + // Read the specified apt.dat file into 'airportInfoMap'. + // 'bytesReadSoFar' and 'totalSizeOfAllAptDatFiles' are used for progress + // information. + void readAptDatFile(const SGPath& aptdb_file, std::size_t bytesReadSoFar, + std::size_t totalSizeOfAllAptDatFiles); + // Read all airports gathered in 'airportInfoMap' and load them into the + // navdata cache (even in case of overlapping apt.dat files, + // 'airportInfoMap' has only one entry per airport). + void loadAirports(); - // 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); + // 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); private: - struct Line - { - Line(unsigned int number_, unsigned int rowCode_, std::string str_) - : number(number_), rowCode(rowCode_), str(str_) { } + struct Line { + Line(unsigned int number_, unsigned int rowCode_, std::string str_) + : number(number_), rowCode(rowCode_), str(str_) {} - unsigned int number; - unsigned int rowCode; // Terminology of the apt.dat spec - std::string str; - }; + unsigned int number; + unsigned int rowCode; // Terminology of the apt.dat spec + std::string str; + }; - typedef std::vector LinesList; + typedef std::vector LinesList; - struct RawAirportInfo - { - // apt.dat file where the airport was defined - SGPath file; - // Row code for the airport (1, 16 or 17) - unsigned int rowCode; - // Line number in the apt.dat file where the airport definition starts - unsigned int firstLineNum; - // The whitespace-separated strings comprising the first line of the airport - // definition - std::vector firstLineTokens; - // Subsequent lines of the airport definition (one element per line) - LinesList otherLines; - }; + struct RawAirportInfo { + // apt.dat file where the airport was defined + SGPath file; + // Row code for the airport (1, 16 or 17) + unsigned int rowCode; + // Line number in the apt.dat file where the airport definition starts + unsigned int firstLineNum; + // The whitespace-separated strings comprising the first line of the airport + // definition + std::vector firstLineTokens; + // Subsequent lines of the airport definition (one element per line) + LinesList otherLines; + }; - typedef std::unordered_map AirportInfoMapType; - typedef SGSharedPtr FGPavementPtr; - typedef std::vector NodeList; + typedef std::unordered_map AirportInfoMapType; + typedef SGSharedPtr FGPavementPtr; + typedef std::vector NodeList; - APTLoader(const APTLoader&); // disable copy constructor - APTLoader& operator=(const APTLoader&); // disable copy-assignment operator + APTLoader(const APTLoader&); // disable copy constructor + 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 - bool isBlankOrCommentLine(const std::string& line); - // Return a copy of 'line' with trailing '\r' char(s) removed - std::string cleanLine(const std::string& line); - void throwExceptionIfStreamError(const sg_gzifstream& input_stream, - const SGPath& path); - void parseAirportLine(unsigned int rowCode, - const std::vector& token); - void finishAirport(const std::string& aptDat); - void parseRunwayLine810(const std::string& aptDat, unsigned int lineNum, + // Tell whether an apt.dat line is blank or a comment line + bool isBlankOrCommentLine(const std::string& line); + // Return a copy of 'line' with trailing '\r' char(s) removed + std::string cleanLine(const std::string& line); + void throwExceptionIfStreamError(const sg_gzifstream& input_stream, + const SGPath& path); + void parseAirportLine(unsigned int rowCode, const std::vector& token); - void parseRunwayLine850(const std::string& aptDat, unsigned int lineNum, - const std::vector& token); - void parseWaterRunwayLine850(const std::string& aptDat, unsigned int lineNum, - const std::vector& token); - void parseHelipadLine850(const std::string& aptDat, unsigned int lineNum, - const std::vector& token); - void parseViewpointLine(const std::string& aptDat, unsigned int lineNum, - const std::vector& token); - void parsePavementLine850(const std::vector& token); - void parseNodeLine850( - NodeList *nodelist, - const std::string& aptDat, unsigned int lineNum, int rowCode, - const std::vector& token); + void finishAirport(const std::string& aptDat); + void parseRunwayLine810(const std::string& aptDat, unsigned int lineNum, + const std::vector& token); + void parseRunwayLine850(const std::string& aptDat, unsigned int lineNum, + const std::vector& token); + void parseWaterRunwayLine850(const std::string& aptDat, unsigned int lineNum, + const std::vector& token); + void parseHelipadLine850(const std::string& aptDat, unsigned int lineNum, + const std::vector& token); + void parseViewpointLine(const std::string& aptDat, unsigned int lineNum, + const std::vector& token); + void parsePavementLine850(const std::vector& token); + void parseNodeLine850( + NodeList* nodelist, + const std::string& aptDat, unsigned int lineNum, int rowCode, + const std::vector& token); - void parseCommLine( - const std::string& aptDat, unsigned int lineNum, unsigned int rowCode, - const std::vector& token); + void parseCommLine( + const std::string& aptDat, unsigned int lineNum, unsigned int rowCode, + const std::vector& token); - std::vector token; - AirportInfoMapType airportInfoMap; - double rwy_lat_accum; - double rwy_lon_accum; - double last_rwy_heading; - int rwy_count; - std::string last_apt_id; - double last_apt_elev; - SGGeod tower; + std::vector token; + AirportInfoMapType airportInfoMap; + double rwy_lat_accum; + double rwy_lon_accum; + double last_rwy_heading; + int rwy_count; + std::string last_apt_id; + double last_apt_elev; + SGGeod tower; - std::string pavement_ident; - NodeList pavements; - NodeList airport_boundary; - NodeList linear_feature; + std::string pavement_ident; + NodeList pavements; + NodeList airport_boundary; + NodeList linear_feature; - // Not an airport identifier in the sense of the apt.dat spec! - PositionedID currentAirportPosID; - NavDataCache* cache; + // Not an airport identifier in the sense of the apt.dat spec! + PositionedID currentAirportPosID; + NavDataCache* cache; - // Enum to keep track of whether we are tracking a pavement, airport boundary - // or linear feature when parsing the file. - enum NodeBlock { None, Pavement, AirportBoundary, LinearFeature}; + // Enum to keep track of whether we are tracking a pavement, airport boundary + // or linear feature when parsing the file. + enum NodeBlock { None, + Pavement, + AirportBoundary, + LinearFeature }; }; bool metarDataLoad(const SGPath& path); -} // of namespace flighgear - -#endif // _FG_APT_LOADER_HXX +} // namespace flightgear diff --git a/src/Airports/dynamics.cxx b/src/Airports/dynamics.cxx index 16cde7fba..a252be4c0 100644 --- a/src/Airports/dynamics.cxx +++ b/src/Airports/dynamics.cxx @@ -1,22 +1,9 @@ -// dynamics.cxx - Code to manage the higher order airport ground activities -// Written by Durk Talsma, started December 2004. -// -// -// 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: dynamics.cxx + * SPDX-FileComment: Code to manage the higher order airport ground activities + * SPDX-FileCopyrightText: Written by Durk Talsma, started December 2004 + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include @@ -236,8 +223,8 @@ void FGAirportDynamics::init() groundController.init(); } -FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const string & flType, - const string & airline, +FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const std::string & flType, + const std::string & airline, bool skipEmptyAirlineCode) { NearbyAIObjectCache nearCache(parent()); @@ -261,7 +248,7 @@ FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const stri } if (!airline.empty() && !parking->getCodes().empty()) { - if (parking->getCodes().find(airline, 0) == string::npos) { + if (parking->getCodes().find(airline, 0) == std::string::npos) { continue; } } @@ -302,9 +289,9 @@ bool FGAirportDynamics::hasParkings() const } ParkingAssignment FGAirportDynamics::getAvailableParking(double radius, - const string & flType, - const string & acType, - const string & airline) + const std::string & flType, + const std::string & acType, + const std::string & airline) { SG_UNUSED(acType); // sadly not used at the moment @@ -321,7 +308,7 @@ ParkingAssignment FGAirportDynamics::getAvailableParking(double radius, } // 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(); } @@ -514,8 +501,8 @@ public: } - // becuase runways were sorted by score when building, they were added - // by score also, so we can use a simple algorithim to assign + // because runways were sorted by score when building, they were added + // by score also, so we can use a simple algorithm to assign for (unsigned int r=0; r < runways.size(); ++r) { if ((r % 2) == 0) { arrivals.push_back(runways[r]); @@ -527,7 +514,7 @@ public: std::string dump() { - ostringstream os; + std::ostringstream os; os << runways.front()->ident(); for (unsigned int r=1; 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; if (_lastFallbackUpdate == SGTimeStamp()) { @@ -686,16 +673,16 @@ string FGAirportDynamics::fallbackGetActiveRunway(int action, double heading) return r->ident(); } -bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType, - int action, string & runway, +bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType, + int action, std::string & runway, double heading) { double windSpeed; double windHeading; double maxTail; double maxCross; - string name; - string type; + std::string name; + std::string type; if (!rwyPrefs.available()) { 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(); windHeading = fgGetInt("/environment/metar/base-wind-dir-deg"); //stationweather.get_wind_from_heading_deg(); - string scheduleName; + std::string scheduleName; //cerr << "finding active Runway for : " << _ap->getId() << endl; //cerr << "Wind Heading : " << windHeading << endl; //cerr << "Wind Speed : " << windSpeed << endl; @@ -823,12 +810,12 @@ bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType, return true; } -string FGAirportDynamics::chooseRwyByHeading(stringVec rwys, +std::string FGAirportDynamics::chooseRwyByHeading(stringVec rwys, double heading) { double bestError = 360.0; double rwyHeading, headingError; - string runway; + std::string runway; for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) { if (!_ap->hasRunwayWithIdent(*i)) { SG_LOG(SG_ATC, SG_WARN, "chooseRwyByHeading: runway " << *i << @@ -850,8 +837,8 @@ string FGAirportDynamics::chooseRwyByHeading(stringVec rwys, return runway; } -void FGAirportDynamics::getActiveRunway(const string & trafficType, - int action, string & runway, +void FGAirportDynamics::getActiveRunway(const std::string & trafficType, + int action, std::string & runway, double 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(); if (!rwy) { @@ -877,7 +864,7 @@ double FGAirportDynamics::getElevation() const return _ap->getElevation(); } -const string FGAirportDynamics::getId() const +const std::string FGAirportDynamics::getId() const { return _ap->getId(); }