BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // $Id: directory.h,v 1.29.16.1 2007/03/25 21:25:38 oliver Exp $ 00005 // 00006 00007 #ifndef BALL_SYSTEM_DIRECTORY_H 00008 #define BALL_SYSTEM_DIRECTORY_H 00009 00010 #ifndef BALL_COMMON_H 00011 # include <BALL/common.h> 00012 #endif 00013 00014 #ifndef BALL_CONCEPT_PROCESSOR_H 00015 # include <BALL/CONCEPT/processor.h> 00016 #endif 00017 00018 #ifndef BALL_DATATYPE_STRING_H 00019 # include <BALL/DATATYPE/string.h> 00020 #endif 00021 00022 #ifndef BALL_SYSTEM_FILESYSTEM_H 00023 # include <BALL/SYSTEM/fileSystem.h> 00024 #endif 00025 00026 #ifdef BALL_HAS_DIRENT_H 00027 # include <dirent.h> 00028 #endif 00029 #ifdef BALL_HAS_UNISTD_H 00030 # include <unistd.h> 00031 #endif 00032 #ifdef BALL_HAS_SYS_STAT_H 00033 # include <sys/stat.h> 00034 #endif 00035 #ifdef BALL_HAS_DIRECT_H 00036 # include <direct.h> 00037 #endif 00038 #include <stdio.h> 00039 #ifdef BALL_COMPILER_MSVC 00040 #define WINDOWS_LEAN_AND_MEAN 00041 #include <windows.h> 00042 #define mode_t int 00043 #endif 00044 00045 namespace BALL 00046 { 00050 class BALL_EXPORT Directory 00051 { 00052 #ifndef BALL_OS_WINDOWS 00053 # define INVALID_HANDLE_VALUE 0 00054 #endif 00055 00056 public: 00057 00061 00066 static const Size MAX_PATH_LENGTH; 00067 00069 00072 00079 Directory(); 00080 00089 Directory(const String& directory_path, bool set_current = false); 00090 00096 Directory(const Directory& directory); 00097 00100 ~Directory(); 00101 00106 void clear(); 00107 00110 void destroy(); 00111 00113 00116 00124 bool set(const String& directory_path, bool set_current = false); 00125 00130 void set(const Directory& directory); 00131 00135 Directory& operator = (const Directory& directory); 00136 00141 void get(Directory& directory) const; 00143 00147 00153 const String& getPath() const; 00154 00162 bool rename(String old_path, String new_path); 00163 00168 bool renameTo(String new_path); 00169 00174 bool setCurrent(String directory_path); 00175 00179 bool setCurrent(); 00180 00188 bool create(String path, const mode_t& mode = 0777); 00189 00196 bool remove(String old_path); 00197 00202 bool remove(); 00203 00208 bool getFirstEntry(String& entry); 00209 00214 bool getNextEntry(String& entry); 00215 00219 Size countItems(); 00220 00224 Size countFiles(); 00225 00229 Size countDirectories(); 00230 00237 bool find(const String& filename, String& filepath); 00238 00240 00243 00248 bool has(const String& item); 00249 00255 bool isValid() const; 00256 00260 bool isCurrent() const; 00261 00265 bool isEmpty(); 00266 00270 bool operator == (const Directory& directory) const; 00271 00275 bool operator != (const Directory& directory) const; 00276 00278 static String getUserHomeDir(); 00279 00281 static bool changeToUserHomeDir(); 00282 00284 00285 private: 00286 00287 //_wrapper function around getcwd to handle different naming conventions in different OS 00288 String getcwd_(); 00289 00290 //_wrapper function around chdir to handle different naming conventions in different OS 00291 int chdir_(const String& new_dir); 00292 00293 //_switch to this dir 00294 void synchronize_(); 00295 00296 //_switch back to the working directory 00297 bool desynchronize_(bool result = true); 00298 #ifdef BALL_COMPILER_MSVC 00299 HANDLE dirent_; 00300 HANDLE dir_; 00301 #else 00302 DIR* dir_; 00303 dirent* dirent_; 00304 #endif 00305 String directory_path_; 00306 String backup_path_; 00307 }; 00308 00309 # ifndef BALL_NO_INLINE_FUNCTIONS 00310 # include <BALL/SYSTEM/directory.iC> 00311 # endif 00312 00313 } // namespace BALL 00314 00315 #endif // BALL_SYSTEM_DIRECTORY_H