- Timestamp:
- 01/15/15 22:43:01 (10 years ago)
- Location:
- cpp/frams/virtfile
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/virtfile/stdiofile.cpp
r293 r295 37 37 } 38 38 39 intStdioFileSystem::Vfexists(const char* path)39 bool StdioFileSystem::Vfexists(const char* path) 40 40 { 41 41 return fileExists(path); -
cpp/frams/virtfile/stdiofile.h
r286 r295 8 8 #include "virtfile.h" 9 9 #include <frams/util/sstring.h> 10 #ifdef USE_MFILE11 10 #include <common/nonstd_stdio.h> 12 #else13 #include <stdio.h>14 #endif15 11 #include <common/nonstd_dir.h> 16 12 … … 19 15 public: 20 16 VirtFILE *Vfopen(const char *path, const char *mode); 21 intVfexists(const char* path);17 bool Vfexists(const char* path); 22 18 VirtDIR *Vopendir(const char* path); 19 bool Vmkdir(const char* path) { return makeDirectory(path); } 20 bool Vdirexists(const char* path,bool is_writable) { return directoryExists(path,is_writable); } 23 21 }; 24 22 … … 28 26 protected: 29 27 MFILE *file; 30 SString path;31 28 public: 32 StdioFILE(MFILE *f) { file = f; }33 StdioFILE(MFILE *f, const SString& p) { file = f; path = p; }29 StdioFILE(MFILE *f):VirtFILE("") { file = f; } 30 StdioFILE(MFILE *f, const SString& p):VirtFILE(p) { file = f; } 34 31 static void setStdio(); 35 32 size_t Vread(void *ptr, size_t size, size_t nmemb) { return mfread(ptr, size, nmemb, file); } … … 41 38 long Vtell() { return mftell(file); } 42 39 int Vflush() { return 0; /*NOT IMPLEMENTED!*/ } 43 const char* VgetPath() { return path; }44 40 45 41 ~StdioFILE() { if (file) mfclose(file); } … … 50 46 protected: 51 47 FILE *file; 52 SString path;53 48 public: 54 StdioFILE(FILE *f) { file = f; }55 StdioFILE(FILE *f, const SString& p) { file = f; path = p; }49 StdioFILE(FILE *f):VirtFILE("") { file = f; } 50 StdioFILE(FILE *f, const SString& p):VirtFILE(p) { file = f; } 56 51 static void setStdio(); 57 52 size_t Vread(void *ptr, size_t size, size_t nmemb) { return fread(ptr, size, nmemb, file); } … … 67 62 void Vrewind() { rewind(file); } 68 63 int Vflush() { return fflush(file); } 69 const char* VgetPath() { return path; }70 64 71 65 ~StdioFILE() { if (file) fclose(file); } -
cpp/frams/virtfile/stringfile.cpp
r286 r295 71 71 return (chain != NULL) ? chain->Vfopen(path, mode) : NULL; 72 72 } 73 74 int StringFileSystem::Vfexists(const char* path)75 {76 return (chain != NULL) ? chain->Vfexists(path) : 0;77 }78 79 VirtDIR *StringFileSystem::Vopendir(const char* path)80 {81 return (chain != NULL) ? chain->Vopendir(path) : NULL;82 } -
cpp/frams/virtfile/stringfile.h
r286 r295 15 15 long pos; 16 16 public: 17 StringFILE(SString& s) :str(s), pos(0) {}17 StringFILE(SString& s): VirtFILE(""), str(s), pos(0) {} 18 18 size_t Vread(void *ptr, size_t size, size_t nmemb); 19 19 size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { str.append((const char*)ptr, (int)(size*nmemb)); return size*nmemb; } … … 38 38 }; 39 39 40 class StringFileSystem : public VirtFileSystem40 class StringFileSystem : public ChainFileSystem 41 41 { 42 42 public: 43 VirtFileSystem *chain; 44 StringFileSystem(VirtFileSystem *_chain = NULL) :chain(_chain) {} 43 StringFileSystem(VirtFileSystem *_chain = NULL):ChainFileSystem(_chain) {} 45 44 VirtFILE *Vfopen(const char* path, const char*mode); 46 int Vfexists(const char* path);47 VirtDIR *Vopendir(const char* path);48 45 static const char PREFIX[]; 49 46 static bool isStringPath(const char* path); -
cpp/frams/virtfile/virtfile.cpp
r286 r295 22 22 } 23 23 24 intVfexists(const char* path)24 bool Vfexists(const char* path) 25 25 { 26 return VirtFILE::vfs ? VirtFILE::vfs->Vfexists(path) : 0; 26 return VirtFILE::vfs ? VirtFILE::vfs->Vfexists(path) : false; 27 } 28 29 bool Vdirexists(const char* path,bool is_writable) 30 { 31 return VirtFILE::vfs ? VirtFILE::vfs->Vdirexists(path,is_writable) : false; 32 } 33 34 bool Vmkdir(const char* path) 35 { 36 return VirtFILE::vfs ? VirtFILE::vfs->Vmkdir(path) : false; 37 } 38 39 bool Vmkdirs(const char* path) 40 { 41 return VirtFILE::vfs ? VirtFILE::vfs->Vmkdirs(path) : false; 27 42 } 28 43 … … 65 80 66 81 VirtFILE* VirtFileSystem::Vfopen(const char* path,const char*mode) {return 0;} 67 intVirtFileSystem::Vfexists(const char* path) {return 0;}82 bool VirtFileSystem::Vfexists(const char* path) {return 0;} 68 83 VirtDIR* VirtFileSystem::Vopendir(const char* path) {return 0;} 84 bool VirtFileSystem::Vmkdir(const char* path) {return false;} //error - not supported 85 bool VirtFileSystem::Vdirexists(const char* path,bool is_writable) {return false;} 69 86 70 87 ////////////////////////////////////////////////////////////////////////// … … 117 134 dirent* readdir(VirtDIR* d) {return d->Vreaddir();} 118 135 136 ///////// 137 138 bool VirtFileSystem::Vmkdirs(const char* path) 139 { 140 if (Vdirexists(path,true)) return true; 141 string parentdir = getFileDir(path); 142 if (!Vmkdirs(parentdir.c_str())) return false; 143 return Vmkdir(path); 144 } 145 146 ////////// 147 148 VirtFILE *ChainFileSystem::Vfopen(const char* path, const char*mode) 149 { 150 return (chain != NULL) ? chain->Vfopen(path, mode) : NULL; 151 } 152 153 bool ChainFileSystem::Vfexists(const char* path) 154 { 155 return (chain != NULL) ? chain->Vfexists(path) : false; 156 } 157 158 VirtDIR *ChainFileSystem::Vopendir(const char* path) 159 { 160 return (chain != NULL) ? chain->Vopendir(path) : NULL; 161 } 162 163 bool ChainFileSystem::Vmkdir(const char* path) 164 { 165 return (chain != NULL) ? chain->Vmkdir(path) : false; 166 } 167 168 bool ChainFileSystem::Vmkdirs(const char* path) 169 { 170 return (chain != NULL) ? chain->Vmkdirs(path) : false; 171 } 172 173 bool ChainFileSystem::Vdirexists(const char* path,bool is_writable) 174 { 175 return (chain != NULL) ? chain->Vdirexists(path,is_writable) : false; 176 } -
cpp/frams/virtfile/virtfile.h
r286 r295 9 9 #include <stdarg.h> 10 10 #include <common/nonstd_dir.h> 11 #include <string> 12 using std::string; 11 13 //#include <dirent.h> //to jest inkludowane przez powyzsze 12 14 //struct dirent; //kiedys byla ta linia jak nie bylo jeszcze implementacji windowsowej dirent, ale borlandowi sie nie podoba jak s¹ obie … … 22 24 class DLLEXP VirtFILE 23 25 { 26 protected: 27 string path; 24 28 public: 25 29 virtual size_t Vread(void *ptr, size_t size, size_t nmemb)=0; … … 36 40 virtual int Vprintf(const char *format, va_list args); 37 41 int printf(const char *format, ...); 38 virtual const char *VgetPath() {return 0;} // 0=unspecified path42 virtual const char *VgetPath() {return path.c_str();} 39 43 virtual int getSize(); 44 VirtFILE(const char* _path):path(_path) {} 40 45 virtual ~VirtFILE(); 41 46 static VirtFILE *Vstdin,*Vstdout,*Vstderr; … … 48 53 static VirtFileSystem *vfs; 49 54 static void selectFileSystem(VirtFileSystem *s); 55 }; 56 57 /** can be used directly or as a base class for implementations delegating VirtFILE calls to another VirtFILE object */ 58 class DLLEXP DelegatedFILE: public VirtFILE 59 { 60 VirtFILE *delegate; 61 public: 62 size_t Vread(void *ptr, size_t size, size_t nmemb) {return delegate->Vread(ptr,size,nmemb);} 63 size_t Vwrite(const void *ptr, size_t size, size_t nmemb) {return delegate->Vwrite(ptr,size,nmemb);} 64 int Veof() {return delegate->Veof();} 65 int Vputc(int c) {return delegate->Vputc(c);} 66 int Vputs(const char *s) {return delegate->Vputs(s);} 67 int Vgetc() {return delegate->Vgetc();} 68 int Vseek(long offset, int whence) {return delegate->Vseek(offset,whence);} 69 long Vtell() {return delegate->Vtell();} 70 void Vrewind() {delegate->Vrewind();} 71 int Vflush() {return delegate->Vflush();} 72 char *Vgets(char *s, int size) {return delegate->Vgets(s,size);} 73 int Vprintf(const char *format, va_list args) {return delegate->Vprintf(format,args);} 74 int getSize() {return delegate->getSize();} 75 // not overriden: VgetPath() 76 77 DelegatedFILE(const char* _path,VirtFILE *_delegate):VirtFILE(_path),delegate(_delegate) {} 78 virtual ~DelegatedFILE() {if (delegate) delete delegate; delegate=NULL;} 50 79 }; 51 80 … … 61 90 public: 62 91 virtual VirtFILE *Vfopen(const char* path,const char*mode); 63 virtual intVfexists(const char* path);92 virtual bool Vfexists(const char* path); 64 93 virtual VirtDIR *Vopendir(const char* path); 94 virtual bool Vmkdir(const char* path); 95 virtual bool Vmkdirs(const char* path); 96 virtual bool Vdirexists(const char* path,bool is_writable); 65 97 }; 98 99 /// base class for chained filesystems - redirect unimplemented calls -> chain 100 class DLLEXP ChainFileSystem : public VirtFileSystem 101 { 102 public: 103 VirtFileSystem *chain; 104 ChainFileSystem(VirtFileSystem *_chain = NULL) :chain(_chain) {} 105 VirtFILE *Vfopen(const char* path, const char*mode); 106 bool Vfexists(const char* path); 107 VirtDIR *Vopendir(const char* path); 108 bool Vmkdir(const char* path); 109 bool Vmkdirs(const char* path); 110 bool Vdirexists(const char* path,bool is_writable); 111 }; 112 66 113 67 114 DLLEXP VirtFILE *Vfopen(const char* path,const char*mode); 68 115 DLLEXP VirtDIR *Vopendir(const char* path); 69 DLLEXP int Vfexists(const char* path); 116 DLLEXP bool Vfexists(const char* path); 117 DLLEXP bool Vmkdir(const char* path); 118 DLLEXP bool Vmkdirs(const char* path); 119 DLLEXP bool Vdirexists(const char* path,bool is_writable); 70 120 71 121 DLLEXP int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f);
Note: See TracChangeset
for help on using the changeset viewer.