Skip to content

Commit

Permalink
Added --format extname and --plugin pluginname extensions, and improv…
Browse files Browse the repository at this point in the history
…ed formating
  • Loading branch information
robertosfield committed Jul 24, 2008
1 parent ea309e2 commit efd20ea
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 38 deletions.
76 changes: 76 additions & 0 deletions applications/osgconv/PluginQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,79 @@ bool osgDB::queryPlugin(const std::string& fileName, ReaderWriterInfoList& infoL
return false;
}
}

static std::string padwithspaces(const std::string& str, unsigned int padLength)
{
std::string newStr(str);
while(newStr.length()<padLength) newStr.push_back(' ');
return newStr;
}

bool osgDB::outputPluginDetails(std::ostream& out, const std::string& fileName)
{


out<<"Plugin "<<fileName<<std::endl;
out<<"{"<<std::endl;
osgDB::ReaderWriterInfoList infoList;
if (osgDB::queryPlugin(fileName, infoList))
{
for(osgDB::ReaderWriterInfoList::iterator rwi_itr = infoList.begin();
rwi_itr != infoList.end();
++rwi_itr)
{
osgDB::ReaderWriterInfo& info = *(*rwi_itr);
out<<" ReaderWriter : "<<info.description<<std::endl;
out<<" {"<<std::endl;

unsigned int longestOptionLength = 0;
osgDB::ReaderWriter::FormatDescriptionMap::iterator fdm_itr;
for(fdm_itr = info.protocols.begin();
fdm_itr != info.protocols.end();
++fdm_itr)
{
if (fdm_itr->first.length()>longestOptionLength) longestOptionLength = fdm_itr->first.length();
}

for(fdm_itr = info.extensions.begin();
fdm_itr != info.extensions.end();
++fdm_itr)
{
if (fdm_itr->first.length()>longestOptionLength) longestOptionLength = fdm_itr->first.length();
}

for(fdm_itr = info.options.begin();
fdm_itr != info.options.end();
++fdm_itr)
{
if (fdm_itr->first.length()>longestOptionLength) longestOptionLength = fdm_itr->first.length();
}

unsigned int padLength = longestOptionLength+4;

for(fdm_itr = info.protocols.begin();
fdm_itr != info.protocols.end();
++fdm_itr)
{
out<<" protocol : "<<padwithspaces(fdm_itr->first, padLength)<<fdm_itr->second<<std::endl;
}

for(fdm_itr = info.extensions.begin();
fdm_itr != info.extensions.end();
++fdm_itr)
{
out<<" extensions : ."<<padwithspaces(fdm_itr->first, padLength-1)<<fdm_itr->second<<std::endl;
}

for(fdm_itr = info.options.begin();
fdm_itr != info.options.end();
++fdm_itr)
{
out<<" options : "<<padwithspaces(fdm_itr->first, padLength)<<fdm_itr->second<<std::endl;
}
out<<" }"<<std::endl;
}
}
out<<"}"<<std::endl<<std::endl;
}

2 changes: 2 additions & 0 deletions applications/osgconv/PluginQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef std::list< osg::ref_ptr<ReaderWriterInfo> > ReaderWriterInfoList;

bool queryPlugin(const std::string& fileName, ReaderWriterInfoList& infoList);

bool outputPluginDetails(std::ostream& out, const std::string& fileName);

}

#endif
54 changes: 16 additions & 38 deletions applications/osgconv/osgconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,50 +537,29 @@ int main( int argc, char **argv )
return 0;
}

std::string plugin;
if (arguments.read("--plugin", plugin))
{
osgDB::outputPluginDetails(std::cout, plugin);
return 0;
}

std::string ext;
if (arguments.read("--format", ext))
{
plugin = osgDB::Registry::instance()->createLibraryNameForExtension(ext);
osgDB::outputPluginDetails(std::cout, plugin);
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;
osgDB::outputPluginDetails(std::cout,*itr);
}
return 0;
}
Expand All @@ -603,7 +582,6 @@ int main( int argc, char **argv )
osgDB::Registry::instance()->setOptions(options);
}

std::string ext;
while (arguments.read("-e",ext))
{
std::string libName = osgDB::Registry::instance()->createLibraryNameForExtension(ext);
Expand Down

0 comments on commit efd20ea

Please sign in to comment.