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:
parent
e25f1c5ff1
commit
b6b398b4c6
2 changed files with 47 additions and 53 deletions
|
@ -44,8 +44,6 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -59,46 +57,43 @@
|
||||||
#include <AIModel/AIManager.hxx>
|
#include <AIModel/AIManager.hxx>
|
||||||
#include <Airports/airport.hxx>
|
#include <Airports/airport.hxx>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
|
||||||
#include "SchedFlight.hxx"
|
#include "SchedFlight.hxx"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* FGScheduledFlight stuff
|
* FGScheduledFlight stuff
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
std::map<std::string, std::string> FGScheduledFlight::missingAirports = std::map<std::string, std::string>();
|
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;
|
cruiseAltitude = 0;
|
||||||
repeatPeriod = 0;
|
|
||||||
initialized = false;
|
initialized = false;
|
||||||
available = true;
|
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;
|
cruiseAltitude = other.cruiseAltitude;
|
||||||
arrivalPort = other.arrivalPort;
|
|
||||||
arrivalTime = other.arrivalTime;
|
|
||||||
repeatPeriod = other.repeatPeriod;
|
|
||||||
initialized = other.initialized;
|
initialized = other.initialized;
|
||||||
requiredAircraft = other.requiredAircraft;
|
|
||||||
available = other.available;
|
available = other.available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,19 +112,21 @@ FGScheduledFlight::FGScheduledFlight(const string& cs,
|
||||||
const string& deptime,
|
const string& deptime,
|
||||||
const string& arrtime,
|
const string& arrtime,
|
||||||
const string& rep,
|
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);
|
//departurePort.setId(depPrt);
|
||||||
//arrivalPort.setId(arrPrt);
|
//arrivalPort.setId(arrPrt);
|
||||||
depId = depPrt;
|
|
||||||
arrId = arrPrt;
|
|
||||||
//cerr << "Constructor: departure " << depId << ". arrival " << arrId << endl;
|
//cerr << "Constructor: departure " << depId << ". arrival " << arrId << endl;
|
||||||
//departureTime = processTimeString(deptime);
|
//departureTime = processTimeString(deptime);
|
||||||
//arrivalTime = processTimeString(arrtime);
|
//arrivalTime = processTimeString(arrtime);
|
||||||
cruiseAltitude = cruiseAlt;
|
cruiseAltitude = cruiseAlt;
|
||||||
requiredAircraft = reqAC;
|
|
||||||
|
|
||||||
// Process the repeat period string
|
// Process the repeat period string
|
||||||
if (rep.find("WEEK",0) != string::npos)
|
if (rep.find("WEEK",0) != string::npos)
|
||||||
|
@ -188,11 +185,11 @@ time_t FGScheduledFlight::processTimeString(const string& theTime)
|
||||||
// okay first split theTime string into
|
// okay first split theTime string into
|
||||||
// weekday, hour, minute, second;
|
// weekday, hour, minute, second;
|
||||||
// Check if a week day is specified
|
// Check if a week day is specified
|
||||||
const auto daySeperatorPos = timeCopy.find("/", 0);
|
const auto daySeparatorPos = timeCopy.find("/", 0);
|
||||||
if (daySeperatorPos != string::npos) {
|
if (daySeparatorPos != string::npos) {
|
||||||
const int weekday = std::stoi(timeCopy.substr(0, daySeperatorPos));
|
const int weekday = std::stoi(timeCopy.substr(0, daySeparatorPos));
|
||||||
timeOffsetInDays = weekday - currTimeDate->getGmt()->tm_wday;
|
timeOffsetInDays = weekday - currTimeDate->getGmt()->tm_wday;
|
||||||
timeCopy = theTime.substr(daySeperatorPos + 1);
|
timeCopy = theTime.substr(daySeparatorPos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto timeTokens = simgear::strutils::split(timeCopy, ":");
|
const auto timeTokens = simgear::strutils::split(timeCopy, ":");
|
||||||
|
@ -290,7 +287,7 @@ bool FGScheduledFlight::initializeAirports()
|
||||||
{
|
{
|
||||||
//cerr << "Initializing using : " << depId << " " << arrId << endl;
|
//cerr << "Initializing using : " << depId << " " << arrId << endl;
|
||||||
departurePort = FGAirport::findByIdent(depId);
|
departurePort = FGAirport::findByIdent(depId);
|
||||||
if(departurePort == NULL)
|
if(departurePort == nullptr)
|
||||||
{
|
{
|
||||||
if (!FGScheduledFlight::missingAirports.count(depId)) {
|
if (!FGScheduledFlight::missingAirports.count(depId)) {
|
||||||
FGScheduledFlight::missingAirports.insert(std::pair<std::string,std::string>(depId, depId));
|
FGScheduledFlight::missingAirports.insert(std::pair<std::string,std::string>(depId, depId));
|
||||||
|
@ -299,7 +296,7 @@ bool FGScheduledFlight::initializeAirports()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
arrivalPort = FGAirport::findByIdent(arrId);
|
arrivalPort = FGAirport::findByIdent(arrId);
|
||||||
if(arrivalPort == NULL)
|
if(arrivalPort == nullptr)
|
||||||
{
|
{
|
||||||
if (!FGScheduledFlight::missingAirports.count(arrId)) {
|
if (!FGScheduledFlight::missingAirports.count(arrId)) {
|
||||||
FGScheduledFlight::missingAirports.insert(std::pair<std::string,std::string>(arrId, arrId));
|
FGScheduledFlight::missingAirports.insert(std::pair<std::string,std::string>(arrId, arrId));
|
||||||
|
@ -314,7 +311,7 @@ bool FGScheduledFlight::initializeAirports()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b)
|
bool FGScheduledFlight::compareScheduledFlights(const FGScheduledFlight *a, const FGScheduledFlight *b)
|
||||||
{
|
{
|
||||||
return (*a) < (*b);
|
return (*a) < (*b);
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,19 +26,18 @@
|
||||||
* scheduled flight (if any) is currently active. I no scheduled flights
|
* scheduled flight (if any) is currently active. I no scheduled flights
|
||||||
* are found active, it tries to position the aircraft associated with this
|
* are found active, it tries to position the aircraft associated with this
|
||||||
* schedule at departure airport of the next scheduled flight.
|
* 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
|
* In summary, this class stores arrival and departure information, as well
|
||||||
* as some administrative data, such as the callsign of this particular
|
* as some administrative data, such as the callsign of this particular
|
||||||
* flight (used in future ATC scenarios), under which flight rules the
|
* flight (used in future ATC scenarios), under which flight rules the
|
||||||
* flight is taking place, as well as a requested initial cruise altitude.
|
* 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
|
* 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
|
* after either a day or a week). If this value is zero, this flight won't
|
||||||
* repeat.
|
* repeat.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#ifndef _FGSCHEDFLIGHT_HXX_
|
#pragma once
|
||||||
#define _FGSCHEDFLIGHT_HXX_
|
|
||||||
|
|
||||||
|
|
||||||
class FGAirport;
|
class FGAirport;
|
||||||
|
@ -50,21 +49,22 @@ private:
|
||||||
|
|
||||||
std::string callsign;
|
std::string callsign;
|
||||||
std::string fltRules;
|
std::string fltRules;
|
||||||
|
|
||||||
FGAirport *departurePort;
|
FGAirport *departurePort;
|
||||||
FGAirport *arrivalPort;
|
FGAirport *arrivalPort;
|
||||||
|
|
||||||
std::string depId;
|
std::string depId;
|
||||||
std::string arrId;
|
std::string arrId;
|
||||||
std::string requiredAircraft;
|
std::string requiredAircraft;
|
||||||
|
|
||||||
time_t departureTime;
|
time_t departureTime;
|
||||||
time_t arrivalTime;
|
time_t arrivalTime;
|
||||||
time_t repeatPeriod;
|
time_t repeatPeriod;
|
||||||
int cruiseAltitude;
|
|
||||||
|
|
||||||
|
int cruiseAltitude;
|
||||||
bool initialized;
|
bool initialized;
|
||||||
bool available;
|
bool available;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FGScheduledFlight();
|
FGScheduledFlight();
|
||||||
FGScheduledFlight(const FGScheduledFlight &other);
|
FGScheduledFlight(const FGScheduledFlight &other);
|
||||||
|
@ -113,14 +113,11 @@ public:
|
||||||
|
|
||||||
void setCallSign(const std::string& val) { callsign = val; };
|
void setCallSign(const std::string& val) { callsign = val; };
|
||||||
void setFlightRules(const std::string& val) { fltRules = 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*> FGScheduledFlightVec;
|
||||||
typedef std::vector<FGScheduledFlight*>::iterator FGScheduledFlightVecIterator;
|
typedef std::vector<FGScheduledFlight*>::iterator FGScheduledFlightVecIterator;
|
||||||
|
|
||||||
typedef std::map < std::string, FGScheduledFlightVec > FGScheduledFlightMap;
|
typedef std::map < std::string, FGScheduledFlightVec > FGScheduledFlightMap;
|
||||||
|
|
||||||
bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in a new issue