#include <FileIO.h>
Static Public Methods | |
| void | addFilePath (const std::string &filepath=".") |
| bool | isAbsolutePathName (const std::string &n) |
| Is n an absolute path name? More... | |
| std::string | demangleFileName (const std::string &n, std::string parentfile) |
| n is your filename. More... | |
| bool | fileExists (const char *const name) |
| Checks if file exists. More... | |
| bool | fileExists (const std::string &name) |
| bool | fileExistsResolvePath (const char *const filename, std::string &realPath) |
| Checks if file exists in any of the registered paths. More... | |
| bool | fileExistsResolvePath (const std::string &filename, std::string &realPath) |
| std::string | resolvePathForName (const char *const filename) |
Static Public Attributes | |
| std::vector< std::string > | mPaths |
|
|
Definition at line 44 of file FileIO.cpp. References mPaths.
00045 {
00046 std::string demangled = vpr::replaceEnvVars( filepath );
00047 mPaths.push_back( demangled );
00048 }
|
|
|
Is n an absolute path name?
Definition at line 110 of file FileIO.cpp. Referenced by demangleFileName.
00111 {
00112 #ifdef WIN32
00113 return ((n.length() > 0) && (n[0] == '\\'))
00114 || ((n.length() > 2) && (n[1] == ':') && (n[2] == '\\'));
00115 #else
00116 return (n.length() > 0) && (n[0] == '/');
00117 #endif
00118 }
|
|
||||||||||||
|
n is your filename. returns n with all ${...} names replaced with their env vars. if ${...} not found... then replaces it with "", and emits error message to console. Definition at line 122 of file FileIO.cpp. References isAbsolutePathName. Referenced by fileExists, and resolvePathForName.
00123 {
00124
00125 std::string fname = vpr::replaceEnvVars (n);
00126
00127 if (!isAbsolutePathName(fname))
00128 {
00129 // it's a relative pathname... so we have to add in the path part
00130 // of parentfile...
00131 // cout << "demangling relative pathname '" << fname.c_str() << "' with parent dir '"
00132 // << parentfile.c_str() << "'\n" << endl;
00133 int lastslash = 0;
00134 for (unsigned int i = 0; i < parentfile.length(); i++)
00135 {
00136 if (parentfile[i] == '/')
00137 lastslash = i;
00138 #ifdef WIN32
00139 if (parentfile[i] == '\\')
00140 lastslash = i;
00141 #endif
00142 }
00143 if (lastslash)
00144 {
00145 std::string s(parentfile, 0, lastslash+1);
00146 fname = s + n;
00147 }
00148 }
00149
00150 return fname;
00151 }
|
|
|
Checks if file exists. Does a demangle on the name before checking. Definition at line 51 of file FileIO.cpp. References demangleFileName. Referenced by fileExists, fileExistsResolvePath, and resolvePathForName.
00052 {
00053 std::string stdstring_name = name;
00054 std::string demangled_name = demangleFileName( stdstring_name, "" );
00055 FILE* file = ::fopen( demangled_name.c_str(), "r" );
00056 if (file == NULL)
00057 {
00058 return false;
00059 }
00060
00061 else
00062 {
00063 ::fclose( file );
00064 return true;
00065 }
00066 }
|
|
|
Definition at line 68 of file FileIO.cpp. References fileExists.
00069 {
00070 return fileExists( name.c_str() );
00071 }
|
|
||||||||||||
|
Checks if file exists in any of the registered paths.
Definition at line 73 of file FileIO.cpp. References fileExists, and resolvePathForName. Referenced by fileExistsResolvePath.
00074 {
00075 realPath = resolvePathForName( filename );
00076 return fileExists( realPath.c_str() );
00077 }
|
|
||||||||||||
|
Definition at line 79 of file FileIO.cpp. References fileExistsResolvePath.
00080 {
00081 return fileExistsResolvePath( filename.c_str(), realPath );
00082 }
|
|
|
Definition at line 84 of file FileIO.cpp. References demangleFileName, and fileExists. Referenced by fileExistsResolvePath.
00085 {
00086 std::string stdstring_name = filename;
00087 std::string demangled_name = demangleFileName( stdstring_name, "" );
00088
00089 for (unsigned int x = 0; x < FileIO::mPaths.size(); ++x)
00090 {
00091 std::string slash = "/";
00092 std::string temp = FileIO::mPaths[x] + slash + demangled_name;
00093
00094 // if this path works, then return it.
00095 if (fileExists( temp ))
00096 {
00097 std::cout<<"Fixed path: "<<temp.c_str()<<"\n"<<std::flush;
00098 return temp;
00099 }
00100 }
00101
00102 // couldn't find any that matched, so just return the filename.
00103 //cout<<"Did not need to fix path: "<<demangled_name<<"\n"<<flush;
00104 return demangled_name;
00105 }
|
|
|
Definition at line 42 of file FileIO.cpp. Referenced by addFilePath. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002