path.h

Go to the documentation of this file.
00001 
00015 #ifndef _DLR_PATH_H_
00016 #define _DLR_PATH_H_
00017 
00018 #include <string>
00019 #include <vector>
00020 
00021 namespace dlr {
00022 
00023   namespace utilities {
00024 
00036     bool
00037     isDirectory(const std::string& path);
00038   
00039   
00040     bool
00041     isExistingPath(const std::string& path);
00042   
00043   
00044     bool
00045     isRegularFile(const std::string& path);
00046     
00047     
00059     std::string
00060     joinPath(const std::string& part0, const std::string& part1);
00061 
00062   
00074     std::vector<std::string>
00075     listDirectory(const std::string& directoryName, bool fullPath=false);
00076 
00077 
00109     std::vector<std::string>
00110     recursiveListDirectory(const std::string& directoryName,
00111                            bool fullPath=false,
00112                            bool includeDirectoryNames=false);
00113 
00114 
00201     template <class IterType>
00202     bool
00203     searchForFile(const std::string& fileName,
00204                   IterType pathBegin, IterType pathEnd,
00205                   std::string& fullPath,
00206                   bool discardInputDir = false);
00207     
00208   
00216     std::pair<std::string, std::string>
00217     splitExtension(const std::string& fileName);
00218 
00219 
00249     std::pair<std::string, std::string>
00250     splitPath(const std::string& path);
00251 
00252   } // namespace utilities
00253     
00254 } // namespace dlr
00255 
00256 
00257 /* ======= Declarations to maintain compatibility with legacy code. ======= */
00258 
00259 namespace dlr {
00260 
00261   using utilities::isDirectory;
00262   using utilities::isExistingPath;
00263   using utilities::isRegularFile;
00264   using utilities::joinPath;
00265   using utilities::listDirectory;
00266   using utilities::recursiveListDirectory;
00267   using utilities::splitExtension;
00268   using utilities::splitPath;
00269   
00270 } // namespace dlr
00271 
00272 
00273 /* ======= Declarations of inline and template functions. ======= */
00274 
00275 namespace dlr {
00276 
00277   namespace utilities {
00278     
00279     // This function searches a sequence of directories looking for
00280     // the specified file.
00281     template <class IterType>
00282     bool
00283     searchForFile(const std::string& fileName,
00284                   IterType pathBegin, IterType pathEnd,
00285                   std::string& fullPath,
00286                   bool discardInputDir)
00287     {
00288       std::string baseName;
00289       if(discardInputDir) {
00290         baseName = splitPath(fileName).second;
00291       } else {
00292         baseName = fileName;
00293       }
00294       while(pathBegin != pathEnd) {
00295         std::string candidateName = joinPath(*pathBegin, baseName);
00296         if(isRegularFile(candidateName)) {
00297           fullPath = candidateName;
00298           return true;
00299         }
00300         ++pathBegin;
00301       }
00302       return false;
00303     }
00304 
00305   } // namespace utilities
00306   
00307 } // namespace dlr
00308 
00309 #endif // #ifndef _DLR_PATH_H_

Generated on Wed Nov 25 11:07:09 2009 for dlrUtilities Utility Library by  doxygen 1.5.8