From Paul Martz, "Here's my changes to Registry to allow extension alias mapping via a config file. I also attached a sample file that tests the parsing, but this is just FYI and not for inclusion in CVS.
To set up extension aliases using a config file, an app calls: osgDB::Registry::instance()->readPluginAliasConfigurationFile(), passing in the file name as the parameter. (Of course this should be done before loading any files whose names depend on the mapping.) osgDB will search for the file using OSG_FILE_PATH. The file should contain a line for each mapping, with the "map" extension first, followed by a space or tab, then the plugin identifier. For example, a file containing this line: flt OpenFlight would map the ".flt" extension to the OpenFlight plugin."
This commit is contained in:
parent
69da91620f
commit
4914d3974a
@ -81,6 +81,11 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
|||||||
* by the libdb_tiff readerwriter plugin.*/
|
* by the libdb_tiff readerwriter plugin.*/
|
||||||
void addFileExtensionAlias(const std::string mapExt, const std::string toExt);
|
void addFileExtensionAlias(const std::string mapExt, const std::string toExt);
|
||||||
|
|
||||||
|
/** Reads a file that configures extension mappings. File is ASCII text
|
||||||
|
* and each line contains the parameyters to the addFileExtensionAlias
|
||||||
|
* method. Lines can be commented out with an initial '#' character.*/
|
||||||
|
bool readPluginAliasConfigurationFile( const std::string& file );
|
||||||
|
|
||||||
void addDotOsgWrapper(DotOsgWrapper* wrapper);
|
void addDotOsgWrapper(DotOsgWrapper* wrapper);
|
||||||
void removeDotOsgWrapper(DotOsgWrapper* wrapper);
|
void removeDotOsgWrapper(DotOsgWrapper* wrapper);
|
||||||
|
|
||||||
@ -470,6 +475,9 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
|||||||
// map to alias to extensions to plugins.
|
// map to alias to extensions to plugins.
|
||||||
ExtensionAliasMap _extAliasMap;
|
ExtensionAliasMap _extAliasMap;
|
||||||
|
|
||||||
|
// Utility: Removes whitespace from both ends of a string.
|
||||||
|
static std::string trim( const std::string& str );
|
||||||
|
|
||||||
// options to pass to reader writers.
|
// options to pass to reader writers.
|
||||||
osg::ref_ptr<ReaderWriter::Options> _options;
|
osg::ref_ptr<ReaderWriter::Options> _options;
|
||||||
|
|
||||||
|
@ -474,6 +474,58 @@ void Registry::addFileExtensionAlias(const std::string mapExt, const std::string
|
|||||||
_extAliasMap[mapExt] = toExt;
|
_extAliasMap[mapExt] = toExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Registry::readPluginAliasConfigurationFile( const std::string& file )
|
||||||
|
{
|
||||||
|
std::string fileName = osgDB::findDataFile( file );
|
||||||
|
if (fileName.empty())
|
||||||
|
{
|
||||||
|
osg::notify( osg::WARN) << "Can't find plugin alias config file \"" << file << "\"." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream ifs;
|
||||||
|
ifs.open( fileName.c_str() );
|
||||||
|
if (!ifs.good())
|
||||||
|
{
|
||||||
|
osg::notify( osg::WARN) << "Can't open plugin alias config file \"" << fileName << "\"." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineNum( 0 );
|
||||||
|
while (ifs.good())
|
||||||
|
{
|
||||||
|
std::string raw;
|
||||||
|
++lineNum;
|
||||||
|
std::getline( ifs, raw );
|
||||||
|
std::string ln = trim( raw );
|
||||||
|
if (ln.empty()) continue;
|
||||||
|
if (ln[0] == '#') continue;
|
||||||
|
|
||||||
|
std::string::size_type spIdx = ln.find_first_of( " \t" );
|
||||||
|
if (spIdx == ln.npos)
|
||||||
|
{
|
||||||
|
// mapExt and toExt must be on the same line, separated by a space.
|
||||||
|
osg::notify( osg::WARN) << file << ", line " << lineNum << ": Syntax error: missing space in \"" << raw << "\"." << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string mapExt = trim( ln.substr( 0, spIdx ) );
|
||||||
|
const std::string toExt = trim( ln.substr( spIdx+1 ) );
|
||||||
|
addFileExtensionAlias( mapExt, toExt );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Registry::trim( const std::string& str )
|
||||||
|
{
|
||||||
|
if (!str.size()) return str;
|
||||||
|
std::string::size_type first = str.find_first_not_of( " \t" );
|
||||||
|
std::string::size_type last = str.find_last_not_of( " \t\r\n" );
|
||||||
|
if ((first==str.npos) || (last==str.npos)) return std::string( "" );
|
||||||
|
return str.substr( first, last-first+1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Registry::createLibraryNameForFile(const std::string& fileName)
|
std::string Registry::createLibraryNameForFile(const std::string& fileName)
|
||||||
{
|
{
|
||||||
std::string ext = getLowerCaseFileExtension(fileName);
|
std::string ext = getLowerCaseFileExtension(fileName);
|
||||||
|
Loading…
Reference in New Issue
Block a user