From: frohlich Date: Sat, 16 May 2009 18:05:21 +0000 (+0000) Subject: Implement current osgDB::ReaderWriters supportsExtension interface instead X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7cd149a4d8462a9ab46360760d27885ec7fd280e;p=simgear.git Implement current osgDB::ReaderWriters supportsExtension interface instead of the previous one. Modified Files: model/SGReaderWriterXML.cxx model/SGReaderWriterXML.hxx tgdb/ReaderWriterSTG.cxx tgdb/ReaderWriterSTG.hxx tgdb/SGReaderWriterBTG.cxx tgdb/SGReaderWriterBTG.hxx --- diff --git a/simgear/scene/model/SGReaderWriterXML.cxx b/simgear/scene/model/SGReaderWriterXML.cxx index 7a3660f6..0f4cdb95 100644 --- a/simgear/scene/model/SGReaderWriterXML.cxx +++ b/simgear/scene/model/SGReaderWriterXML.cxx @@ -54,14 +54,19 @@ sgLoad3DModel_internal(const string &path, osg::Node *(*load_panel)(SGPropertyNode *) = 0, SGPropertyNode *overlay = 0); -const char* SGReaderWriterXML::className() const + +SGReaderWriterXML::SGReaderWriterXML() +{ + supportsExtension("xml", "SimGear xml database format"); +} + +SGReaderWriterXML::~SGReaderWriterXML() { - return "XML database reader"; } -bool SGReaderWriterXML::acceptsExtension(const std::string& extension) const +const char* SGReaderWriterXML::className() const { - return (osgDB::equalCaseInsensitive(extension, "xml")); + return "XML database reader"; } osgDB::ReaderWriter::ReadResult @@ -70,10 +75,6 @@ SGReaderWriterXML::readNode(const std::string& fileName, { // SG_LOG(SG_GENERAL, SG_ALERT, "SGReaderWriterXML::readNode(" << fileName << ")"); - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if (!acceptsExtension(ext)) - return ReadResult::FILE_NOT_HANDLED; - const SGReaderWriterXMLOptions* xmlOptions = dynamic_cast(options); diff --git a/simgear/scene/model/SGReaderWriterXML.hxx b/simgear/scene/model/SGReaderWriterXML.hxx index 2d92c3ef..afa5925d 100644 --- a/simgear/scene/model/SGReaderWriterXML.hxx +++ b/simgear/scene/model/SGReaderWriterXML.hxx @@ -27,9 +27,10 @@ namespace simgear class SGReaderWriterXML : public osgDB::ReaderWriter { public: - virtual const char* className() const; + SGReaderWriterXML(); + virtual ~SGReaderWriterXML(); - virtual bool acceptsExtension(const std::string& extension) const; + virtual const char* className() const; virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) diff --git a/simgear/scene/tgdb/ReaderWriterSTG.cxx b/simgear/scene/tgdb/ReaderWriterSTG.cxx index 8e7fd2a2..57da979b 100644 --- a/simgear/scene/tgdb/ReaderWriterSTG.cxx +++ b/simgear/scene/tgdb/ReaderWriterSTG.cxx @@ -33,15 +33,18 @@ using namespace simgear; -const char* ReaderWriterSTG::className() const +ReaderWriterSTG::ReaderWriterSTG() +{ + supportsExtension("stg", "SimGear stg database format"); +} + +ReaderWriterSTG::~ReaderWriterSTG() { - return "STG Database reader"; } -bool ReaderWriterSTG::acceptsExtension(const std::string& extension) const +const char* ReaderWriterSTG::className() const { - return (osgDB::equalCaseInsensitive(extension, "gz") - || osgDB::equalCaseInsensitive(extension, "stg")); + return "STG Database reader"; } //#define SLOW_PAGER 1 @@ -53,22 +56,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTG::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if(!acceptsExtension(ext)) - return ReadResult::FILE_NOT_HANDLED; - std::string stgFileName; - if (osgDB::equalCaseInsensitive(ext, "gz")) { - stgFileName = osgDB::getNameLessExtension(fileName); - if (!acceptsExtension( - osgDB::getLowerCaseFileExtension(stgFileName))) { - return ReadResult::FILE_NOT_HANDLED; - } - } else { - stgFileName = fileName; - } - osg::Node* result - = TileEntry::loadTileByName(osgDB::getNameLessExtension(stgFileName), - options); + std::string tileName = osgDB::getNameLessExtension(fileName); + osg::Node* result = TileEntry::loadTileByName(tileName, options); // For debugging race conditions #ifdef SLOW_PAGER sleep(5); diff --git a/simgear/scene/tgdb/ReaderWriterSTG.hxx b/simgear/scene/tgdb/ReaderWriterSTG.hxx index 7f53f65a..7c571ccf 100644 --- a/simgear/scene/tgdb/ReaderWriterSTG.hxx +++ b/simgear/scene/tgdb/ReaderWriterSTG.hxx @@ -28,9 +28,10 @@ namespace simgear { class ReaderWriterSTG : public osgDB::ReaderWriter { public: - virtual const char* className() const; + ReaderWriterSTG(); + virtual ~ReaderWriterSTG(); - virtual bool acceptsExtension(const std::string& extension) const; + virtual const char* className() const; virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) diff --git a/simgear/scene/tgdb/SGReaderWriterBTG.cxx b/simgear/scene/tgdb/SGReaderWriterBTG.cxx index a93bfcec..1fa3e981 100644 --- a/simgear/scene/tgdb/SGReaderWriterBTG.cxx +++ b/simgear/scene/tgdb/SGReaderWriterBTG.cxx @@ -31,31 +31,24 @@ using namespace simgear; std::string SGReaderWriterBTGOptions::defaultOptions; -const char* SGReaderWriterBTG::className() const +SGReaderWriterBTG::SGReaderWriterBTG() { - return "BTG Database reader"; + supportsExtension("btg", "SimGear btg database format"); } -bool SGReaderWriterBTG::acceptsExtension(const std::string& extension) const +SGReaderWriterBTG::~SGReaderWriterBTG() { - return (osgDB::equalCaseInsensitive(extension, "gz") - || osgDB::equalCaseInsensitive(extension, "btg")); +} + +const char* SGReaderWriterBTG::className() const +{ + return "BTG Database reader"; } osgDB::ReaderWriter::ReadResult SGReaderWriterBTG::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if(!acceptsExtension(ext)) - return ReadResult::FILE_NOT_HANDLED; - if (osgDB::equalCaseInsensitive(ext, "gz")) { - std::string btgFileName = osgDB::getNameLessExtension(fileName); - if (!acceptsExtension( - osgDB::getLowerCaseFileExtension(btgFileName))) { - return ReadResult::FILE_NOT_HANDLED; - } - } SGMaterialLib* matlib = 0; bool calcLights = false; bool useRandomObjects = false; diff --git a/simgear/scene/tgdb/SGReaderWriterBTG.hxx b/simgear/scene/tgdb/SGReaderWriterBTG.hxx index 3c0ccc80..ca5f4a73 100644 --- a/simgear/scene/tgdb/SGReaderWriterBTG.hxx +++ b/simgear/scene/tgdb/SGReaderWriterBTG.hxx @@ -23,10 +23,11 @@ class SGReaderWriterBTG : public osgDB::ReaderWriter { public: + SGReaderWriterBTG(); + virtual ~SGReaderWriterBTG(); + virtual const char* className() const; - virtual bool acceptsExtension(const std::string& extension) const; - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const;