Ignore:
Timestamp:
01/15/15 22:43:01 (9 years ago)
Author:
Maciej Komosinski
Message:

Reorganizations and extensions of directory/file/filesystem IO classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/virtfile/virtfile.h

    r286 r295  
    99#include <stdarg.h>
    1010#include <common/nonstd_dir.h>
     11#include <string>
     12using std::string;
    1113//#include <dirent.h> //to jest inkludowane przez powyzsze
    1214//struct dirent; //kiedys byla ta linia jak nie bylo jeszcze implementacji windowsowej dirent, ale borlandowi sie nie podoba jak s¹ obie
     
    2224class DLLEXP VirtFILE
    2325{
     26  protected:
     27string path;
    2428  public:
    2529virtual size_t Vread(void *ptr, size_t size, size_t nmemb)=0;
     
    3640virtual int Vprintf(const char *format, va_list args);
    3741int printf(const char *format, ...);
    38 virtual const char *VgetPath() {return 0;} // 0=unspecified path
     42virtual const char *VgetPath() {return path.c_str();}
    3943virtual int getSize();
     44VirtFILE(const char* _path):path(_path) {}
    4045virtual ~VirtFILE();
    4146static VirtFILE *Vstdin,*Vstdout,*Vstderr;
     
    4853static VirtFileSystem *vfs;
    4954static 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 */
     58class DLLEXP DelegatedFILE: public VirtFILE
     59{
     60VirtFILE *delegate;
     61  public:
     62size_t Vread(void *ptr, size_t size, size_t nmemb) {return delegate->Vread(ptr,size,nmemb);}
     63size_t Vwrite(const void *ptr, size_t size, size_t nmemb) {return delegate->Vwrite(ptr,size,nmemb);}
     64int Veof() {return delegate->Veof();}
     65int Vputc(int c) {return delegate->Vputc(c);}
     66int Vputs(const char *s) {return delegate->Vputs(s);}
     67int Vgetc() {return delegate->Vgetc();}
     68int Vseek(long offset, int whence) {return delegate->Vseek(offset,whence);}
     69long Vtell() {return delegate->Vtell();}
     70void Vrewind() {delegate->Vrewind();}
     71int Vflush() {return delegate->Vflush();}
     72char *Vgets(char *s, int size) {return delegate->Vgets(s,size);}
     73int Vprintf(const char *format, va_list args) {return delegate->Vprintf(format,args);}
     74int getSize() {return delegate->getSize();}
     75// not overriden: VgetPath()
     76
     77DelegatedFILE(const char* _path,VirtFILE *_delegate):VirtFILE(_path),delegate(_delegate) {}
     78virtual ~DelegatedFILE() {if (delegate) delete delegate; delegate=NULL;}
    5079};
    5180
     
    6190public:
    6291virtual VirtFILE *Vfopen(const char* path,const char*mode);
    63 virtual int Vfexists(const char* path);
     92virtual bool Vfexists(const char* path);
    6493virtual VirtDIR *Vopendir(const char* path);
     94virtual bool Vmkdir(const char* path);
     95virtual bool Vmkdirs(const char* path);
     96virtual bool Vdirexists(const char* path,bool is_writable);
    6597};
     98
     99/// base class for chained filesystems - redirect unimplemented calls -> chain
     100class DLLEXP ChainFileSystem : public VirtFileSystem
     101{
     102public:
     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
    66113
    67114DLLEXP VirtFILE *Vfopen(const char* path,const char*mode);
    68115DLLEXP VirtDIR *Vopendir(const char* path);
    69 DLLEXP int Vfexists(const char* path);
     116DLLEXP bool Vfexists(const char* path);
     117DLLEXP bool Vmkdir(const char* path);
     118DLLEXP bool Vmkdirs(const char* path);
     119DLLEXP bool Vdirexists(const char* path,bool is_writable);
    70120
    71121DLLEXP int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f);
Note: See TracChangeset for help on using the changeset viewer.