Rewrote the FileUtils support for data and library file paths, moving the

storage of the path lists into osgDB::Registry, and changed the data
structor from a char* to a std::deque.  Changed a names of couple of the
convinience functions in osgDB/FileUtils to better reflect the two
public FilePathList's - DataFilePathList and the LibraryFilePathList.

Added support into the osgDB::Registry::readNode/Image/Object methods
for pushing and popping the path of the current file being loaded.
This commit is contained in:
Robert Osfield
2002-06-17 21:50:37 +00:00
parent 27412c27c9
commit 6767dd49d0
17 changed files with 502 additions and 714 deletions

View File

@@ -5,36 +5,22 @@
#ifndef OSGDB_FILEUTILS
#define OSGDB_FILEUTILS 1
#include <osgDB/Export>
#include <osgDB/Registry>
#include <vector>
#include <deque>
#include <string>
namespace osgDB {
/** initialize the data file path,
* uses OSGFILEPATH environmental
* variable to defined.*/
OSGDB_EXPORT extern void initFilePath( void );
/** set the data file path.*/
OSGDB_EXPORT extern void setFilePath( const char *_path );
/** return true if a file exisits. */
OSGDB_EXPORT extern bool fileExists(const std::string& filename);
/** set the data file path.*/
OSGDB_EXPORT extern const char* getFilePath();
/** find specified file if specified file path.*/
OSGDB_EXPORT extern char *findFileInPath( const char *_file, const char * filePath );
/** find specified file on the set data file path.*/
OSGDB_EXPORT extern char *findFile( const char *file );
/** find specified dso/dll.*/
OSGDB_EXPORT extern char *findDSO( const char *name );
/** simple list of names to represent a directory's contents. */
typedef std::vector<std::string> DirectoryContents;
/** find specified file in specified file path.*/
OSGDB_EXPORT extern std::string findFileInPath(const std::string& filename, const FilePathList& filePath);
/** return the directory/filename of a file if its is contained within specified directory.
* return "" if directory does not contain file. If caseInsensitive is set to true then
@@ -43,11 +29,50 @@ typedef std::vector<std::string> DirectoryContents;
*/
OSGDB_EXPORT extern std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,bool caseInsensitive=false);
/** simple list of names to represent a directory's contents. */
typedef std::vector<std::string> DirectoryContents;
/** return the contents of a directory.
* returns an empty array on any error.*/
OSGDB_EXPORT extern DirectoryContents getDirectoryContents(const std::string& dirName);
inline void setDataFilePathList(const FilePathList& filepath) { osgDB::Registry::instance()->setDataFilePathList(filepath); }
inline void setDataFilePathList(const std::string& paths) { osgDB::Registry::instance()->setDataFilePathList(paths); }
inline FilePathList& getDataFilePathList() { return osgDB::Registry::instance()->getDataFilePathList(); }
OSGDB_EXPORT extern std::string findDataFile(const std::string& filename);
/** 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:
PushAndPopDataPath(const std::string& path)
{
getDataFilePathList().push_front(path);
}
~PushAndPopDataPath()
{
getDataFilePathList().pop_front();
}
};
inline void setLibraryFilePathList(const FilePathList& filepaths) { osgDB::Registry::instance()->setLibraryFilePathList(filepaths); }
inline void setLibraryFilePathList(const std::string& paths) { osgDB::Registry::instance()->setLibraryFilePathList(paths); }
inline FilePathList& getLibraryFilePathList() { return osgDB::Registry::instance()->getLibraryFilePathList(); }
OSGDB_EXPORT extern std::string findLibraryFile(const std::string& filename);
}
#endif

View File

@@ -5,19 +5,24 @@
#ifndef OSGDB_REGISTRY
#define OSGDB_REGISTRY 1
#include <vector>
#include <map>
#include <string>
#include <osg/ref_ptr>
#include <osgDB/DynamicLibrary>
#include <osgDB/ReaderWriter>
#include <osgDB/DotOsgWrapper>
#include <vector>
#include <map>
#include <string>
#include <deque>
namespace osgDB {
/** list of directories to search through which searching for files. */
typedef std::deque<std::string> FilePathList;
/**
Registry is a singleton factory which stores
the reader/writers which are linked in
@@ -97,6 +102,46 @@ class OSGDB_EXPORT Registry
const ReaderWriter::Options* getOptions() const { return _options.get(); }
/** initilize both the Data and Library FilePaths, by default called by the
* constructor, so it should only be required if you want to force
* the re-reading of environmental variables.*/
void initFilePathLists() { initDataFilePathList(); initLibraryFilePathList(); }
/** initilize the Data FilePath by reading the OSG_FILE_PATH environmental variable.*/
void initDataFilePathList();
/** Set the data file path using a list of paths stored in a FilePath, which is used when search for data files.*/
void setDataFilePathList(const FilePathList& filepath) { _dataFilePath = filepath; }
/** Set the data file path using a single string deliminated either with ';' (Windows) or ':' (All other platforms), which is used when search for data files.*/
void setDataFilePathList(const std::string& paths) { _dataFilePath.clear(); convertStringPathIntoFilePathList(paths,_dataFilePath); }
/** get the data file path which is used when search for data files.*/
FilePathList& getDataFilePathList() { return _dataFilePath; }
/** get the const data file path which is used when search for data files.*/
const FilePathList& getDataFilePathList() const { return _dataFilePath; }
/** initilize the Library FilePath by reading the OSG_LIBRARY_PATH
* and the appropriate system environmental variables*/
void initLibraryFilePathList();
/** Set the library file path using a list of paths stored in a FilePath, which is used when search for data files.*/
void setLibraryFilePathList(const FilePathList& filepath) { _libraryFilePath = filepath; }
/** Set the library file path using a single string deliminated either with ';' (Windows) or ':' (All other platforms), which is used when search for data files.*/
void setLibraryFilePathList(const std::string& paths) { _libraryFilePath.clear(); convertStringPathIntoFilePathList(paths,_libraryFilePath); }
/** get the library file path which is used when search for library (dso/dll's) files.*/
FilePathList& getLibraryFilePathList() { return _libraryFilePath; }
/** get the const library file path which is used when search for library (dso/dll's) files.*/
const FilePathList& getLibraryFilePathList() const { return _libraryFilePath; }
/** convert a string containing a list of paths deliminated either with ';' (Windows) or ':' (All other platforms) into FilePath represetation.*/
static void convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath);
private:
typedef std::map<std::string,osg::ref_ptr<DotOsgWrapper> > DotOsgWrapperMap;
@@ -138,6 +183,9 @@ class OSGDB_EXPORT Registry
// options to pass to reader writers.
osg::ref_ptr<ReaderWriter::Options> _options;
FilePathList _dataFilePath;
FilePathList _libraryFilePath;
};