source: cpp/gdk/stdiofile.h @ 50

Last change on this file since 50 was 5, checked in by sz, 16 years ago

added the GDK (Genotype Development Kit)

File size: 1.7 KB
Line 
1// This file is a part of Framsticks GDK library.
2// Copyright (C) 2002-2006  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.frams.alife.pl/ for further information.
4
5#ifndef _STDIOFILE_H_
6#define _STDIOFILE_H_
7
8#include "virtfile.h"
9#include "sstring.h"
10#include <stdio.h>
11#ifndef _MSC_VER
12#include <dirent.h>
13#endif
14
15class StdioFileSystem: public VirtFileSystem
16{
17public:
18VirtFILE *Vfopen(const char* path,const char*mode);
19int Vfexists(const char* path);
20VirtDIR *Vopendir(const char* path);
21};
22
23class StdioFILE: public VirtFILE
24{
25  protected:
26FILE *file;
27SString path;
28  public:
29StdioFILE(FILE *f) {file=f;}
30StdioFILE(FILE *f,const SString& p) {file=f;path=p;}
31static void setStdio();
32int Vread(void *ptr, size_t size, size_t nmemb) {return fread(ptr,size,nmemb,file);}
33int Vwrite(const void *ptr, size_t size, size_t nmemb) {return fwrite(ptr,size,nmemb,file);}
34int Veof() {return feof(file);}
35int Vputc(int c) {return fputc(c,file);}
36int Vputs(const char *s) {return fputs(s,file);}
37int Vgetc() {return fgetc(file);}
38char *Vgets(char *s, int size) {return fgets(s,size,file);}
39int Vprintf(const char *format, va_list args) { return vfprintf(file,format,args); }
40int Vseek(long offset, int whence) {return fseek(file,offset,whence);}
41int Vtell() {return ftell(file);}
42void Vrewind() {rewind(file);}
43int Vflush() {return fflush(file);}
44const char* VgetPath() {return path;}
45
46~StdioFILE() {if (file) fclose(file);}
47};
48
49class StdioDIR: public VirtDIR
50{
51#ifndef _MSC_VER
52DIR *dir;
53  public:
54StdioDIR(DIR* d):dir(d) {}
55~StdioDIR() {if (dir) closedir(dir);}
56dirent* Vreaddir();
57#endif
58};
59
60class StdioFILEDontClose: public StdioFILE
61{
62  public:
63StdioFILEDontClose(FILE *f):StdioFILE(f) {}
64~StdioFILEDontClose() {file=0;}
65};
66
67#endif
Note: See TracBrowser for help on using the repository browser.