| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGDB_FILEUTILS |
|---|
| 15 | #define OSGDB_FILEUTILS 1 |
|---|
| 16 | |
|---|
| 17 | #include <osgDB/Registry> |
|---|
| 18 | |
|---|
| 19 | #include <vector> |
|---|
| 20 | #include <deque> |
|---|
| 21 | #include <string> |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | namespace osgDB { |
|---|
| 25 | |
|---|
| 26 | enum CaseSensitivity |
|---|
| 27 | { |
|---|
| 28 | CASE_SENSITIVE, |
|---|
| 29 | CASE_INSENSITIVE, |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | enum FileType |
|---|
| 33 | { |
|---|
| 34 | FILE_NOT_FOUND, |
|---|
| 35 | REGULAR_FILE, |
|---|
| 36 | DIRECTORY, |
|---|
| 37 | }; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | /** return true if a file exisits. */ |
|---|
| 41 | extern OSGDB_EXPORT bool fileExists(const std::string& filename); |
|---|
| 42 | |
|---|
| 43 | /** return type of file. */ |
|---|
| 44 | extern OSGDB_EXPORT FileType fileType(const std::string& filename); |
|---|
| 45 | |
|---|
| 46 | /** find specified file in specified file path.*/ |
|---|
| 47 | extern OSGDB_EXPORT std::string findFileInPath(const std::string& filename, const FilePathList& filePath,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| 48 | |
|---|
| 49 | /** return the directory/filename of a file if its is contained within specified directory. |
|---|
| 50 | * return "" if directory does not contain file. If caseInsensitive is set to true then |
|---|
| 51 | * a case insensitive comparison is used to compare fileName to directory contents. |
|---|
| 52 | * This is useful when unix programs attempt read case insentive windows filenames. |
|---|
| 53 | */ |
|---|
| 54 | extern OSGDB_EXPORT std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| 55 | |
|---|
| 56 | /** simple list of names to represent a directory's contents. */ |
|---|
| 57 | typedef std::vector<std::string> DirectoryContents; |
|---|
| 58 | |
|---|
| 59 | /** return the contents of a directory. |
|---|
| 60 | * returns an empty array on any error.*/ |
|---|
| 61 | extern OSGDB_EXPORT DirectoryContents getDirectoryContents(const std::string& dirName); |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | inline void setDataFilePathList(const FilePathList& filepath) { osgDB::Registry::instance()->setDataFilePathList(filepath); } |
|---|
| 66 | |
|---|
| 67 | inline void setDataFilePathList(const std::string& paths) { osgDB::Registry::instance()->setDataFilePathList(paths); } |
|---|
| 68 | |
|---|
| 69 | inline FilePathList& getDataFilePathList() { return osgDB::Registry::instance()->getDataFilePathList(); } |
|---|
| 70 | |
|---|
| 71 | extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| 72 | |
|---|
| 73 | /** Convinience class for pushing a path on construction, and popping the path |
|---|
| 74 | * and destruction. This helps keep the addition of a path local to a block |
|---|
| 75 | * of code, even in the presence of exceptions.*/ |
|---|
| 76 | class PushAndPopDataPath |
|---|
| 77 | { |
|---|
| 78 | public: |
|---|
| 79 | PushAndPopDataPath(const std::string& path) |
|---|
| 80 | { |
|---|
| 81 | getDataFilePathList().push_front(path); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | ~PushAndPopDataPath() |
|---|
| 85 | { |
|---|
| 86 | getDataFilePathList().pop_front(); |
|---|
| 87 | } |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | inline void setLibraryFilePathList(const FilePathList& filepaths) { osgDB::Registry::instance()->setLibraryFilePathList(filepaths); } |
|---|
| 92 | |
|---|
| 93 | inline void setLibraryFilePathList(const std::string& paths) { osgDB::Registry::instance()->setLibraryFilePathList(paths); } |
|---|
| 94 | |
|---|
| 95 | inline FilePathList& getLibraryFilePathList() { return osgDB::Registry::instance()->getLibraryFilePathList(); } |
|---|
| 96 | |
|---|
| 97 | extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| 98 | |
|---|
| 99 | // |
|---|
| 100 | // |
|---|
| 101 | // /** Deprecated. */ |
|---|
| 102 | // inline std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,bool caseInsensitive) |
|---|
| 103 | // { |
|---|
| 104 | // return findFileInDirectory(fileName,dirName,caseInsensitive?CASE_SENSITIVE:CASE_INSENSITIVE); |
|---|
| 105 | // } |
|---|
| 106 | // |
|---|
| 107 | |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | #endif |
|---|