Ignore:
Timestamp:
04/03/14 01:24:30 (11 years ago)
Author:
Maciej Komosinski
Message:

VirtFILE base class provides Vprintf, Vgetc, Vputc, Vrewind, so that subclasses do not have to implement these functions

File:
1 edited

Legend:

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

    r197 r206  
    88#include "virtfile.h"
    99#include <frams/util/sstring.h>
     10#ifdef USE_MFILE
     11#include <common/nonstd_stdio.h>
     12#else
    1013#include <stdio.h>
     14#endif
    1115#include <common/nonstd_dir.h>
    1216
     
    1923};
    2024
     25#ifdef USE_MFILE
     26class StdioFILE: public VirtFILE
     27{
     28  protected:
     29MFILE *file;
     30SString path;
     31  public:
     32StdioFILE(MFILE *f) {file=f;}
     33StdioFILE(MFILE *f,const SString& p) {file=f;path=p;}
     34static void setStdio();
     35int Vread(void *ptr, size_t size, size_t nmemb) {return mfread(ptr,size,nmemb,file);}
     36int Vwrite(const void *ptr, size_t size, size_t nmemb) {return mfwrite(ptr,size,nmemb,file);}
     37int Veof() {return mfeof(file);}
     38int Vputs(const char *s) {return mfputs(s,file);}
     39char *Vgets(char *s, int size) {return mfgets(s,size,file);}
     40int Vseek(long offset, int whence) {return mfseek(file,offset,whence);}
     41int Vtell() {return mftell(file);}
     42int Vflush() {return 0;/*NOT IMPLEMENTED!*/;}
     43const char* VgetPath() {return path;}
     44
     45~StdioFILE() {if (file) fclose(file);}
     46};
     47#else
    2148class StdioFILE: public VirtFILE
    2249{
     
    4471~StdioFILE() {if (file) fclose(file);}
    4572};
     73#endif
    4674
    4775class StdioDIR: public VirtDIR
     
    5785{
    5886  public:
     87#ifdef USE_MFILE
     88StdioFILEDontClose(MFILE *f):StdioFILE(f) {}
     89#else
    5990StdioFILEDontClose(FILE *f):StdioFILE(f) {}
     91#endif
    6092~StdioFILEDontClose() {file=0;}
    6193};
Note: See TracChangeset for help on using the changeset viewer.