1
0
Fork 0

XMLLoader re-factoring.

This commit is contained in:
jmt 2009-08-29 10:21:51 +00:00 committed by Tim Moore
parent 1c015387ba
commit cc0c19f62e
2 changed files with 38 additions and 107 deletions

View file

@ -32,120 +32,51 @@ using std::string;
XMLLoader::XMLLoader() {} XMLLoader::XMLLoader() {}
XMLLoader::~XMLLoader() {} XMLLoader::~XMLLoader() {}
string XMLLoader::expandICAODirs(const string& in){
//cerr << "Expanding " << in << endl;
if (in.size() == 4) {
char buffer[11];
snprintf(buffer, 11, "%c/%c/%c", in[0], in[1], in[2]);
//cerr << "result: " << buffer << endl;
return string(buffer);
} else {
return in;
}
//exit(1);
}
void XMLLoader::load(FGAirportDynamics* d) { void XMLLoader::load(FGAirportDynamics* d) {
FGAirportDynamicsXMLLoader visitor(d); FGAirportDynamicsXMLLoader visitor(d);
if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) { if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
SGPath parkpath( globals->get_fg_root() ); SGPath parkpath( globals->get_fg_root() );
parkpath.append( "/AI/Airports/" ); parkpath.append( "/AI/Airports/" );
parkpath.append( d->getId() ); parkpath.append( d->getId() );
parkpath.append( "parking.xml" ); parkpath.append( "parking.xml" );
SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str()); SG_LOG(SG_GENERAL, SG_DEBUG, "running old loader:" << parkpath.c_str());
if (parkpath.exists()) { if (parkpath.exists()) {
try { try {
readXML(parkpath.str(), visitor); readXML(parkpath.str(), visitor);
d->init(); d->init();
} }
catch (const sg_exception &) { catch (const sg_exception &) {
}
} }
} else { }
string_list sc = globals->get_fg_scenery(); } else {
char buffer[32]; loadAirportXMLDataIntoVisitor(d->getId(), "groundnet", visitor);
snprintf(buffer, 32, "%s.groundnet.xml", d->getId().c_str() ); }
string airportDir = XMLLoader::expandICAODirs(d->getId());
for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
SGPath parkpath( *i );
parkpath.append( "Airports" );
parkpath.append ( airportDir );
parkpath.append( string (buffer) );
SG_LOG(SG_GENERAL, SG_DEBUG, "Trying to read ground net:" << parkpath.c_str());
if (parkpath.exists()) {
SG_LOG(SG_GENERAL, SG_DEBUG, "reading ground net:" << parkpath.c_str());
try {
readXML(parkpath.str(), visitor);
d->init();
}
catch (const sg_exception &) {
}
return;
}
}
}
} }
void XMLLoader::load(FGRunwayPreference* p) { void XMLLoader::load(FGRunwayPreference* p) {
FGRunwayPreferenceXMLLoader visitor(p); FGRunwayPreferenceXMLLoader visitor(p);
if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) { if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == false) {
SGPath rwyPrefPath( globals->get_fg_root() ); SGPath rwyPrefPath( globals->get_fg_root() );
rwyPrefPath.append( "AI/Airports/" ); rwyPrefPath.append( "AI/Airports/" );
rwyPrefPath.append( p->getId() ); rwyPrefPath.append( p->getId() );
rwyPrefPath.append( "rwyuse.xml" ); rwyPrefPath.append( "rwyuse.xml" );
if (rwyPrefPath.exists()) { if (rwyPrefPath.exists()) {
try { try {
readXML(rwyPrefPath.str(), visitor); readXML(rwyPrefPath.str(), visitor);
} }
catch (const sg_exception &) { catch (const sg_exception &) {
}
}
} else {
string_list sc = globals->get_fg_scenery();
char buffer[32];
snprintf(buffer, 32, "%s.rwyuse.xml", p->getId().c_str() );
string airportDir = expandICAODirs(p->getId());
for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
SGPath rwypath( *i );
rwypath.append( "Airports" );
rwypath.append ( airportDir );
rwypath.append( string(buffer) );
if (rwypath.exists()) {
try {
readXML(rwypath.str(), visitor);
}
catch (const sg_exception &) {
}
return;
}
} }
} }
} else {
loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor);
}
} }
void XMLLoader::load(FGSidStar* p) { void XMLLoader::load(FGSidStar* p) {
//FGRunwayPreferenceXMLLoader visitor(p); SGPath path;
if (fgGetBool("/sim/traffic-manager/use-custom-scenery-data") == true) { if (findAirportData(p->getId(), "SID", path)) {
string_list sc = globals->get_fg_scenery(); p->load(path);
char buffer[32]; }
snprintf(buffer, 32, "%s.SID.xml", p->getId().c_str() );
string airportDir = expandICAODirs(p->getId());
for (string_list_iterator i = sc.begin(); i != sc.end(); i++) {
SGPath sidpath( *i );
sidpath.append( "Airports" );
sidpath.append ( airportDir );
sidpath.append( string(buffer) );
if (sidpath.exists()) {
try {
//readXML(rwypath.str(), visitor);
//cerr << "Reading SID procedure : " << sidpath.str() << endl;
p->load(sidpath);
}
catch (const sg_exception &) {
}
return;
}
}
}
} }
bool XMLLoader::findAirportData(const std::string& aICAO, bool XMLLoader::findAirportData(const std::string& aICAO,
@ -167,7 +98,6 @@ bool XMLLoader::findAirportData(const std::string& aICAO,
} // of path exists } // of path exists
} // of scenery path iteration } // of scenery path iteration
return false; return false;
} }
@ -176,9 +106,11 @@ bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
{ {
SGPath path; SGPath path;
if (!findAirportData(aICAO, aFileName, path)) { if (!findAirportData(aICAO, aFileName, path)) {
SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
return false; return false;
} }
SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str());
readXML(path.str(), aVisitor); readXML(path.str(), aVisitor);
return true; return true;
} }

View file

@ -26,7 +26,6 @@ class XMLLoader {
public: public:
XMLLoader(); XMLLoader();
~XMLLoader(); ~XMLLoader();
static string expandICAODirs(const std::string& in);
static void load(FGRunwayPreference* p); static void load(FGRunwayPreference* p);
static void load(FGAirportDynamics* d); static void load(FGAirportDynamics* d);