Added --plugins and --formats query support into osgconv to help with querying the

available plugins and the file formats/protocols they support
This commit is contained in:
Robert Osfield 2008-07-14 20:22:38 +00:00
parent 5ab4af80c5
commit f22c06acbe
3 changed files with 96 additions and 3 deletions

View File

@ -39,3 +39,33 @@ FileNameList osgDB::listAllAvailablePlugins()
return pluginFiles;
}
bool osgDB::queryPlugin(const std::string& fileName, ReaderWriterInfoList& infoList)
{
if (osgDB::Registry::instance()->loadLibrary(fileName))
{
const Registry::ReaderWriterList& rwList = osgDB::Registry::instance()->getReaderWriterList();
for(Registry::ReaderWriterList::const_iterator itr = rwList.begin();
itr != rwList.end();
++itr)
{
const ReaderWriter* rw = itr->get();
osg::ref_ptr<ReaderWriterInfo> rwi = new ReaderWriterInfo;
rwi->plugin = fileName;
rwi->description = rw->className();
rwi->protocols = rw->supportedProtocols();
rwi->extensions = rw->supportedExtensions();
rwi->options = rw->supportedOptions();
infoList.push_back(rwi.get());
}
osgDB::Registry::instance()->closeLibrary(fileName);
return true;
}
else
{
return false;
}
}

View File

@ -22,6 +22,20 @@ typedef std::list<std::string> FileNameList;
FileNameList listAllAvailablePlugins();
class ReaderWriterInfo : public osg::Referenced
{
public:
std::string plugin;
std::string description;
ReaderWriter::FormatDescriptionMap protocols;
ReaderWriter::FormatDescriptionMap extensions;
ReaderWriter::FormatDescriptionMap options;
};
typedef std::list< osg::ref_ptr<ReaderWriterInfo> > ReaderWriterInfoList;
bool queryPlugin(const std::string& fileName, ReaderWriterInfoList& infoList);
}

View File

@ -507,7 +507,8 @@ int main( int argc, char **argv )
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters");
arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
arguments.getApplicationUsage()->addCommandLineOption("--fmts","List supported file formats");
arguments.getApplicationUsage()->addCommandLineOption("--formats","List supported file formats");
arguments.getApplicationUsage()->addCommandLineOption("--plugins","List database olugins");
// if user request help write it out to cout.
@ -524,7 +525,7 @@ int main( int argc, char **argv )
return 1;
}
if (arguments.read("--fmts"))
if (arguments.read("--plugins"))
{
osgDB::FileNameList plugins = osgDB::listAllAvailablePlugins();
for(osgDB::FileNameList::iterator itr = plugins.begin();
@ -533,7 +534,55 @@ int main( int argc, char **argv )
{
std::cout<<"Plugin "<<*itr<<std::endl;
}
return 1;
return 0;
}
if (arguments.read("--formats"))
{
osgDB::FileNameList plugins = osgDB::listAllAvailablePlugins();
for(osgDB::FileNameList::iterator itr = plugins.begin();
itr != plugins.end();
++itr)
{
std::cout<<"Plugin "<<*itr<<std::endl;
std::cout<<"{"<<std::endl;
osgDB::ReaderWriterInfoList infoList;
if (osgDB::queryPlugin(*itr, infoList))
{
for(osgDB::ReaderWriterInfoList::iterator rwi_itr = infoList.begin();
rwi_itr != infoList.end();
++rwi_itr)
{
osgDB::ReaderWriterInfo& info = *(*rwi_itr);
std::cout<<" ReaderWriter : "<<info.description<<std::endl;
std::cout<<" {"<<std::endl;
for(osgDB::ReaderWriter::FormatDescriptionMap::iterator fdm_itr = info.protocols.begin();
fdm_itr != info.protocols.end();
++fdm_itr)
{
std::cout<<" protocol : "<<fdm_itr->first<<"\t"<<fdm_itr->second<<std::endl;
}
for(osgDB::ReaderWriter::FormatDescriptionMap::iterator fdm_itr = info.extensions.begin();
fdm_itr != info.extensions.end();
++fdm_itr)
{
std::cout<<" extensions : ."<<fdm_itr->first<<"\t"<<fdm_itr->second<<std::endl;
}
for(osgDB::ReaderWriter::FormatDescriptionMap::iterator fdm_itr = info.options.begin();
fdm_itr != info.options.end();
++fdm_itr)
{
std::cout<<" options : "<<fdm_itr->first<<"\t"<<fdm_itr->second<<std::endl;
}
std::cout<<" }"<<std::endl;
}
}
std::cout<<"}"<<std::endl<<std::endl;
}
return 0;
}
if (arguments.argc()<=1)