1
0
Fork 0

Performance improvement: pass (const) strings by reference

to avoid copying actual string data around.
This commit is contained in:
ThorstenB 2012-11-24 11:59:13 +01:00
parent d79b2385b4
commit bb494e52e5
19 changed files with 138 additions and 147 deletions

View file

@ -1000,7 +1000,7 @@ void FGAIAircraft::updatePrimaryTargetValues(bool& flightplanActive, bool& aiOut
// from control properties. These default to the initial
// settings in the config file, but can be changed "on the
// fly".
string lat_mode = props->getStringValue("controls/flight/lateral-mode");
const string& lat_mode = props->getStringValue("controls/flight/lateral-mode");
if ( lat_mode == "roll" ) {
double angle
= props->getDoubleValue("controls/flight/target-roll" );
@ -1213,7 +1213,7 @@ void FGAIAircraft::updatePitchAngleTarget() {
}
}
string FGAIAircraft::atGate()
const string& FGAIAircraft::atGate()
{
if ((fp->getLeg() < 3) && trafficRef) {
if (fp->getParkingGate()) {
@ -1221,7 +1221,8 @@ string FGAIAircraft::atGate()
}
}
return string();
static const string empty;
return empty;
}
void FGAIAircraft::handleATCRequests() {
@ -1342,7 +1343,7 @@ double FGAIAircraft::getBearing(double crse)
return hdgDiff;
}
time_t FGAIAircraft::checkForArrivalTime(string wptName) {
time_t FGAIAircraft::checkForArrivalTime(const string& wptName) {
FGAIWaypoint* curr = 0;
curr = fp->getCurrentWaypoint();

View file

@ -52,7 +52,7 @@ public:
void initializeFlightPlan();
FGAIFlightPlan* GetFlightPlan() const { return fp; };
void ProcessFlightPlan( double dt, time_t now );
time_t checkForArrivalTime(string wptName);
time_t checkForArrivalTime(const string& wptName);
void AccelTo(double speed);
void PitchTo(double angle);
@ -68,7 +68,7 @@ public:
double getBearing(double crse);
void setAcType(const std::string& ac) { acType = ac; };
std::string getAcType() const { return acType; }
const std::string& getAcType() const { return acType; }
void setCompany(const std::string& comp) { company = comp;};
@ -86,7 +86,7 @@ public:
virtual const char* getTypeString(void) const { return "aircraft"; }
std::string GetTransponderCode() { return transponderCode; };
const std::string& GetTransponderCode() { return transponderCode; };
void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
// included as performance data needs them, who else?
@ -99,7 +99,7 @@ public:
inline double getVerticalSpeed() const { return vs; };
inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
std::string atGate();
const std::string& atGate();
int getTakeOffStatus() { return takeOffStatus; };

View file

@ -244,7 +244,7 @@ void FGAIBase::update(double dt) {
// sound initialization
if (fgGetBool("/sim/sound/aimodels/enabled",false))
{
string fxpath = _modeldata->get_sound_path();
const string& fxpath = _modeldata->get_sound_path();
if (fxpath != "")
{
props->setStringValue("sim/sound/path", fxpath.c_str());
@ -666,7 +666,7 @@ bool FGAIBase::setParentNode() {
model = _selected_ac;
} else {
model = ai->getChild(i);
string path = ai->getPath();
//const string& path = ai->getPath();
const string name = model->getStringValue("name");
if (!model->nChildren()){

View file

@ -73,7 +73,7 @@ void FGAICarrier::readFromScenario(SGPropertyNode* scFileNode) {
std::vector<SGPropertyNode_ptr> props = scFileNode->getChildren("parking-pos");
std::vector<SGPropertyNode_ptr>::const_iterator it;
for (it = props.begin(); it != props.end(); ++it) {
string name = (*it)->getStringValue("name", "unnamed");
const string name = (*it)->getStringValue("name", "unnamed");
// Transform to the right coordinate frame, configuration is done in
// the usual x-back, y-right, z-up coordinates, computations
// in the simulation usual body x-forward, y-right, z-down coordinates
@ -549,7 +549,7 @@ void FGAICarrier::UpdateElevator(double dt, double transition_time) {
void FGAICarrier::UpdateJBD(double dt, double jbd_transition_time) {
string launchbar_state = _launchbar_state_node->getStringValue();
const string launchbar_state = _launchbar_state_node->getStringValue();
double step = 0;
if (launchbar_state == "Engaged"){

View file

@ -58,7 +58,7 @@ FGAIWaypoint::FGAIWaypoint() {
trackLength = 0;
}
bool FGAIWaypoint::contains(string target) {
bool FGAIWaypoint::contains(const string& target) {
size_t found = name.find(target);
if (found == string::npos)
return false;
@ -449,7 +449,7 @@ int FGAIFlightPlan::getRouteIndex(int i) {
return 0;
}
double FGAIFlightPlan::checkTrackLength(string wptName) {
double FGAIFlightPlan::checkTrackLength(const string& wptName) {
// skip the first two waypoints: first one is behind, second one is partially done;
double trackDistance = 0;
wpt_vector_iterator wptvec = waypoints.begin();

View file

@ -54,7 +54,7 @@ private:
public:
FGAIWaypoint();
~FGAIWaypoint() {};
void setName (std::string nam) { name = nam; };
void setName (const std::string& nam) { name = nam; };
void setLatitude (double lat);
void setLongitude (double lon);
void setAltitude (double alt);
@ -68,11 +68,11 @@ public:
void setRouteIndex (int rte) { routeIndex = rte; };
void setTime_sec (double ts ) { time_sec = ts; };
void setTrackLength (double tl ) { trackLength = tl; };
void setTime (std::string tme) { time = tme; };
void setTime (const std::string& tme) { time = tme; };
bool contains(std::string name);
bool contains(const std::string& name);
std::string getName () { return name; };
const std::string& getName() { return name; };
const SGGeod& getPos () { return pos; };
double getLatitude ();
double getLongitude ();
@ -87,7 +87,7 @@ public:
bool isFinished () { return finished; };
double getTime_sec () { return time_sec; };
double getTrackLength() { return trackLength; };
std::string getTime () { return time; };
const std::string& getTime () { return time; };
};
@ -130,7 +130,7 @@ public:
double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
double checkTrackLength(std::string wptName);
double checkTrackLength(const std::string& wptName);
time_t getStartTime() const { return start_time; }
time_t getArrivalTime() const { return arrivalTime; }
@ -153,18 +153,18 @@ public:
int getRouteIndex(int i); // returns the AI related index of this current routes.
std::string getRunway() { return activeRunway; }
const std::string& getRunway() { return activeRunway; }
bool isActive(time_t time) {return time >= this->getStartTime();}
void incrementLeg() { leg++;};
void setRunway(std::string rwy) { activeRunway = rwy; };
std::string getRunwayClassFromTrafficType(std::string fltType);
void setRunway(const std::string& rwy) { activeRunway = rwy; };
const char* getRunwayClassFromTrafficType(const std::string& fltType);
void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
void setName(std::string n) { name = n; };
std::string getName() { return name; };
void setName(const std::string& n) { name = n; };
const std::string& getName() { return name; };
void setSID(FGAIFlightPlan* fp) { sid = fp;};
FGAIFlightPlan* getSID() { return sid; };
@ -175,6 +175,7 @@ public:
void setGate(ParkingAssignment pka);
FGParking* getParkingGate();
private:
FGAIFlightPlan *sid;
typedef std::vector <FGAIWaypoint*> wpt_vector_type;

View file

@ -103,6 +103,7 @@ bool FGAIFlightPlan::create(FGAIAircraft * ac, FGAirport * dep,
SG_LOG(SG_AI, SG_ALERT,
"AIFlightPlan::create() attempting to create unknown leg"
" this is probably an internal program error");
break;
}
wpt_iterator = waypoints.begin() + currWpt;
//don't increment leg right away, but only once we pass the actual last waypoint that was created.
@ -225,7 +226,7 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight,
}
}
string rwyClass = getRunwayClassFromTrafficType(fltType);
const string& rwyClass = getRunwayClassFromTrafficType(fltType);
// Only set this if it hasn't been set by ATC already.
if (activeRunway.empty()) {
@ -478,7 +479,7 @@ bool FGAIFlightPlan::createTakeOff(FGAIAircraft * ac, bool firstFlight,
// NOTE: DT (2009-01-18: IIRC, this is currently already the case,
// because the getActive runway function takes care of that.
if (firstFlight) {
string rwyClass = getRunwayClassFromTrafficType(fltType);
const string& rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading);
@ -539,7 +540,7 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight,
double vClimb = ac->getPerformance()->vClimb();
if (firstFlight) {
string rwyClass = getRunwayClassFromTrafficType(fltType);
const string& rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading);
@ -592,7 +593,7 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
double vApproach = ac->getPerformance()->vApproach();
//Beginning of Descent
string rwyClass = getRunwayClassFromTrafficType(fltType);
const string& rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway,
heading);
@ -844,7 +845,7 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
if (reposition) {
double tempDistance;
//double minDistance = HUGE_VAL;
string wptName;
//string wptName;
tempDistance = SGGeodesy::distanceM(current, initialTarget);
time_t eta =
tempDistance / ((vDescent * SG_NM_TO_METER) / 3600.0) + now;
@ -1044,21 +1045,21 @@ bool FGAIFlightPlan::createParking(FGAIAircraft * ac, FGAirport * apt,
* - ul (ultralight: I can imagine that these may share a runway with ga on some airports)
* - mil (all military traffic)
*/
string FGAIFlightPlan::getRunwayClassFromTrafficType(string fltType)
const char* FGAIFlightPlan::getRunwayClassFromTrafficType(const string& fltType)
{
if ((fltType == "gate") || (fltType == "cargo")) {
return string("com");
return "com";
}
if (fltType == "ga") {
return string("gen");
return "gen";
}
if (fltType == "ul") {
return string("ul");
return "ul";
}
if ((fltType == "mil-fighter") || (fltType == "mil-transport")) {
return string("mil");
return "mil";
}
return string("com");
return "com";
}

View file

@ -295,7 +295,7 @@ bool FGAIFlightPlan::createCruise(FGAIAircraft *ac, bool firstFlight, FGAirport
wpt = createInAir(ac, "Cruise", SGGeod::fromDeg(longitude, latitude), alt, vCruise);
pushBackWaypoint(wpt);
string rwyClass = getRunwayClassFromTrafficType(fltType);
const string& rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse();
arr->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, heading);
FGRunway* rwy = arr->getRunwayByIdent(activeRunway);

View file

@ -97,7 +97,7 @@ FGAIManager::postinit() {
if (strcmp(n->getName(), "scenario"))
continue;
string name = n->getStringValue();
const string& name = n->getStringValue();
if (name.empty())
continue;
@ -275,7 +275,7 @@ FGAIManager::processScenario( const string &filename ) {
if (strcmp(scEntry->getName(), "entry"))
continue;
std::string type = scEntry->getStringValue("type", "aircraft");
const std::string& type = scEntry->getStringValue("type", "aircraft");
if (type == "tanker") { // refueling scenarios
FGAITanker* tanker = new FGAITanker;
@ -349,8 +349,8 @@ FGAIManager::loadScenarioFile(const std::string& filename)
} catch (const sg_exception &t) {
SG_LOG(SG_AI, SG_ALERT, "Failed to load scenario '"
<< path.str() << "': " << t.getFormattedMessage());
return 0;
}
return 0;
}
bool
@ -365,16 +365,16 @@ FGAIManager::getStartPosition(const string& id, const string& pid,
for (int i = 0 ; (!found) && i < root->nChildren() ; i++) {
SGPropertyNode *aiEntry = root->getChild( i );
if ( !strcmp( aiEntry->getName(), "scenario" ) ) {
string filename = aiEntry->getStringValue();
const string& filename = aiEntry->getStringValue();
SGPropertyNode_ptr scenarioTop = loadScenarioFile(filename);
if (scenarioTop) {
SGPropertyNode* scenarios = scenarioTop->getChild("scenario");
if (scenarios) {
for (int i = 0; i < scenarios->nChildren(); i++) {
SGPropertyNode* scEntry = scenarios->getChild(i);
std::string type = scEntry->getStringValue("type");
std::string pnumber = scEntry->getStringValue("pennant-number");
std::string name = scEntry->getStringValue("name");
const std::string& type = scEntry->getStringValue("type");
const std::string& pnumber = scEntry->getStringValue("pennant-number");
const std::string& name = scEntry->getStringValue("name");
if (type == "carrier" && (pnumber == id || name == id)) {
SGSharedPtr<FGAICarrier> carrier = new FGAICarrier;
carrier->readFromScenario(scEntry);

View file

@ -54,8 +54,8 @@ bool FGAIMultiplayer::init(bool search_in_AI_path) {
isTanker = false; // do this until this property is
// passed over the net
string str1 = _getCallsign();
string str2 = "MOBIL";
const string& str1 = _getCallsign();
const string str2 = "MOBIL";
string::size_type loc1= str1.find( str2, 0 );
if ( (loc1 != string::npos && str2 != "") ){

View file

@ -90,7 +90,7 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
setRudder(scFileNode->getFloatValue("rudder", 0.0));
setName(scFileNode->getStringValue("name", "Titanic"));
setRadius(scFileNode->getDoubleValue("turn-radius-ft", 2000));
std::string flightplan = scFileNode->getStringValue("flightplan");
const std::string& flightplan = scFileNode->getStringValue("flightplan");
setRepeat(scFileNode->getBoolValue("repeat", false));
setRestart(scFileNode->getBoolValue("restart", false));
setStartTime(scFileNode->getStringValue("time", ""));
@ -265,7 +265,7 @@ void FGAIShip::Run(double dt) {
if (_fp_init)
ProcessFlightPlan(dt);
string type = getTypeString();
const string& type = getTypeString();
double alpha;
double rudder_limit;

View file

@ -47,7 +47,7 @@ PerformanceData* PerformanceDB::getDataFor(const string& acType, const string& a
return _db[acType];
}
string alias = findAlias(acType);
const string& alias = findAlias(acType);
if (_db.find(alias) != _db.end()) {
return _db[alias];
}
@ -78,7 +78,7 @@ void PerformanceDB::load(const SGPath& filename)
if (!strcmp(db_node->getName(), "aircraft")) {
PerformanceData* data = NULL;
if (db_node->hasChild("base")) {
string baseName = db_node->getStringValue("base");
const string& baseName = db_node->getStringValue("base");
PerformanceData* baseData = _db[baseName];
if (!baseData) {
SG_LOG(SG_AI, SG_ALERT,
@ -93,17 +93,17 @@ void PerformanceDB::load(const SGPath& filename)
}
data->initFromProps(db_node);
string name = db_node->getStringValue("type", "heavy_jet");
const string& name = db_node->getStringValue("type", "heavy_jet");
registerPerformanceData(name, data);
} else if (!strcmp(db_node->getName(), "alias")) {
string alias(db_node->getStringValue("alias"));
const string& alias(db_node->getStringValue("alias"));
if (alias.empty()) {
SG_LOG(SG_AI, SG_ALERT, "performance DB alias entry with no <alias> definition");
continue;
}
BOOST_FOREACH(SGPropertyNode* matchNode, db_node->getChildren("match")) {
string match(matchNode->getStringValue());
const string& match(matchNode->getStringValue());
_aliases.push_back(StringPair(match, alias));
}
} else {
@ -112,7 +112,7 @@ void PerformanceDB::load(const SGPath& filename)
} // of nodes iteration
}
string PerformanceDB::findAlias(const string& acType) const
const string& PerformanceDB::findAlias(const string& acType) const
{
BOOST_FOREACH(const StringPair& alias, _aliases) {
if (acType.find(alias.first) == 0) { // matched!
@ -120,7 +120,8 @@ string PerformanceDB::findAlias(const string& acType) const
}
} // of alias iteration
return string();
static const string empty;
return empty;
}

View file

@ -36,7 +36,7 @@ public:
private:
std::map<std::string, PerformanceData*> _db;
std::string findAlias(const std::string& acType) const;
const std::string& findAlias(const std::string& acType) const;
typedef std::pair<std::string, std::string> StringPair;
/// alias list, to allow type/class names to share data. This is used to merge

View file

@ -35,7 +35,7 @@ FGSubmodelMgr::FGSubmodelMgr()
yaw_offset = 0.0;
//out[0] = out[1] = out[2] = 0;
string contents_node;
//string contents_node;
contrail_altitude = 30000;
_count = 0;
_found_sub = true;
@ -210,7 +210,7 @@ void FGSubmodelMgr::update(double dt)
if (trigger && (*submodel_iterator)->count != 0) {
//int id = (*submodel_iterator)->id;
string name = (*submodel_iterator)->name;
//const string& name = (*submodel_iterator)->name;
SG_LOG(SG_AI, SG_DEBUG,
"Submodels release: " << (*submodel_iterator)->id
@ -319,7 +319,7 @@ void FGSubmodelMgr::load()
if (path) {
const int id = 0;
string Path = path->getStringValue();
const string& Path = path->getStringValue();
bool Seviceable =_serviceable_node->getBoolValue();
setData(id, Path, Seviceable);
}
@ -345,7 +345,7 @@ void FGSubmodelMgr::transform(submodel *sm)
int id = sm->id;
//int sub_id = sm->sub_id;
string name = sm->name;
//const string& name = sm->name;
if (sm->speed_node != 0)
@ -500,9 +500,9 @@ void FGSubmodelMgr::loadAI()
}
int id = (*sm_list_itr)->getID();
string type = (*sm_list_itr)->getTypeString();
bool serviceable = (*sm_list_itr)->_getServiceable();
//string type = (*sm_list_itr)->getTypeString();
//cout << "loadAI: type " << type << " path "<< path << " serviceable " << serviceable << endl;
setData(id, path, serviceable);
@ -512,7 +512,7 @@ void FGSubmodelMgr::loadAI()
void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
void FGSubmodelMgr::setData(int id, const string& path, bool serviceable)
{
SGPropertyNode root;
@ -598,13 +598,13 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
sm->prop->tie("serviceable", SGRawValuePointer<bool>(&(sm->serviceable)));
sm->prop->tie("random", SGRawValuePointer<bool>(&(sm->random)));
sm->prop->tie("slaved", SGRawValuePointer<bool>(&(sm->slaved)));
string name = sm->name;
const string& name = sm->name;
sm->prop->setStringValue("name", name.c_str());
string submodel = sm->submodel;
const string& submodel = sm->submodel;
sm->prop->setStringValue("submodel", submodel.c_str());
string force_path = sm->force_path;
const string& force_path = sm->force_path;
sm->prop->setStringValue("force_path", force_path.c_str());
//cout << "set force_path Sub " << force_path << endl;
@ -616,7 +616,7 @@ void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
}
}
void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
void FGSubmodelMgr::setSubData(int id, const string& path, bool serviceable)
{
SGPropertyNode root;
SGPath config = globals->resolve_aircraft_path(path);
@ -703,14 +703,14 @@ void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
sm->prop->tie("random", SGRawValuePointer<bool>(&(sm->random)));
sm->prop->tie("slaved", SGRawValuePointer<bool>(&(sm->slaved)));
string name = sm->name;
const string& name = sm->name;
sm->prop->setStringValue("name", name.c_str());
string submodel = sm->submodel;
const string& submodel = sm->submodel;
sm->prop->setStringValue("submodel-path", submodel.c_str());
// cout << " set submodel path AI" << submodel<< endl;
string force_path = sm->force_path;
const string& force_path = sm->force_path;
sm->prop->setStringValue("force_path", force_path.c_str());
//cout << "set force_path AI" << force_path << endl;
@ -731,7 +731,7 @@ void FGSubmodelMgr::loadSubmodels()
submodel_iterator = submodels.begin();
while (submodel_iterator != submodels.end()) {
string submodel = (*submodel_iterator)->submodel;
const string& submodel = (*submodel_iterator)->submodel;
if (!submodel.empty()) {
//int id = (*submodel_iterator)->id;
bool serviceable = true;
@ -841,8 +841,7 @@ void FGSubmodelMgr::valueChanged(SGPropertyNode *prop)
SGPropertyNode_ptr path_node = sub_node->getChild("path", 0, true);
SGPropertyNode_ptr callsign_node = a_node->getChild("callsign", 0, true);
string callsign = callsign_node->getStringValue();
//const string& callsign = callsign_node->getStringValue();
//cout << "Submodels: model added - " << callsign <<" read callsign "<< endl;
return;
@ -864,8 +863,8 @@ void FGSubmodelMgr::setParentNode(int id) {
model = _selected_ac;
} else {
model = ai->getChild(i);
string path = ai->getPath();
const string name = model->getStringValue("name");
//const string& path = ai->getPath();
//const string& name = model->getStringValue("name");
int parent_id = model->getIntValue("id");
if (!model->nChildren()){
continue;

View file

@ -191,8 +191,8 @@ private:
void loadAI();
void loadSubmodels();
void setData(int id, std::string& path, bool serviceable);
void setSubData(int id, std::string& path, bool serviceable);
void setData(int id, const std::string& path, bool serviceable);
void setSubData(int id, const std::string& path, bool serviceable);
void valueChanged (SGPropertyNode *);
void transform(submodel *);
void setParentNode(int parent_id);

View file

@ -65,29 +65,29 @@ private:
public:
FGScheduledFlight();
FGScheduledFlight(const FGScheduledFlight &other);
// FGScheduledFlight(const string);
FGScheduledFlight(const string& cs,
const string& fr,
const string& depPrt,
const string& arrPrt,
int cruiseAlt,
const string& deptime,
const string& arrtime,
const string& rep,
const string& reqAC
);
// FGScheduledFlight(const std::string);
FGScheduledFlight(const std::string& cs,
const std::string& fr,
const std::string& depPrt,
const std::string& arrPrt,
int cruiseAlt,
const std::string& deptime,
const std::string& arrtime,
const std::string& rep,
const std::string& reqAC
);
~FGScheduledFlight();
void update();
bool initializeAirports();
bool initializeAirports();
void adjustTime(time_t now);
time_t getDepartureTime() { return departureTime; };
time_t getArrivalTime () { return arrivalTime; };
void setDepartureAirport(string port) { depId = port; };
void setArrivalAirport (string port) { arrId = port; };
void setDepartureAirport(const std::string& port) { depId = port; };
void setArrivalAirport (const std::string& port) { arrId = port; };
FGAirport *getDepartureAirport();
FGAirport *getArrivalAirport ();
@ -97,19 +97,19 @@ public:
{
return (departureTime < other.departureTime);
};
string& getFlightRules() { return fltRules; };
const std::string& getFlightRules() { return fltRules; };
time_t processTimeString(const string& time);
const string& getCallSign() {return callsign; };
const string& getRequirement() { return requiredAircraft; }
time_t processTimeString(const std::string& time);
const std::string& getCallSign() {return callsign; };
const std::string& getRequirement() { return requiredAircraft; }
void lock() { available = false; };
void release() { available = true; };
void lock() { available = false; };
void release() { available = true; };
bool isAvailable() { return available; };
void setCallSign(string val) { callsign = val; };
void setFlightRules(string val) { fltRules = val; };
void setCallSign(const std::string& val) { callsign = val; };
void setFlightRules(const std::string& val) { fltRules = val; };
};
typedef std::vector<FGScheduledFlight*> FGScheduledFlightVec;

View file

@ -71,29 +71,17 @@ FGAISchedule::FGAISchedule()
//score = 0;
}
/*
FGAISchedule::FGAISchedule(string mdl,
string liv,
string reg,
bool hvy,
string act,
string arln,
string mclass,
string fltpe,
double rad,
double grnd,
int scre,
FGScheduledFlightVec flt)*/
FGAISchedule::FGAISchedule(string model,
string lvry,
string port,
string reg,
string flightId,
FGAISchedule::FGAISchedule(const string& model,
const string& lvry,
const string& port,
const string& reg,
const string& flightId,
bool hvy,
string act,
string arln,
string mclass,
string fltpe,
const string& act,
const string& arln,
const string& mclass,
const string& fltpe,
double rad,
double grnd)
{
@ -226,7 +214,7 @@ bool FGAISchedule::update(time_t now, const SGVec3d& userCart)
FGScheduledFlight* flight = flights.front();
if (!deptime) {
deptime = flight->getDepartureTime();
//cerr << "Settiing departure time " << deptime << endl;
//cerr << "Setting departure time " << deptime << endl;
}
if (aiAircraft) {

View file

@ -20,9 +20,9 @@
**************************************************************************/
/**************************************************************************
* This file contains the definition of the class Shedule.
* This file contains the definition of the class Schedule.
*
* A schedule is basically a number of scheduled flights, wich can be
* A schedule is basically a number of scheduled flights, which can be
* assigned to an AI aircraft.
**************************************************************************/
@ -76,16 +76,16 @@ class FGAISchedule
SGSharedPtr<FGAIAircraft> aiAircraft;
public:
FGAISchedule(); // constructor
FGAISchedule(string model,
string livery,
string homePort,
string registration,
string flightId,
FGAISchedule(const std::string& model,
const std::string& livery,
const std::string& homePort,
const std::string& registration,
const std::string& flightId,
bool heavy,
string acType,
string airline,
string m_class,
string flight_type,
const std::string& acType,
const std::string& airline,
const std::string& m_class,
const std::string& flight_type,
double radius,
double offset); // construct & init
FGAISchedule(const FGAISchedule &other); // copy constructor
@ -110,12 +110,12 @@ class FGAISchedule
int getCruiseAlt () { return (*flights.begin())->getCruiseAlt (); };
double getRadius () { return radius; };
double getGroundOffset () { return groundOffset;};
const string& getFlightType () { return flightType;};
const string& getAirline () { return airline; };
const string& getAircraft () { return acType; };
const string& getCallSign () { return (*flights.begin())->getCallSign (); };
const string& getRegistration () { return registration;};
const string& getFlightRules () { return (*flights.begin())->getFlightRules (); };
const std::string& getFlightType () { return flightType;};
const std::string& getAirline () { return airline; };
const std::string& getAircraft () { return acType; };
const std::string& getCallSign () { return (*flights.begin())->getCallSign (); };
const std::string& getRegistration () { return registration;};
const std::string& getFlightRules () { return (*flights.begin())->getFlightRules (); };
bool getHeavy () { return heavy; };
double getCourse () { return courseToDest; };
unsigned int getRunCount () { return runCount; };
@ -127,14 +127,14 @@ class FGAISchedule
double getScore () { return score; };
void setHeading ();
void assign (FGScheduledFlight *ref) { flights.push_back(ref); };
void setFlightType (string val ) { flightType = val; };
FGScheduledFlight*findAvailableFlight (const string &currentDestination, const string &req, time_t min=0, time_t max=0);
// used to sort in decending order of score: I've probably found a better way to
// decending order sorting, but still need to test that.
void setFlightType (const std::string& val) { flightType = val; };
FGScheduledFlight*findAvailableFlight (const std::string& currentDestination, const std::string &req, time_t min=0, time_t max=0);
// used to sort in descending order of score: I've probably found a better way to
// descending order sorting, but still need to test that.
bool operator< (const FGAISchedule &other) const;
void taint() { valid = false; };
int getLastUsed() { return lastRun; };
void setLastUsed(unsigned int val) {lastRun = val; };
int getLastUsed() { return lastRun; };
void setLastUsed(unsigned int val) {lastRun = val; };
//void * getAiRef () { return AIManagerRef; };
//FGAISchedule* getAddress () { return this;};

View file

@ -183,7 +183,7 @@ void FGTrafficManager::shutdown()
if (fgGetBool("/sim/traffic-manager/heuristics")) {
SGPath cacheData(globals->get_fg_home());
cacheData.append("ai");
string airport = fgGetString("/sim/presets/airport-id");
const string airport = fgGetString("/sim/presets/airport-id");
if ((airport) != "") {
char buffer[128];
@ -237,7 +237,7 @@ void FGTrafficManager::init()
assert(!doingInit);
doingInit = true;
if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) {
if (string(fgGetString("/sim/traffic-manager/datafile")).empty()) {
scheduleParser.reset(new ScheduleParseThread(this));
scheduleParser->setTrafficDir(SGPath(globals->get_fg_root(), "AI/Traffic"));
scheduleParser->start();
@ -328,7 +328,7 @@ void FGTrafficManager::loadHeuristics()
}
for(currAircraft = scheduledAircraft.begin(); currAircraft != scheduledAircraft.end(); ++currAircraft) {
string registration = (*currAircraft)->getRegistration();
const string& registration = (*currAircraft)->getRegistration();
HeuristicMapIterator itr = heurMap.find(registration);
if (itr != heurMap.end()) {
(*currAircraft)->setrunCount(itr->second.runCount);