00001 #ifndef Impala_Util_DirectoryInfo_h 00002 #define Impala_Util_DirectoryInfo_h 00003 00004 #include <vector> 00005 #include <string> 00006 #include "Util/FileInfo.h" 00007 #ifndef unix 00008 #include <windows.h> 00009 #endif 00010 00011 00012 namespace Impala 00013 { 00014 namespace Util 00015 { 00016 00017 class DirectoryInfo 00018 { 00019 public: 00020 DirectoryInfo(const std::string& name) 00021 : mName(name), mShortName(name), mFilter("*") 00022 { 00023 } 00024 00025 DirectoryInfo(const std::string& name, const std::string& shortname) 00026 : mName(name), mShortName(shortname), mFilter("*") 00027 { 00028 00029 } 00030 00031 void 00032 SetFilter(const std::string& filter) 00033 { 00034 mFilter = filter; 00035 } 00036 00037 void 00038 Scan(); 00039 00040 void 00041 Clear() 00042 { 00043 unsigned int i; 00044 for (i=0 ; i<mSubDirs.size() ; i++) 00045 { 00046 delete mSubDirs[i]; 00047 } 00048 mSubDirs.clear(); 00049 for (i=0 ; i<mFiles.size() ; i++) 00050 { 00051 delete mFiles[i]; 00052 } 00053 mFiles.clear(); 00054 } 00055 00056 size_t 00057 GetFileCount() 00058 { 00059 return mFiles.size(); 00060 } 00061 00062 Util::FileInfo* 00063 GetFile(unsigned int index) 00064 { 00065 if(index > mFiles.size()) 00066 throw std::logic_error("[DirectoryInfo::GetFile] index out of bounds"); 00067 return mFiles[index]; 00068 } 00069 00070 size_t 00071 GetSubDirCount() 00072 { 00073 return mSubDirs.size(); 00074 } 00075 00076 DirectoryInfo* 00077 GetSubDir(unsigned int index) 00078 { 00079 if (index > mSubDirs.size()) 00080 throw std::logic_error("[DirectoryInfo::GetSubDir] index out of bounds"); 00081 return mSubDirs[index]; 00082 } 00083 00084 std::string GetName() 00085 { 00086 return mName; 00087 } 00088 00089 std::string GetShortName() 00090 { 00091 return mShortName; 00092 } 00093 00094 static void 00095 SetAutoScanSubDirs(bool value) 00096 { 00097 mAutoScanSubDirs = value; 00098 } 00099 00100 void 00101 Print(std::ostream& os) const 00102 { 00103 os << "directory \"" << mName << "\"\n"; 00104 for (unsigned int i=0 ; i<mFiles.size() ; ++i) 00105 os << "- " << mFiles[i]->mName << "\n"; 00106 } 00107 00108 protected: 00109 00110 std::vector<DirectoryInfo*> mSubDirs; 00111 std::vector<Util::FileInfo*> mFiles; 00112 std::string mName; 00113 std::string mShortName; 00114 std::string mFilter; 00115 #ifndef unix 00116 WIN32_FIND_DATA mInfo; 00117 00118 void CopyWinFindData(WIN32_FIND_DATA* dst, const WIN32_FIND_DATA* src) const; 00119 #endif 00120 static bool mAutoScanSubDirs; 00121 }; 00122 00123 inline std::ostream& 00124 operator<< (std::ostream& os, const DirectoryInfo& d) 00125 { 00126 d.Print(os); 00127 return os; 00128 } 00129 00130 } // namespace Util 00131 } // namespace Impala 00132 00133 #endif Impala_Util_DirectoryInfo_h