Moved Registry::CacheHintOptions into ReaderWriter::Options

This commit is contained in:
Robert Osfield
2004-11-22 14:10:12 +00:00
parent 1ac452df69
commit a6369da4f4
20 changed files with 205 additions and 152 deletions

View File

@@ -70,7 +70,7 @@ class OSGDB_EXPORT Archive : public ReaderWriter
OSGDB_EXPORT Archive* openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint=4096);
/** Open an archive for reading or writing.*/
OSGDB_EXPORT Archive* openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint,Registry::CacheHintOptions useObjectCache);
OSGDB_EXPORT Archive* openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint,ReaderWriter::Options* options);
}
#endif // OSGDB_ARCHIVE

View File

@@ -74,11 +74,20 @@ inline void setDataFilePathList(const std::string& paths) { osgDB::Registry::ins
inline FilePathList& getDataFilePathList() { return osgDB::Registry::instance()->getDataFilePathList(); }
/** Search for specified file in file system, checking the DataFilePathList for possible paths,
* returning the full path of the first valid file found, return an empty string if no string is found.
*/
extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE);
/** Search for specified file in file system, checking first the database path set in the Options structure, then the DataFilePathList for possible paths,
* returning the full path of the first valid file found, return an empty string if no string is found.
*/
extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,ReaderWriter::Options* options, CaseSensitivity caseSensitivity=CASE_SENSITIVE);
/** Convinience class for pushing a path on construction, and popping the path
* and destruction. This helps keep the addition of a path local to a block
* of code, even in the presence of exceptions.*/
class PushAndPopDataPath
{
public:

View File

@@ -29,11 +29,11 @@ namespace osgDB {
/** Read an osg::Object from file.
* Return valid osg::Object on success,
* return NULL on failure.
* Use the useObjectCache flag to override the osgDB::Regisytr::getUseObjectCacheHint().
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::Object* readObjectFile(const std::string& filename,Registry::CacheHintOptions useObjectCache);
extern OSGDB_EXPORT osg::Object* readObjectFile(const std::string& filename,const ReaderWriter::Options* options);
/** Read an osg::Object from file.
* Return valid osg::Object on success,
@@ -43,18 +43,18 @@ extern OSGDB_EXPORT osg::Object* readObjectFile(const std::string& filename,Regi
* to read the specified file.*/
inline osg::Object* readObjectFile(const std::string& filename)
{
return readObjectFile(filename,Registry::instance()->getUseObjectCacheHint());
return readObjectFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Image from file.
* Return valid osg::Image on success,
* return NULL on failure.
* Use the useObjectCache flag to override the osgDB::Regisytr::getUseObjectCacheHint().
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::Image* readImageFile(const std::string& filename,Registry::CacheHintOptions useObjectCache);
extern OSGDB_EXPORT osg::Image* readImageFile(const std::string& filename,const ReaderWriter::Options* options);
/** Read an osg::Image from file.
* Return valid osg::Image on success,
@@ -64,17 +64,17 @@ extern OSGDB_EXPORT osg::Image* readImageFile(const std::string& filename,Regis
* to read the specified file.*/
inline osg::Image* readImageFile(const std::string& filename)
{
return readImageFile(filename,Registry::instance()->getUseObjectCacheHint());
return readImageFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::HeightField from file.
* Return valid osg::HeightField on success,
* return NULL on failure.
* Use the useObjectCache flag to override the osgDB::Regisytr::getUseObjectCacheHint().
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::HeightField* readHeightFieldFile(const std::string& filename,Registry::CacheHintOptions useObjectCache);
extern OSGDB_EXPORT osg::HeightField* readHeightFieldFile(const std::string& filename,const ReaderWriter::Options* options);
/** Read an osg::HeightField from file.
* Return valid osg::HeightField on success,
@@ -84,17 +84,17 @@ extern OSGDB_EXPORT osg::HeightField* readHeightFieldFile(const std::string& fi
* to read the specified file.*/
inline osg::HeightField* readHeightFieldFile(const std::string& filename)
{
return readHeightFieldFile(filename,Registry::instance()->getUseObjectCacheHint());
return readHeightFieldFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Node from file.
* Return valid osg::Node on success,
* return NULL on failure.
* Use the useObjectCache flag to override the osgDB::Regisytr::getUseObjectCacheHint().
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::Node* readNodeFile(const std::string& filename,Registry::CacheHintOptions useObjectCache);
extern OSGDB_EXPORT osg::Node* readNodeFile(const std::string& filename,const ReaderWriter::Options* options);
/** Read an osg::Node from file.
* Return valid osg::Node on success,
@@ -104,33 +104,33 @@ extern OSGDB_EXPORT osg::Node* readNodeFile(const std::string& filename,Registr
* to read the specified file.*/
inline osg::Node* readNodeFile(const std::string& filename)
{
return readNodeFile(filename,Registry::instance()->getUseObjectCacheHint());
return readNodeFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.
* Use the useObjectCache flag to override the osgDB::Regisytr::getUseObjectCacheHint().*/
extern OSGDB_EXPORT osg::Node* readNodeFiles(std::vector<std::string>& commandLine,Registry::CacheHintOptions useObjectCache);
* Use the Options object to control cache operations and file search paths in osgDB::Registry.*/
extern OSGDB_EXPORT osg::Node* readNodeFiles(std::vector<std::string>& commandLine,const ReaderWriter::Options* options);
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.*/
inline osg::Node* readNodeFiles(std::vector<std::string>& commandLine)
{
return readNodeFiles(commandLine,Registry::instance()->getUseObjectCacheHint());
return readNodeFiles(commandLine,Registry::instance()->getOptions());
}
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.
* Use the useObjectCache flag to override the osgDB::Regisytr::getUseObjectCacheHint().*/
extern OSGDB_EXPORT osg::Node* readNodeFiles(osg::ArgumentParser& parser,Registry::CacheHintOptions useObjectCache);
* Use the Options object to control cache operations and file search paths in osgDB::Registry.*/
extern OSGDB_EXPORT osg::Node* readNodeFiles(osg::ArgumentParser& parser,const ReaderWriter::Options* options);
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.*/
inline osg::Node* readNodeFiles(osg::ArgumentParser& parser)
{
return readNodeFiles(parser,Registry::instance()->getUseObjectCacheHint());
return readNodeFiles(parser,Registry::instance()->getOptions());
}
}

View File

@@ -24,10 +24,15 @@
#include <osgDB/Export>
#include <osgDB/ReentrantMutex>
#include <deque>
namespace osgDB {
class Archive;
/** list of directories to search through which searching for files. */
typedef std::deque<std::string> FilePathList;
/** pure virtual base class for reading and writing of non native formats. */
class OSGDB_EXPORT ReaderWriter : public osg::Object
{
@@ -47,14 +52,45 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
class Options : public osg::Object
{
public:
/// bit mask for setting up which object types get cached by readObject/Image/HeightField/Node(filename) calls
enum CacheHintOptions
{ /// do not cache objects of any type
CACHE_NONE = 0,
Options() {}
/// cache nodes loaded via readNode(filename)
CACHE_NODES = 1,
/// cache images loaded via readImage(filename)
CACHE_IMAGES = 2,
/// cache heightfield loaded via readHeightField(filename)
CACHE_HEIGHTFIELDS = 4,
/// cache heightfield loaded via readHeightField(filename)
CACHE_ARCHIVES = 8,
/// cache objects loaded via readObject(filename)
CACHE_OBJECTS = 16,
/// cache on all read*(filename) calls
CACHE_ALL = CACHE_NODES |
CACHE_IMAGES |
CACHE_HEIGHTFIELDS |
CACHE_ARCHIVES |
CACHE_OBJECTS
};
Options():_useObjectCacheHint(CACHE_NONE) {}
Options(const std::string& str):_str(str) {}
Options(const Options& options,const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):
Object(options,copyop),
_str(options._str),
_databasePath(options._databasePath) {}
_databasePaths(options._databasePaths),
_useObjectCacheHint(options._useObjectCacheHint) {}
META_Object(osgDB,Options);
@@ -65,17 +101,28 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
const std::string& getOptionString() const { return _str; }
/** Set the database path to use a hint of where to look when loading models.*/
void setDatabasePath(const std::string& str) { _databasePath = str; }
void setDatabasePath(const std::string& str) { _databasePaths.clear(); _databasePaths.push_back(str); }
/** Get the database path which is used a hint of where to look when loading models.*/
const std::string& getDatabasePath() const { return _databasePath; }
FilePathList& getDatabasePathList() { return _databasePaths; }
/** Get the const database path which is used a hint of where to look when loading models.*/
const FilePathList& getDatabasePathList() const { return _databasePaths; }
/** Set whether the Registry::ObjectCache should be used by default.*/
void setUseObjectCacheHint(CacheHintOptions useObjectCache) { _useObjectCacheHint = useObjectCache; }
/** Get whether the Registry::ObjectCache should be used by default.*/
CacheHintOptions getUseObjectCacheHint() const { return _useObjectCacheHint; }
protected:
virtual ~Options() {}
std::string _str;
std::string _databasePath;
std::string _str;
FilePathList _databasePaths;
CacheHintOptions _useObjectCacheHint;
};

View File

@@ -25,7 +25,6 @@
#include <vector>
#include <map>
#include <string>
#include <deque>
namespace osgDB {
@@ -49,8 +48,6 @@ struct type_wrapper: basic_type_wrapper {
}
};
/** list of directories to search through which searching for files. */
typedef std::deque<std::string> FilePathList;
/**
Registry is a singleton factory which stores
@@ -68,33 +65,6 @@ class OSGDB_EXPORT Registry : public osg::Referenced
{
public:
/// bit mask for setting up which object types get cached by readObject/Image/HeightField/Node(filename) calls
enum CacheHintOptions
{ /// do not cache objects of any type
CACHE_NONE = 0,
/// cache nodes loaded via readNode(filename)
CACHE_NODES = 1,
/// cache images loaded via readImage(filename)
CACHE_IMAGES = 2,
/// cache heightfield loaded via readHeightField(filename)
CACHE_HEIGHTFIELDS = 4,
/// cache heightfield loaded via readHeightField(filename)
CACHE_ARCHIVES = 8,
/// cache objects loaded via readObject(filename)
CACHE_OBJECTS = 16,
/// cache on all read*(filename) calls
CACHE_ALL = CACHE_NODES |
CACHE_IMAGES |
CACHE_HEIGHTFIELDS |
CACHE_ARCHIVES |
CACHE_OBJECTS
};
@@ -151,27 +121,27 @@ class OSGDB_EXPORT Registry : public osg::Referenced
{
public:
virtual ReaderWriter::ReadResult openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, CacheHintOptions useObjectCache)
virtual ReaderWriter::ReadResult openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* useObjectCache)
{
return osgDB::Registry::instance()->openArchiveImplementation(filename, status, indexBlockSizeHint, useObjectCache);
}
virtual ReaderWriter::ReadResult readObject(const std::string& filename, CacheHintOptions options)
virtual ReaderWriter::ReadResult readObject(const std::string& filename, const ReaderWriter::Options* options)
{
return osgDB::Registry::instance()->readObjectImplementation(filename,options);
}
virtual ReaderWriter::ReadResult readImage(const std::string& filename, CacheHintOptions options)
virtual ReaderWriter::ReadResult readImage(const std::string& filename, const ReaderWriter::Options* options)
{
return osgDB::Registry::instance()->readImageImplementation(filename,options);
}
virtual ReaderWriter::ReadResult readHeightField(const std::string& filename, CacheHintOptions options)
virtual ReaderWriter::ReadResult readHeightField(const std::string& filename, const ReaderWriter::Options* options)
{
return osgDB::Registry::instance()->readHeightFieldImplementation(filename,options);
}
virtual ReaderWriter::ReadResult readNode(const std::string& filename, CacheHintOptions options)
virtual ReaderWriter::ReadResult readNode(const std::string& filename, const ReaderWriter::Options* options)
{
return osgDB::Registry::instance()->readNodeImplementation(filename,options);
}
@@ -190,40 +160,40 @@ class OSGDB_EXPORT Registry : public osg::Referenced
const ReadFileCallback* getReadFileCallback() const { return _readFileCallback.get(); }
ReaderWriter::ReadResult openArchive(const std::string& fileName,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, CacheHintOptions useObjectCache)
ReaderWriter::ReadResult openArchive(const std::string& fileName,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* options)
{
if (_readFileCallback.valid()) return _readFileCallback->openArchive(fileName, status, indexBlockSizeHint, useObjectCache);
else return openArchiveImplementation(fileName, status, indexBlockSizeHint, useObjectCache);
if (_readFileCallback.valid()) return _readFileCallback->openArchive(fileName, status, indexBlockSizeHint, options);
else return openArchiveImplementation(fileName, status, indexBlockSizeHint, options);
}
ReaderWriter::ReadResult openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, CacheHintOptions useObjectCache);
ReaderWriter::ReadResult openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* options);
ReaderWriter::ReadResult readObject(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult readObject(const std::string& fileName,const ReaderWriter::Options* options)
{
if (_readFileCallback.valid()) return _readFileCallback->readObject(fileName,useObjectCache);
else return readObjectImplementation(fileName,useObjectCache);
if (_readFileCallback.valid()) return _readFileCallback->readObject(fileName,options);
else return readObjectImplementation(fileName,options);
}
ReaderWriter::ReadResult readObjectImplementation(const std::string& fileName,CacheHintOptions useObjectCache);
ReaderWriter::ReadResult readObjectImplementation(const std::string& fileName,const ReaderWriter::Options* options);
ReaderWriter::ReadResult readImage(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult readImage(const std::string& fileName,const ReaderWriter::Options* options)
{
if (_readFileCallback.valid()) return _readFileCallback->readImage(fileName,useObjectCache);
else return readImageImplementation(fileName,useObjectCache);
if (_readFileCallback.valid()) return _readFileCallback->readImage(fileName,options);
else return readImageImplementation(fileName,options);
}
ReaderWriter::ReadResult readImageImplementation(const std::string& fileName,CacheHintOptions useObjectCache);
ReaderWriter::ReadResult readImageImplementation(const std::string& fileName,const ReaderWriter::Options* options);
ReaderWriter::ReadResult readHeightField(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult readHeightField(const std::string& fileName,const ReaderWriter::Options* options)
{
if (_readFileCallback.valid()) return _readFileCallback->readHeightField(fileName,useObjectCache);
else return readHeightFieldImplementation(fileName,useObjectCache);
if (_readFileCallback.valid()) return _readFileCallback->readHeightField(fileName,options);
else return readHeightFieldImplementation(fileName,options);
}
ReaderWriter::ReadResult readHeightFieldImplementation(const std::string& fileName,CacheHintOptions useObjectCache);
ReaderWriter::ReadResult readHeightFieldImplementation(const std::string& fileName,const ReaderWriter::Options* options);
ReaderWriter::ReadResult readNode(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult readNode(const std::string& fileName,const ReaderWriter::Options* options)
{
if (_readFileCallback.valid()) return _readFileCallback->readNode(fileName,useObjectCache);
else return readNodeImplementation(fileName,useObjectCache);
if (_readFileCallback.valid()) return _readFileCallback->readNode(fileName,options);
else return readNodeImplementation(fileName,options);
}
ReaderWriter::ReadResult readNodeImplementation(const std::string& fileName,CacheHintOptions useObjectCache);
ReaderWriter::ReadResult readNodeImplementation(const std::string& fileName,const ReaderWriter::Options* options);
@@ -365,10 +335,10 @@ class OSGDB_EXPORT Registry : public osg::Referenced
void addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp = 0.0);
/** Set whether the Registry::ObjectCache should be used by default.*/
void setUseObjectCacheHint(CacheHintOptions useObjectCache) { _useObjectCacheHint = useObjectCache; }
void setUseObjectCacheHint(ReaderWriter::Options::CacheHintOptions useObjectCache) { _useObjectCacheHint = useObjectCache; }
/** Get whether the Registry::ObjectCache should be used by default.*/
CacheHintOptions getUseObjectCacheHint() const { return _useObjectCacheHint; }
ReaderWriter::Options::CacheHintOptions getUseObjectCacheHint() const { return _useObjectCacheHint; }
/** Add archive to archive cache so that future calls reference this archive.*/
@@ -494,21 +464,21 @@ class OSGDB_EXPORT Registry : public osg::Referenced
ExtensionAliasMap _extAliasMap;
// options to pass to reader writers.
osg::ref_ptr<ReaderWriter::Options> _options;
osg::ref_ptr<ReaderWriter::Options> _options;
FilePathList _dataFilePath;
FilePathList _libraryFilePath;
FilePathList _dataFilePath;
FilePathList _libraryFilePath;
CacheHintOptions _useObjectCacheHint;
ObjectCache _objectCache;
OpenThreads::Mutex _objectCacheMutex;
ReaderWriter::Options::CacheHintOptions _useObjectCacheHint;
ObjectCache _objectCache;
OpenThreads::Mutex _objectCacheMutex;
ArchiveCache _archiveCache;
OpenThreads::Mutex _archiveCacheMutex;
ArchiveCache _archiveCache;
OpenThreads::Mutex _archiveCacheMutex;
osg::ref_ptr<DatabasePager> _databasePager;
osg::ref_ptr<SharedStateManager> _sharedStateManager;
osg::ref_ptr<DatabasePager> _databasePager;
osg::ref_ptr<SharedStateManager> _sharedStateManager;
};