1
0
Fork 0

Maintenance: SchedFlight

header guard.
compareScheduledFlights() moved to a static member with const parameters.
ctor initialization moved to intializer-list.
replace NULL with nullptr.
spelling.
This commit is contained in:
scttgs0 2023-05-26 19:48:12 -05:00
parent e25f1c5ff1
commit b6b398b4c6
2 changed files with 47 additions and 53 deletions

View file

@ -44,8 +44,6 @@
#include <time.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
@ -59,46 +57,43 @@
#include <AIModel/AIManager.hxx>
#include <Airports/airport.hxx>
#include <Main/globals.hxx>
#include "SchedFlight.hxx"
using std::string;
/******************************************************************************
* FGScheduledFlight stuff
*****************************************************************************/
std::map<std::string, std::string> FGScheduledFlight::missingAirports = std::map<std::string, std::string>();
FGScheduledFlight::FGScheduledFlight()
FGScheduledFlight::FGScheduledFlight() : departurePort{nullptr},
arrivalPort{nullptr},
departureTime{0},
arrivalTime{0},
repeatPeriod{0}
{
departureTime = 0;
arrivalTime = 0;
cruiseAltitude = 0;
repeatPeriod = 0;
initialized = false;
available = true;
departurePort = NULL;
arrivalPort = NULL;
}
FGScheduledFlight::FGScheduledFlight(const FGScheduledFlight &other)
FGScheduledFlight::FGScheduledFlight(const FGScheduledFlight &other) : callsign{other.callsign},
fltRules{other.fltRules},
departurePort{other.departurePort},
arrivalPort{other.arrivalPort},
depId{other.depId},
arrId{other.arrId},
requiredAircraft{other.requiredAircraft},
departureTime{other.departureTime},
arrivalTime{other.arrivalTime},
repeatPeriod{other.repeatPeriod}
{
callsign = other.callsign;
fltRules = other.fltRules;
departurePort = other.departurePort;
depId = other.depId;
arrId = other.arrId;
departureTime = other.departureTime;
cruiseAltitude = other.cruiseAltitude;
arrivalPort = other.arrivalPort;
arrivalTime = other.arrivalTime;
repeatPeriod = other.repeatPeriod;
initialized = other.initialized;
requiredAircraft = other.requiredAircraft;
available = other.available;
}
@ -117,19 +112,21 @@ FGScheduledFlight::FGScheduledFlight(const string& cs,
const string& deptime,
const string& arrtime,
const string& rep,
const string& reqAC)
const string& reqAC) : callsign{cs},
fltRules{fr},
departurePort{nullptr},
arrivalPort{nullptr},
depId{depPrt},
arrId{arrPrt},
requiredAircraft{reqAC}
{
callsign = cs;
fltRules = fr;
//departurePort.setId(depPrt);
//arrivalPort.setId(arrPrt);
depId = depPrt;
arrId = arrPrt;
//cerr << "Constructor: departure " << depId << ". arrival " << arrId << endl;
//departureTime = processTimeString(deptime);
//arrivalTime = processTimeString(arrtime);
cruiseAltitude = cruiseAlt;
requiredAircraft = reqAC;
// Process the repeat period string
if (rep.find("WEEK",0) != string::npos)
@ -188,11 +185,11 @@ time_t FGScheduledFlight::processTimeString(const string& theTime)
// okay first split theTime string into
// weekday, hour, minute, second;
// Check if a week day is specified
const auto daySeperatorPos = timeCopy.find("/", 0);
if (daySeperatorPos != string::npos) {
const int weekday = std::stoi(timeCopy.substr(0, daySeperatorPos));
const auto daySeparatorPos = timeCopy.find("/", 0);
if (daySeparatorPos != string::npos) {
const int weekday = std::stoi(timeCopy.substr(0, daySeparatorPos));
timeOffsetInDays = weekday - currTimeDate->getGmt()->tm_wday;
timeCopy = theTime.substr(daySeperatorPos + 1);
timeCopy = theTime.substr(daySeparatorPos + 1);
}
const auto timeTokens = simgear::strutils::split(timeCopy, ":");
@ -290,7 +287,7 @@ bool FGScheduledFlight::initializeAirports()
{
//cerr << "Initializing using : " << depId << " " << arrId << endl;
departurePort = FGAirport::findByIdent(depId);
if(departurePort == NULL)
if(departurePort == nullptr)
{
if (!FGScheduledFlight::missingAirports.count(depId)) {
FGScheduledFlight::missingAirports.insert(std::pair<std::string,std::string>(depId, depId));
@ -299,7 +296,7 @@ bool FGScheduledFlight::initializeAirports()
return false;
}
arrivalPort = FGAirport::findByIdent(arrId);
if(arrivalPort == NULL)
if(arrivalPort == nullptr)
{
if (!FGScheduledFlight::missingAirports.count(arrId)) {
FGScheduledFlight::missingAirports.insert(std::pair<std::string,std::string>(arrId, arrId));
@ -314,7 +311,7 @@ bool FGScheduledFlight::initializeAirports()
return true;
}
bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b)
bool FGScheduledFlight::compareScheduledFlights(const FGScheduledFlight *a, const FGScheduledFlight *b)
{
return (*a) < (*b);
};

View file

@ -26,19 +26,18 @@
* scheduled flight (if any) is currently active. I no scheduled flights
* are found active, it tries to position the aircraft associated with this
* schedule at departure airport of the next scheduled flight.
* The class ScheduledFlight is a software implimentation of this.
* The class ScheduledFlight is a software implementation of this.
* In summary, this class stores arrival and departure information, as well
* as some administrative data, such as the callsign of this particular
* flight (used in future ATC scenarios), under which flight rules the
* flight is taking place, as well as a requested initial cruise altitude.
* Finally, the class contains a repeat period, wich indicates after how
* Finally, the class contains a repeat period, which indicates after how
* many seconds a flight should repeat in this schedule (which is usually
* after either a day or a week). If this value is zero, this flight won't
* repeat.
**************************************************************************/
#ifndef _FGSCHEDFLIGHT_HXX_
#define _FGSCHEDFLIGHT_HXX_
#pragma once
class FGAirport;
@ -50,21 +49,22 @@ private:
std::string callsign;
std::string fltRules;
FGAirport *departurePort;
FGAirport *arrivalPort;
std::string depId;
std::string arrId;
std::string requiredAircraft;
time_t departureTime;
time_t arrivalTime;
time_t repeatPeriod;
int cruiseAltitude;
int cruiseAltitude;
bool initialized;
bool available;
public:
FGScheduledFlight();
FGScheduledFlight(const FGScheduledFlight &other);
@ -113,14 +113,11 @@ public:
void setCallSign(const std::string& val) { callsign = val; };
void setFlightRules(const std::string& val) { fltRules = val; };
static bool compareScheduledFlights(const FGScheduledFlight *a, const FGScheduledFlight *b);
};
typedef std::vector<FGScheduledFlight*> FGScheduledFlightVec;
typedef std::vector<FGScheduledFlight*>::iterator FGScheduledFlightVecIterator;
typedef std::map < std::string, FGScheduledFlightVec > FGScheduledFlightMap;
bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b);
#endif