From b4b88e9549a9c6965ed69e0b196f177eda58ad46 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 6 May 2011 16:46:13 +0000 Subject: [PATCH] Added osg::ref_ptr osgDB::Registry::getRefFromArchiveCache() and osg::ref_ptr osgDB::Registry::getRefFromObjectCache(). --- include/osgDB/Registry | 12 +++++++++--- src/osgDB/Registry.cpp | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 958791a7d..4ccdcb3a2 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -438,17 +438,23 @@ class OSGDB_EXPORT Registry : public osg::Referenced /** Add a filename,object,timestamp triple to the Registry::ObjectCache.*/ void addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp = 0.0); - /** Get an object from the object cache*/ + /** Get an Object from the object cache*/ osg::Object* getFromObjectCache(const std::string& fileName); + /** Get an ref_ptr from the object cache*/ + osg::ref_ptr getRefFromObjectCache(const std::string& fileName); + /** Add archive to archive cache so that future calls reference this archive.*/ void addToArchiveCache(const std::string& fileName, osgDB::Archive* archive); - /** Remove archive from cache.*/ + /** Remove Archive from cache.*/ void removeFromArchiveCache(const std::string& fileName); - /** Get an archive from the archive cache*/ + /** Get an Archive from the archive cache.*/ osgDB::Archive* getFromArchiveCache(const std::string& fileName); + + /** Get an ref_ptr from the archive cache.*/ + osg::ref_ptr getRefFromArchiveCache(const std::string& fileName); /** Remove all archives from the archive cache.*/ void clearArchiveCache(); diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 1bae8c593..9f2a6c1cd 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -1228,8 +1228,8 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* options) { - osgDB::Archive* archive = getFromArchiveCache(fileName); - if (archive) return archive; + osg::ref_ptr archive = getRefFromArchiveCache(fileName); + if (archive.valid()) return archive.get(); ReaderWriter::ReadResult result = readImplementation(ReadArchiveFunctor(fileName, status, indexBlockSizeHint, options),Options::CACHE_ARCHIVES); @@ -1526,6 +1526,7 @@ void Registry::addEntryToObjectCache(const std::string& filename, osg::Object* o OpenThreads::ScopedLock lock(_objectCacheMutex); _objectCache[filename]=ObjectTimeStampPair(object,timestamp); } + osg::Object* Registry::getFromObjectCache(const std::string& fileName) { OpenThreads::ScopedLock lock(_objectCacheMutex); @@ -1534,6 +1535,14 @@ osg::Object* Registry::getFromObjectCache(const std::string& fileName) else return 0; } +osg::ref_ptr Registry::getRefFromObjectCache(const std::string& fileName) +{ + OpenThreads::ScopedLock lock(_objectCacheMutex); + ObjectCache::iterator itr = _objectCache.find(fileName); + if (itr!=_objectCache.end()) return itr->second.first; + else return 0; +} + void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(const osg::FrameStamp& frameStamp) { OpenThreads::ScopedLock lock(_objectCacheMutex); @@ -1616,6 +1625,14 @@ osgDB::Archive* Registry::getFromArchiveCache(const std::string& fileName) else return 0; } +osg::ref_ptr Registry::getRefFromArchiveCache(const std::string& fileName) +{ + OpenThreads::ScopedLock lock(_archiveCacheMutex); + ArchiveCache::iterator itr = _archiveCache.find(fileName); + if (itr!=_archiveCache.end()) return itr->second; + else return 0; +} + void Registry::clearArchiveCache() { OpenThreads::ScopedLock lock(_archiveCacheMutex);