From 5b75d7f52581642664e04a85c6132fcf668ce576 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 10 Jul 2003 13:35:19 +0000 Subject: [PATCH] From Michael Gronger, addition of ReaderWriter* Registry::getReaderWriterForExtension(const std::string& ext). Also removed copy constructor and = operator from Ouput as it was produce spurious warnings under gcc 3.3. --- include/osgDB/Output | 3 --- include/osgDB/Registry | 5 ++++- src/osgDB/Output.cpp | 4 ---- src/osgDB/Registry.cpp | 47 +++++++++++++++++++++++++++++++++++------- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/include/osgDB/Output b/include/osgDB/Output index cbd8f9626..eef463d1b 100644 --- a/include/osgDB/Output +++ b/include/osgDB/Output @@ -81,9 +81,6 @@ class OSGDB_EXPORT Output : public std::ofstream protected: - // prevent copy construction and assignment. - Output(const Output&); - Output& operator = (const Output&); virtual void init(); diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 82f37c092..b28f0f2f9 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -71,7 +71,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced std::string createLibraryNameForFile(const std::string& fileName); /** create the platform specific library name associated with file extension.*/ - std::string createLibraryNameForExt(const std::string& ext); + std::string createLibraryNameForExtension(const std::string& ext); /** create the platform specific library name associated with nodekit library name.*/ std::string createLibraryNameForNodeKit(const std::string& name); @@ -81,6 +81,9 @@ class OSGDB_EXPORT Registry : public osg::Referenced /** close the attached library with specified name.*/ bool closeLibrary(const std::string& fileName); + /** get a reader writer which handles specified extension.*/ + ReaderWriter* getReaderWriterForExtension(const std::string& ext); + osg::Object* readObjectOfType(const osg::Object& compObj,Input& fr); osg::Object* readObject(Input& fr); diff --git a/src/osgDB/Output.cpp b/src/osgDB/Output.cpp index e491e94b1..b3e544ce1 100644 --- a/src/osgDB/Output.cpp +++ b/src/osgDB/Output.cpp @@ -32,10 +32,6 @@ Output::Output(const char* name) : ofstream(name) _filename = name; } -Output::Output(const Output&) : ofstream() {} - -Output& Output::operator = (const Output&) { return *this; } - Output::~Output() { } diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 24b14ca82..9a4a51311 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -289,7 +289,7 @@ void Registry::readCommandLine(osg::ArgumentParser& arguments) while(arguments.read("-e",value)) { - std::string libName = createLibraryNameForExt(value); + std::string libName = createLibraryNameForExtension(value); loadLibrary(libName); } @@ -424,15 +424,15 @@ void Registry::addFileExtensionAlias(const std::string mapExt, const std::string std::string Registry::createLibraryNameForFile(const std::string& fileName) { std::string ext = getLowerCaseFileExtension(fileName); - return createLibraryNameForExt(ext); + return createLibraryNameForExtension(ext); } -std::string Registry::createLibraryNameForExt(const std::string& ext) +std::string Registry::createLibraryNameForExtension(const std::string& ext) { ExtensionAliasMap::iterator itr=_extAliasMap.find(ext); - if (itr!=_extAliasMap.end()) return createLibraryNameForExt(itr->second); + if (itr!=_extAliasMap.end()) return createLibraryNameForExtension(itr->second); #if defined(WIN32) // !! recheck evolving Cygwin DLL extension naming protocols !! NHV @@ -532,6 +532,39 @@ DynamicLibrary* Registry::getLibrary(const std::string& fileName) else return NULL; } +ReaderWriter* Registry::getReaderWriterForExtension(const std::string& ext) +{ + // record the existing reader writer. + std::set rwOriginal; + + // first attemt one of the installed loaders + for(ReaderWriterList::iterator itr=_rwList.begin(); + itr!=_rwList.end(); + ++itr) + { + rwOriginal.insert(itr->get()); + if((*itr)->acceptsExtension(ext)) return (*itr).get(); + } + + // now look for a plug-in to load the file. + std::string libraryName = createLibraryNameForExtension(ext); + notify(INFO) << "Now checking for plug-in "<get())==rwOriginal.end()) + if((*itr)->acceptsExtension(ext)) return (*itr).get(); + } + } + + return NULL; + +} + + osg::Object* Registry::readObjectOfType(const osg::Object& compObj,Input& fr) { const char *str = fr[0].getStr(); @@ -572,7 +605,7 @@ osg::Object* Registry::readObjectOfType(const osg::Object& compObj,Input& fr) if (loadLibrary(nodeKitLibraryName)) return readObjectOfType(compObj,fr); // otherwise try the osgdb_ plugin library. - std::string pluginLibraryName = createLibraryNameForExt(libraryName); + std::string pluginLibraryName = createLibraryNameForExtension(libraryName); if (loadLibrary(pluginLibraryName)) return readObjectOfType(compObj,fr); } } @@ -667,7 +700,7 @@ osg::Object* Registry::readObject(DotOsgWrapperMap& dowMap,Input& fr) if (loadLibrary(nodeKitLibraryName)) return readObject(dowMap,fr); // otherwise try the osgdb_ plugin library. - std::string pluginLibraryName = createLibraryNameForExt(libraryName); + std::string pluginLibraryName = createLibraryNameForExtension(libraryName); if (loadLibrary(pluginLibraryName)) return readObject(dowMap,fr); } } @@ -873,7 +906,7 @@ bool Registry::writeObject(const osg::Object& obj,Output& fw) if (loadLibrary(nodeKitLibraryName)) return writeObject(obj,fw); // otherwise try the osgdb_ plugin library. - std::string pluginLibraryName = createLibraryNameForExt(obj.libraryName()); + std::string pluginLibraryName = createLibraryNameForExtension(obj.libraryName()); if (loadLibrary(pluginLibraryName)) return writeObject(obj,fw); } else