#include <jccl/Config/ParseUtil.h>
Collaboration diagram for jccl::ParseUtil:

Static Public Member Functions | |
| static std::string | expandFileName (const std::string &name, const std::string &parentFile) |
| Expands a filename to a string capable of being passed to an I/O system call. | |
| static void | setCfgSearchPath (const std::string &path) |
| Replaces the current configuration file search path with the given string. | |
Static Private Member Functions | |
| static vpr::ReturnStatus | findFileUsingPath (const std::string &fileName, std::string &absoluteFile) |
| Looks for a file in a path and opens it if found. | |
Static Private Attributes | |
| static SearchPathData | mSearchInfo |
Classes | |
| struct | SearchPathData |
| Simple helper type to ensure that the static data in this class is initialized at the same time. More... | |
Definition at line 48 of file ParseUtil.h.
| std::string jccl::ParseUtil::expandFileName | ( | const std::string & | name, | |
| const std::string & | parentFile | |||
| ) | [static] |
Expands a filename to a string capable of being passed to an I/O system call.
The result may be an absolute path depending on various factors.
| name | The name to expand. | |
| parentFile | The name of the file that n is being loaded relative to. |
Definition at line 55 of file ParseUtil.cpp.
References findFileUsingPath(), and jcclDBG_CONFIG().
Referenced by jccl::ElementFactory::loadDef(), and jccl::ElementFactory::loadDefs().
00057 { 00058 std::string fname = vpr::replaceEnvVars(name); 00059 00060 fs::path fname_path(fname, fs::native); 00061 00062 // If the given file name does not exist, try searching for it. 00063 if ( ! fs::exists(fname_path) ) 00064 { 00065 // If the given file name is not absolute, look it up relative to 00066 // parentfile or using the config file search path. 00067 if ( ! fname_path.is_complete() ) 00068 { 00069 // If the parentfile string is empty, we'll use the search path to 00070 // find the file. 00071 if ( parentfile.empty() ) 00072 { 00073 vprDEBUG(jcclDBG_CONFIG, vprDBG_STATE_LVL) 00074 << "[jccl::ParseUtil::expandFileName()] Looking up '" << fname 00075 << "' using search path ...\n" << vprDEBUG_FLUSH; 00076 00077 std::string absolute_fname; 00078 if ( findFileUsingPath(fname, absolute_fname).success() ) 00079 { 00080 fname_path = fs::path(absolute_fname, fs::native); 00081 } 00082 } 00083 // parentfile is not empty, so we assume that fname is relative to 00084 // parentfile. 00085 else 00086 { 00087 fs::path parentfile_path(parentfile, fs::native); 00088 fs::path parentdir = parentfile_path.branch_path(); 00089 fname_path = parentdir / fname_path; 00090 } 00091 } 00092 } 00093 00094 return fname_path.native_file_string(); 00095 }
| void jccl::ParseUtil::setCfgSearchPath | ( | const std::string & | path | ) | [static] |
Replaces the current configuration file search path with the given string.
| path | A string of directories separted by a platform-specific path separation character. On Windows, this character is ';', and on UNIX and Mac OS X, this character is ':'. |
Definition at line 97 of file ParseUtil.cpp.
References mSearchInfo, and jccl::ParseUtil::SearchPathData::setSearchPath().
00098 { 00099 mSearchInfo.setSearchPath(path); 00100 }
| vpr::ReturnStatus jccl::ParseUtil::findFileUsingPath | ( | const std::string & | fileName, | |
| std::string & | absoluteFile | |||
| ) | [static, private] |
Looks for a file in a path and opens it if found.
| fileName | The name of a file to search for. | |
| absoluteFile | Storage for the absolute path to the file if it was found in the path. |
Definition at line 102 of file ParseUtil.cpp.
References jcclDBG_CONFIG(), jccl::ParseUtil::SearchPathData::mPath, and mSearchInfo.
Referenced by expandFileName().
00104 { 00105 vpr::ReturnStatus status(vpr::ReturnStatus::Fail); 00106 fs::path filename_path(fileName, fs::native); 00107 00108 for ( std::vector<std::string>::iterator i = mSearchInfo.mPath.begin(); 00109 i != mSearchInfo.mPath.end(); 00110 ++i ) 00111 { 00112 fs::path full_path = fs::path(*i, fs::native) / filename_path; 00113 00114 vprDEBUG(jcclDBG_CONFIG, vprDBG_HVERB_LVL) 00115 << "[jccl::ParseUtil::findFileUsingPath()] Attempting to open file '" 00116 << full_path.native_file_string() << "'\n" << vprDEBUG_FLUSH; 00117 00118 try 00119 { 00120 if ( fs::exists(full_path) && ! fs::is_directory(full_path) ) 00121 { 00122 status.setCode(vpr::ReturnStatus::Succeed); 00123 absoluteFile = full_path.native_file_string(); 00124 break; 00125 } 00126 } 00127 catch(fs::filesystem_error&) 00128 { 00129 /* Ignore the exception. */ ; 00130 } 00131 } 00132 00133 return status; 00134 }
ParseUtil::SearchPathData jccl::ParseUtil::mSearchInfo [static, private] |
Definition at line 111 of file ParseUtil.h.
Referenced by findFileUsingPath(), setCfgSearchPath(), and jccl::ParseUtil::SearchPathData::setSearchPath().
1.5.1