00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef VRS_IO_FILE_H
00021 #define VRS_IO_FILE_H
00022
00023 #include <vrs/sharedobj.h>
00024 #include <vector>
00025
00026 namespace VRS {
00027
00028 class DataResource;
00029
00031 class VRS_CORE_API File : public SharedObj {
00032 public:
00033 enum WriteMode { WM_ReadOnly, WM_Create, WM_Overwrite, WM_Append };
00034 enum SeekMode { SM_FromStart, SM_FromCurrent, SM_FromEnd };
00035 enum FileTime { Access, Modification };
00036 VRS_SERIALIZABLE_CLASS_ENUM(WriteMode);
00037 VRS_SERIALIZABLE_CLASS_ENUM(SeekMode);
00038
00039 File(const std::string& filename, WriteMode writeMode = WM_ReadOnly);
00051 bool isReadOnly() const;
00052
00053 std::string fullName() const;
00055
00056 std::string fileName() const;
00060 std::string pathName() const;
00064 std::string baseName() const;
00068 std::string extensionName() const;
00072 std::string replaceExtensionName(const std::string& extensionName) const;
00077 UINT64 size() const;
00079
00080 UINT64 position() const;
00082
00083 UINT64 seek(INT64 relativePosition, SeekMode seekMode = SM_FromStart);
00093 UINT64 read(void* writeInto, UINT64 bytes);
00098 UINT64 write(const void* readFrom, UINT64 bytes);
00103 UINT64 resize(UINT64 bytes);
00112 UINT64 truncate();
00117 SO<DataResource> mapToMemory();
00122 static bool exists(const std::string& filename);
00124
00125 static bool isFile(const std::string& filename);
00127
00128 static bool isDir(const std::string& dirname);
00130
00131 static bool isRelative(const std::string& name);
00133
00134 static std::vector<std::string> matchingEntries(
00135 const std::string& dirName,
00136 const std::string& pattern = "*",
00137 bool includeFiles = true,
00138 bool includeDirs = true,
00139 bool recurseIntoSubDirs = false
00140 );
00151 static UINT64 size(const std::string& filename);
00155 static bool create(const std::string& filename, UINT64 size = 0, const void* copyFrom = NULL);
00161 static bool append(const std::string& filename, UINT64 size, const void* copyFrom = NULL);
00167 static bool rename(const std::string& oldFilename, const std::string& newFilename);
00169
00170 static bool getFileTime(const std::string& filename, FileTime type, time_t* time);
00171
00172 static bool setFileTime(const std::string& filename, FileTime type, time_t time);
00173
00174 static bool copy(const std::string& fromFilename, const std::string& toFilename);
00176
00177 static bool remove(const std::string& filename);
00179
00181 static bool createDir(const std::string& dirname);
00182
00184 static bool removeDir(const std::string& dirname);
00185
00189 static bool removeOldFiles(const std::string& dirname, const std::string& fileExtension, unsigned int numberOfFilesToRemove = 20);
00190
00191 static std::string temporaryDir();
00195 static void temporaryDir(const std::string& tempDir);
00199 static std::string temporaryFileName(const std::string& fileNamePrefix = "");
00201
00202 static SO<File> newTemporaryFile(const std::string& fileNamePrefix = "");
00204
00205 static std::string fileName(const std::string& fullFileName);
00209 static std::string pathName(const std::string& fullFileName);
00215 static std::string baseName(const std::string& fullFileName);
00219 static std::string extensionName(const std::string& fullFileName);
00224 static std::string replaceExtensionName(const std::string& fullFileName, const std::string& extensionName);
00228 static SO<DataResource> mapToMemory(const std::string& fileName, bool readOnly = true);
00232 static std::string currentWorkingDir(const int drive = -1);
00237 static std::string initialWorkingDir();
00238
00239 static std::string relativePath(const std::string& absolutePath, const std::string& relativeTo = File::currentWorkingDir(), const bool absolutePathIsDir = false);
00241
00249 static std::string absolutePath(const std::string& relativePath, const std::string& relativeTo = File::currentWorkingDir());
00251
00257 #ifdef __APPLE__
00258 static std::string resourcePath(const std::string& fileName = "", const std::string& subdirectory = "");
00265 #endif
00266
00267 VRS_TYPEINFO(File, SharedObj);
00268
00269 private:
00270 class Impl;
00271 SO<Impl> impl_;
00272 WriteMode writeMode_;
00273
00274 static std::string initialWorkingDir_;
00275 };
00276
00277 }
00278
00279 #endif // VRS_IO_FILE_H