OpenSceneGraph/include/osgDB/FileUtils
Robert Osfield 6767dd49d0 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.
2002-06-17 21:50:37 +00:00

79 lines
2.7 KiB
Plaintext

//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSGDB_FILEUTILS
#define OSGDB_FILEUTILS 1
#include <osgDB/Registry>
#include <vector>
#include <deque>
#include <string>
namespace osgDB {
/** return true if a file exisits. */
OSGDB_EXPORT extern bool fileExists(const std::string& filename);
/** 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
* a case insensitive comparison is used to compare fileName to directory contents.
* This is useful when unix programs attempt read case insentive windows filenames.
*/
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