Identify files in object cache by filename and optional provided options.

Objects with the same filename may be different from others based on the provided
plugin options. Using filename *and* the provided options as object cache key
helps to avoid fetching the wrong object.
This commit is contained in:
Ralf Habacker
2014-01-15 15:33:42 +01:00
committed by Robert Osfield
parent 3816e4c76e
commit 85cd1c456f
6 changed files with 68 additions and 36 deletions

View File

@@ -50,16 +50,16 @@ class OSGDB_EXPORT ObjectCache : public osg::Referenced
void addObjectCache(ObjectCache* object);
/** Add a filename,object,timestamp triple to the Registry::ObjectCache.*/
void addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp = 0.0);
void addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp = 0.0, const Options *options = NULL);
/** Remove Object from cache.*/
void removeFromObjectCache(const std::string& fileName);
void removeFromObjectCache(const std::string& fileName, const Options *options = NULL);
/** Get an Object from the object cache*/
osg::Object* getFromObjectCache(const std::string& fileName);
osg::Object* getFromObjectCache(const std::string& fileName, const Options *options = NULL);
/** Get an ref_ptr<Object> from the object cache*/
osg::ref_ptr<osg::Object> getRefFromObjectCache(const std::string& fileName);
osg::ref_ptr<osg::Object> getRefFromObjectCache(const std::string& fileName, const Options *options = NULL);
/** call rleaseGLObjects on all objects attached to the object cache.*/
void releaseGLObjects(osg::State* state);
@@ -69,7 +69,8 @@ class OSGDB_EXPORT ObjectCache : public osg::Referenced
virtual ~ObjectCache();
typedef std::pair<osg::ref_ptr<osg::Object>, double > ObjectTimeStampPair;
typedef std::map<std::string, ObjectTimeStampPair > ObjectCacheMap;
typedef std::pair<std::string, osg::ref_ptr<const osgDB::Options> > FileNameOptionsPair;
typedef std::map<FileNameOptionsPair, ObjectTimeStampPair > ObjectCacheMap;
ObjectCacheMap _objectCache;
OpenThreads::Mutex _objectCacheMutex;