Changeset 7621 in orxonox.OLD
- Timestamp:
- May 15, 2006, 6:35:32 PM (18 years ago)
- Location:
- branches/qt_gui/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/qt_gui/src/lib/util/file.cc
r7620 r7621 33 33 #include <cassert> 34 34 35 File::File() 36 { 37 this->init(); 38 } 35 39 36 40 File::File(const std::string& fileName) 37 41 { 38 this->_name = fileName;39 File::homeDirCheck(this->_name);40 42 this->init(); 43 this->setFileName(fileName); 41 44 } 42 45 43 46 File::File(const File& file) 44 47 { 45 this->_name = file._name; 48 this->init(); 49 this->setFileName(file.name()); 46 50 } 47 51 48 52 File::~File() 49 53 { 54 this->close(); 55 50 56 if (this->_status) 51 57 delete this->_status; 52 if (this->_handle) 53 assert(0); 54 } 58 } 59 55 60 56 61 /** … … 62 67 { 63 68 this->_handle = 0; 64 65 this->_status = new struct stat; 69 this->_status = NULL; 70 } 71 72 73 /** 74 * @brief sets a new File to apply to this File. 75 * @param fileName the Filename of the File to access. 76 */ 77 void File::setFileName(const std::string& fileName) 78 { 79 this->close(); 80 this->_name = fileName; 81 File::homeDirCheck(this->_name); 82 this->statFile(); 83 } 84 85 86 void File::statFile() 87 { 88 if (this->_status == NULL) 89 this->_status = new struct stat; 66 90 // Check the End of the FileName and chop away any \ and // 67 91 /* std::string name = this->_name; … … 69 93 this->_name[this->_name.size()-1] == '\\') 70 94 name.resize(name.size()-1);*/ 71 72 95 if (stat(this->_name.c_str(), this->_status)) 73 96 { … … 87 110 } 88 111 89 int File::handle()90 {91 return this->_handle;92 }93 94 112 bool File::exists() const 95 113 { … … 97 115 } 98 116 117 /** 118 * @brief checks if the file is a Link (symlink/hardlink on UNIX) 119 * @returns true if the File is a Link, false otherwise (on windows always false) 120 */ 99 121 bool File::isLink() const 100 122 { … … 105 127 #endif 106 128 } 107 // only on UNIX 108 129 130 /** 131 * @brief checks if the File is a regular File 132 * @returns true if the File is a Regular file. 133 */ 109 134 bool File::isFile() const 110 135 { … … 113 138 114 139 /** 115 * @brief Checks if it is a Directory 116 * @param directoryName the Directory to check for 140 * @brief Checks if the File is a Directory 117 141 * @returns true if it is a directory/symlink false otherwise 118 142 */ … … 138 162 #endif 139 163 } 140 141 164 bool File::isWriteable() const 142 165 { … … 156 179 } 157 180 158 181 /** 182 * @brief copies the File to another File. 183 * @param destination the Destination File. 184 * @returns true on success, false otherwise. 185 */ 159 186 bool File::copy(const File& destination) 160 187 { … … 168 195 } 169 196 197 /** 198 * @brief renames the File (move) 199 * @param destination the Destination to move this file to. 200 * @returns true on success, false otherwise. 201 * 202 * if the File was opened, it will be closed throuh this function. 203 */ 170 204 bool File::rename(const File& destination) 171 205 { … … 173 207 { 174 208 this->close(); 175 delete this->_status;176 this->_status = NULL;177 209 this->_name = destination.name(); 178 this-> init();210 this->statFile(); 179 211 180 212 return true; … … 183 215 } 184 216 217 /** 218 * @brief touches the File. 219 * @returns true if the file could have been touched. false otherwise. 220 * 221 * Touching a File means creating it. 222 */ 185 223 bool File::touch() 186 224 { … … 195 233 } 196 234 235 /** 236 * @brief delete the File on the Disk 237 * @returns true on success, false otherwise. 238 */ 197 239 bool File::remove() 198 240 { … … 203 245 } 204 246 205 void File::relToAbs(std::string& fileName) 206 { 207 if (fileName.empty()) 247 /** 248 * @brief transforms a Relative path to an absolute one. 249 * @param fileName the Absolute Path. 250 */ 251 void File::relToAbs(std::string& relFileName) 252 { 253 if (relFileName.empty()) 208 254 return ; 209 if (fileName[0] != '/') 210 { 211 if (fileName[0] == '.' && fileName[1] != '.') 212 fileName.erase(0); 213 fileName = File::cwd() + fileName; 214 } 215 } 216 217 void File::absToRel(std::string& fileName) 218 { 219 if (fileName.find(cwd()) == 0) 220 fileName.replace(0, File::cwd().size(), "."); 221 } 222 223 255 if (relFileName[0] != '/') 256 { 257 if (relFileName[0] == '.' && relFileName[1] != '.') 258 relFileName.erase(0); 259 relFileName = File::cwd() + relFileName; 260 } 261 } 262 263 void File::absToRel(std::string& absFileName) 264 { 265 if (absFileName.find(cwd()) == 0) 266 absFileName.replace(0, File::cwd().size(), "."); 267 } 224 268 225 269 … … 243 287 } 244 288 245 289 /** 290 * @brief check if fileName has the '~/` prepended. 291 * @returns the fileName in absolute coordinate. 292 */ 246 293 void File::homeDirCheck(std::string& fileName) 247 294 { -
branches/qt_gui/src/lib/util/file.h
r7620 r7621 23 23 24 24 public: 25 File(); 25 26 File(const std::string& fileName); 26 27 File(const File& file); 27 28 ~File(); 29 void setFileName(const std::string& fileName); 30 File& operator=(const std::string& fileName); 31 File& operator=(const File& file); 32 bool operator==(const std::string& fileName) const; 33 bool operator==(const File& file) const; 34 35 28 36 29 37 virtual bool open(OpenMode mode); 30 38 virtual bool close(); 31 int handle() ;39 int handle() const { return this->_handle; }; 32 40 33 41 /** @returns the FileName of this File */ … … 48 56 bool remove(); 49 57 50 static void relToAbs(std::string& fileName);51 static void absToRel(std::string& fileName);58 static void relToAbs(std::string& relFileName); 59 static void absToRel(std::string& absFileName); 52 60 static const std::string& cwd(); 53 61 54 62 private: 55 63 void init(); 56 boolstatFile();64 void statFile(); 57 65 void homeDirCheck(std::string& fileName); 58 66
Note: See TracChangeset
for help on using the changeset viewer.