00001 00002 // 00003 // Copyright (C) 2000 00004 // Ralf Westram 00005 // Time-stamp: <Fri Dec/06/2002 05:19 MET Coder@ReallySoft.de> 00006 // 00007 // Permission to use, copy, modify, distribute and sell this software 00008 // and its documentation for any purpose is hereby granted without fee, 00009 // provided that the above copyright notice appear in all copies and 00010 // that both that copyright notice and this permission notice appear 00011 // in supporting documentation. Ralf Westram makes no 00012 // representations about the suitability of this software for any 00013 // purpose. It is provided "as is" without express or implied warranty. 00014 // 00015 // This code is part of my library. 00016 // You may find a more recent version at http://www.reallysoft.de/ 00017 // 00019 00020 #ifndef DIRECTORY_H 00021 #define DIRECTORY_H 00022 00023 #ifndef __SET__ 00024 #include <set> 00025 #endif 00026 #ifndef __MAP__ 00027 #include <map> 00028 #endif 00029 00030 // #define HAVE_STDC 00031 #ifndef __STAT_H__ 00032 #include <sys/stat.h> 00033 #endif 00034 00035 #ifndef BINFILE_H 00036 #include <BinFile.h> 00037 #endif 00038 00039 00040 namespace rs { 00041 00046 namespace file { 00047 00049 extern char DIR_SEPARATOR; 00050 00055 std::string catDF(const std::string& directory, const std::string& filename); 00056 00057 // ------------------------------------------------- 00058 // class Directory : public BinaryStoreable 00059 // ------------------------------------------------- 00060 00067 class Directory : public rs::file::BinaryStoreable { 00068 private: 00069 std::string name_; // full path of Directory 00070 std::set<std::string> files; // the files in this directory 00071 time_t oldest_; // modification time of oldest 00072 time_t newest_; // and newest accepted file 00073 00074 public: 00076 Directory() { oldest_ = newest_ = 0; } 00077 virtual ~Directory() {} 00078 00082 void addFile(const std::string& filename, time_t t); 00083 00086 void setName(const std::string& dirname) { name_ = dirname; } 00087 00089 const std::string& name() const { return name_; } 00090 00092 size_t size() const { return files.size(); } 00093 00095 std::set<std::string>::const_iterator begin() const { return files.begin(); } 00097 std::set<std::string>::const_iterator end() const { return files.end(); } 00098 00102 std::string fullPath(const std::string& filename) const; 00103 00105 time_t oldest() const { return oldest_; } 00107 time_t newest() const { return newest_; } 00108 00110 virtual void save(rs::file::BinaryFile& out) const; 00112 virtual void load(rs::file::BinaryFile& in, int version); 00113 }; 00114 00119 typedef std::map<std::string, Directory> Directories; 00120 00122 typedef bool (*predicate)(const std::string& dirname, const char *filename, const struct stat& filestat); 00123 00136 void scanDir(Directories& dirs, 00137 const std::string& rootdir, 00138 bool recurse, 00139 bool follow_links, 00140 predicate takeFile, 00141 predicate recurseDirectory, 00142 std::ostream *display); 00143 00148 void scanDir(Directories& dirs, 00149 const std::string& rootdir, 00150 bool recurse, 00151 bool follow_links, 00152 predicate takeFile, 00153 std::ostream *display); 00154 00156 void saveDirectories(const Directories& dirs, rs::file::BinaryFile& out); 00158 void loadDirectories(Directories& dirs, rs::file::BinaryFile& in); 00159 00165 std::string canonicalize(const std::string& filename, bool to_win32 = (DIR_SEPARATOR == '\\')); 00166 00170 inline bool is_canonical(const std::string& filename) { return filename == canonicalize(filename); } 00171 00176 std::string extractDirectory(const std::string& fullpath); 00177 00182 std::string extractFilename(const std::string& fullpath); 00183 00185 void backslashes2slashes(std::string& filename); 00186 00192 bool isLink(const std::string& file, std::string& target); 00193 }; 00194 00195 }; // end of namespace rs 00196 00197 #else 00198 #error Directory.h included twice 00199 #endif // DIRECTORY_H
Contact me in case of errors or questions. This documentation is powered by . |
(C) 2000-2002 |