00001 #ifndef JOBOPTIONS_DIRSEARCHPATH_H
00002 #define JOBOPTIONS_DIRSEARCHPATH_H
00003
00008 #include <list>
00009 #include <functional>
00010 #include <string>
00011 #include "boost/filesystem/path.hpp"
00012 #include "boost/filesystem/exception.hpp"
00018 class DirSearchPath {
00019 public:
00020 typedef boost::filesystem::path path;
00021
00023
00024 DirSearchPath() { addCWD(); }
00026 #ifdef _WIN32
00027 DirSearchPath(const std::string& stringifiedPath, const char* separator=",;");
00028 #else
00029 DirSearchPath(const std::string& stringifiedPath, const char* separator=",:");
00030 #endif
00031
00032
00034
00035
00036 bool add(const path& dir);
00037 bool addCWD();
00038
00039
00041
00042
00043
00044 bool find(const std::string& fileName, std::string& fullFileName) const;
00046 bool find(const path& file, path& fileFound) const;
00048 std::list<path> find_all(const path& file) const;
00050
00051
00053
00054 static bool existsDir(const std::string& dirName);
00055 static bool existsDir(const path& dir);
00056
00057
00058 private:
00059
00061 struct eqPath : public std::unary_function<const path&,bool> {
00062 eqPath(const path& ref) : m_ref(ref) {}
00063 bool operator() (const path& p) const {
00064 return p.string() == m_ref.string();
00065 }
00066 private:
00067 path m_ref;
00068 };
00069
00070
00071
00072
00073
00074
00076
00077
00078
00079
00080 std::list<path> m_dirs;
00081 };
00082 #endif // JOBOPTIONS_DIRSEARCHPATH_H