root/OpenSceneGraph/trunk/include/osgDB/FileUtils @ 3330

Revision 3330, 3.9 kB (checked in by robert, 10 years ago)

Added a new osgDB::appendPlatformSpecificLibraryFilePaths() method to FileUtils?.cpp
Includes a new OSX code from Eric Wing

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
24namespace osgDB {
25
26enum CaseSensitivity
27{
28    CASE_SENSITIVE,
29    CASE_INSENSITIVE,
30};
31
32enum FileType
33{
34    FILE_NOT_FOUND,
35    REGULAR_FILE,
36    DIRECTORY,
37};
38
39
40/** return true if a file exisits. */
41extern OSGDB_EXPORT bool fileExists(const std::string& filename);
42
43/** return type of file. */
44extern OSGDB_EXPORT FileType fileType(const std::string& filename);
45
46/** find specified file in specified file path.*/
47extern 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  */
54extern 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. */
57typedef std::vector<std::string> DirectoryContents;
58
59/** return the contents of a directory.
60  * returns an empty array on any error.*/
61extern OSGDB_EXPORT DirectoryContents getDirectoryContents(const std::string& dirName);
62
63
64
65inline void setDataFilePathList(const FilePathList& filepath) { osgDB::Registry::instance()->setDataFilePathList(filepath); }
66
67inline void setDataFilePathList(const std::string& paths) { osgDB::Registry::instance()->setDataFilePathList(paths); }
68
69inline FilePathList& getDataFilePathList() { return osgDB::Registry::instance()->getDataFilePathList(); }
70
71extern 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.*/
76class 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
91inline void setLibraryFilePathList(const FilePathList& filepaths) { osgDB::Registry::instance()->setLibraryFilePathList(filepaths); }
92
93inline void setLibraryFilePathList(const std::string& paths) { osgDB::Registry::instance()->setLibraryFilePathList(paths); }
94
95inline FilePathList& getLibraryFilePathList() { return osgDB::Registry::instance()->getLibraryFilePathList(); }
96
97extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE);
98
99/** convert a string containing a list of paths  deliminated either with ';' (Windows) or ':' (All other platforms) into FilePath represetation.*/
100extern OSGDB_EXPORT void convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath);
101
102extern OSGDB_EXPORT void appendPlatformSpecificLibraryFilePaths(FilePathList& filepath);
103
104}
105
106#endif
Note: See TracBrowser for help on using the browser.