Refactored the Registry::ReadFileCallback, WriteFileCallback and ReaderWriter::Options to they are now defined in their own header and in the osgDB namespace.

Introduced a new FindFileCallback to Registry to compliement the existing ReadFileCallback and WriteFileCallback.

Added support for assign Find, Read and WriteFileCallbacks to osdDB::Options to enable plugins/applications to override the callbacks just for that
read/write call and any nested file operations
This commit is contained in:
Robert Osfield
2009-05-09 08:49:27 +00:00
parent a4ff2c4af7
commit b7b065abe3
43 changed files with 1180 additions and 825 deletions

View File

@@ -31,6 +31,9 @@ class Archive;
/** list of directories to search through which searching for files. */
typedef std::deque<std::string> FilePathList;
// forward declare
class Options;
/** pure virtual base class for reading and writing of non native formats. */
class OSGDB_EXPORT ReaderWriter : public osg::Object
{
@@ -52,10 +55,10 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
/** return which protocols are supported by ReaderWriter. */
virtual const FormatDescriptionMap& supportedProtocols() const { return _supportedProtocols; }
/** return which list of file extensions supported by ReaderWriter. */
virtual const FormatDescriptionMap& supportedExtensions() const { return _supportedExtensions; }
/** return which list of file extensions supported by ReaderWriter. */
virtual const FormatDescriptionMap& supportedOptions() const { return _supportedOptions; }
@@ -93,164 +96,6 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
/** return feature as string */
static FeatureList featureAsString(Features feature);
/** Options base class used for passing options into plugins to control their operation.*/
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,
/// cache nodes loaded via readNode(filename)
CACHE_NODES = 1<<0,
/// cache images loaded via readImage(filename)
CACHE_IMAGES = 1<<1,
/// cache heightfield loaded via readHeightField(filename)
CACHE_HEIGHTFIELDS = 1<<2,
/// cache heightfield loaded via readHeightField(filename)
CACHE_ARCHIVES = 1<<3,
/// cache objects loaded via readObject(filename)
CACHE_OBJECTS = 1<<4,
/// cache shaders loaded via readShader(filename)
CACHE_SHADERS = 1<<5,
/// cache on all read*(filename) calls
CACHE_ALL = CACHE_NODES |
CACHE_IMAGES |
CACHE_HEIGHTFIELDS |
CACHE_ARCHIVES |
CACHE_OBJECTS |
CACHE_SHADERS
};
/// range of options of whether to build kdtrees automatically on loading
enum BuildKdTreesHint
{
NO_PREFERENCE,
DO_NOT_BUILD_KDTREES,
BUILD_KDTREES
};
Options():
osg::Object(true),
_objectCacheHint(CACHE_ARCHIVES),
_buildKdTreesHint(NO_PREFERENCE) {}
Options(const std::string& str):
osg::Object(true),
_str(str),
_objectCacheHint(CACHE_ARCHIVES),
_buildKdTreesHint(NO_PREFERENCE) {}
Options(const Options& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(options,copyop),
_str(options._str),
_databasePaths(options._databasePaths),
_objectCacheHint(options._objectCacheHint),
_buildKdTreesHint(options._buildKdTreesHint),
_pluginData(options._pluginData),
_pluginStringData(options._pluginStringData){}
META_Object(osgDB,Options);
/** Set the general Options string.*/
void setOptionString(const std::string& str) { _str = str; }
/** Get the general Options string.*/
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) { _databasePaths.clear(); _databasePaths.push_back(str); }
/** Get the database path which is used a hint of where to look when loading models.*/
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 setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; }
/** Get whether the Registry::ObjectCache should be used by default.*/
CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; }
/** Set whether the KdTrees should be built for geometry in the loader model. */
void setBuildKdTreesHint(BuildKdTreesHint hint) { _buildKdTreesHint = hint; }
/** Get whether the KdTrees should be built for geometry in the loader model. */
BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; }
/** Set the password map to be used by plugins when access files from secure locations.*/
void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
/** Get the password map to be used by plugins when access files from secure locations.*/
const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); }
/** Sets a plugindata value PluginData with a string */
void setPluginData(const std::string& s, void* v) const { _pluginData[s] = v; }
/** Get a value from the PluginData */
void* getPluginData(const std::string& s) { return _pluginData[s]; }
/** Get a value from the PluginData */
const void* getPluginData(const std::string& s) const
{
PluginDataMap::const_iterator itr = _pluginData.find(s);
return (itr == _pluginData.end()) ? 0 : itr->second;
}
/** Remove a value from the PluginData */
void removePluginData(const std::string& s) const { _pluginData.erase(s); }
/** Sets a plugindata value PluginData with a string */
void setPluginStringData(const std::string& s, const std::string& v) const { _pluginStringData[s] = v; }
/** Get a string from the PluginStrData */
std::string getPluginStringData(const std::string& s) { return _pluginStringData[s]; }
/** Get a value from the PluginData */
const std::string getPluginStringData(const std::string& s) const
{
PluginStringDataMap::const_iterator itr = _pluginStringData.find(s);
return (itr == _pluginStringData.end()) ? std::string("") : itr->second;
}
/** Remove a value from the PluginData */
void removePluginStringData(const std::string& s) const { _pluginStringData.erase(s); }
protected:
virtual ~Options() {}
std::string _str;
FilePathList _databasePaths;
CacheHintOptions _objectCacheHint;
BuildKdTreesHint _buildKdTreesHint;
osg::ref_ptr<AuthenticationMap> _authenticationMap;
typedef std::map<std::string,void*> PluginDataMap;
mutable PluginDataMap _pluginData;
typedef std::map<std::string,std::string> PluginStringDataMap;
mutable PluginStringDataMap _pluginStringData;
};
class OSGDB_EXPORT ReadResult
@@ -353,6 +198,8 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
CREATE
};
typedef osgDB::Options Options;
/** open an archive for reading, writing, or to create an empty archive for writing to.*/
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }