From Alan Harris, "Registry and Archive
~~~~~~~~~~~~~~~~~~~~~~~~~ This is a simple change to permit databases other than those named "*.osga" to be used. It is hardcoded in read() at present. It is non-critical and does not affect existing program functionality. Registry and Registry.cpp ~~~~~~~~~~~~~~~~~~~~~~~~~ Added a new typedef: typedef std::vector< std::string> ArchiveExtensionList; a list of extensions: ArchiveExtensionList _archiveExtList; and an "add" method: addArchiveExtension(const std::string ext) This is initialised by adding "osga" in Registry() and used in Registry::read() where the list is searched for the extension used. Archive.cpp ~~~~~~~~~~~ This submission is a little more tentative. openArchive() is modified to automatically add the filename extension to the Registry extension list. "
This commit is contained in:
@@ -385,6 +385,8 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
/** Get the SharedStateManager. Return 0 if no SharedStateManager has been assigned.*/
|
||||
SharedStateManager* getSharedStateManager() { return _sharedStateManager.get(); }
|
||||
|
||||
/** Add an Archive extension.*/
|
||||
void addArchiveExtension(const std::string ext);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -394,6 +396,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
typedef std::map< std::string, osg::ref_ptr<DotOsgWrapper> > DotOsgWrapperMap;
|
||||
typedef std::vector< osg::ref_ptr<DynamicLibrary> > DynamicLibraryList;
|
||||
typedef std::map< std::string, std::string> ExtensionAliasMap;
|
||||
typedef std::vector< std::string> ArchiveExtensionList;
|
||||
|
||||
typedef std::pair<osg::ref_ptr<osg::Object>, double > ObjectTimeStampPair;
|
||||
typedef std::map<std::string, ObjectTimeStampPair > ObjectCache;
|
||||
@@ -489,7 +492,8 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
|
||||
ArchiveCache _archiveCache;
|
||||
OpenThreads::Mutex _archiveCacheMutex;
|
||||
|
||||
|
||||
ArchiveExtensionList _archiveExtList;
|
||||
|
||||
osg::ref_ptr<DatabasePager> _databasePager;
|
||||
osg::ref_ptr<SharedStateManager> _sharedStateManager;
|
||||
|
||||
@@ -29,6 +29,13 @@ osgDB::Archive* osgDB::openArchive(const std::string& filename, Archive::Archive
|
||||
|
||||
osgDB::Archive* osgDB::openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint,ReaderWriter::Options* options)
|
||||
{
|
||||
// ensure archive extension is in the registry list
|
||||
std::string::size_type dot = filename.find_last_of('.');
|
||||
if (dot != std::string::npos)
|
||||
{
|
||||
std::string ext = filename.substr(dot+1);
|
||||
Registry::instance()->addArchiveExtension(ext);
|
||||
}
|
||||
ReaderWriter::ReadResult result = osgDB::Registry::instance()->openArchive(filename, status, indexBlockSizeHint, options);
|
||||
return result.takeArchive();
|
||||
}
|
||||
|
||||
@@ -136,6 +136,9 @@ Registry::Registry()
|
||||
|
||||
_createNodeFromImage = false;
|
||||
_openingLibrary = false;
|
||||
|
||||
// add default osga archive extension
|
||||
_archiveExtList.push_back("osga");
|
||||
|
||||
initFilePathLists();
|
||||
|
||||
@@ -1291,30 +1294,47 @@ struct Registry::ReadArchiveFunctor : public Registry::ReadFunctor
|
||||
|
||||
};
|
||||
|
||||
void Registry::addArchiveExtension(const std::string ext)
|
||||
{
|
||||
for(ArchiveExtensionList::iterator aitr=_archiveExtList.begin();
|
||||
aitr!=_archiveExtList.end();
|
||||
++aitr)
|
||||
{
|
||||
if ( (*aitr) == ext) // extension already in archive extension list
|
||||
return;
|
||||
}
|
||||
_archiveExtList.push_back(ext);
|
||||
};
|
||||
|
||||
ReaderWriter::ReadResult Registry::read(const ReadFunctor& readFunctor)
|
||||
{
|
||||
std::string archiveName(".osga");
|
||||
|
||||
std::string::size_type positionArchive = readFunctor._filename.find(archiveName+'/');
|
||||
if (positionArchive==std::string::npos) positionArchive = readFunctor._filename.find(archiveName+'\\');
|
||||
if (positionArchive!=std::string::npos)
|
||||
for(ArchiveExtensionList::iterator aitr=_archiveExtList.begin();
|
||||
aitr!=_archiveExtList.end();
|
||||
++aitr)
|
||||
{
|
||||
std::string archiveName(readFunctor._filename.substr(0,positionArchive+5));
|
||||
std::string fileName(readFunctor._filename.substr(positionArchive+6,std::string::npos));
|
||||
osg::notify(osg::INFO)<<"Contains archive : "<<readFunctor._filename<<std::endl;
|
||||
osg::notify(osg::INFO)<<" archive : "<<archiveName<<std::endl;
|
||||
osg::notify(osg::INFO)<<" filename : "<<fileName<<std::endl;
|
||||
|
||||
ReaderWriter::ReadResult result = openArchiveImplementation(archiveName,ReaderWriter::READ, 4096, readFunctor._options);
|
||||
|
||||
if (!result.validArchive()) return result;
|
||||
std::string archiveName = "." + (*aitr);
|
||||
|
||||
osgDB::Archive* archive = result.getArchive();
|
||||
std::string::size_type positionArchive = readFunctor._filename.find(archiveName+'/');
|
||||
if (positionArchive==std::string::npos) positionArchive = readFunctor._filename.find(archiveName+'\\');
|
||||
if (positionArchive!=std::string::npos)
|
||||
{
|
||||
std::string archiveName(readFunctor._filename.substr(0,positionArchive+5));
|
||||
std::string fileName(readFunctor._filename.substr(positionArchive+6,std::string::npos));
|
||||
osg::notify(osg::INFO)<<"Contains archive : "<<readFunctor._filename<<std::endl;
|
||||
osg::notify(osg::INFO)<<" archive : "<<archiveName<<std::endl;
|
||||
osg::notify(osg::INFO)<<" filename : "<<fileName<<std::endl;
|
||||
|
||||
osg::ref_ptr<ReaderWriter::Options> options = new ReaderWriter::Options;
|
||||
options->setDatabasePath(archiveName);
|
||||
ReaderWriter::ReadResult result = openArchiveImplementation(archiveName,ReaderWriter::READ, 4096, readFunctor._options);
|
||||
|
||||
if (!result.validArchive()) return result;
|
||||
|
||||
return archive->readObject(fileName,options.get());
|
||||
osgDB::Archive* archive = result.getArchive();
|
||||
|
||||
osg::ref_ptr<ReaderWriter::Options> options = new ReaderWriter::Options;
|
||||
options->setDatabasePath(archiveName);
|
||||
|
||||
return archive->readObject(fileName,options.get());
|
||||
}
|
||||
}
|
||||
|
||||
// if filename contains archive
|
||||
|
||||
Reference in New Issue
Block a user