source: cpp/frams/virtfile/stdiofile.h @ 324

Last change on this file since 324 was 299, checked in by Maciej Komosinski, 10 years ago

Instead of linking with stdiofile-autoinit.cpp, create an object StdioFileSystem_autoselect stdiofilesys;

  • Property svn:eol-style set to native
File size: 3.1 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
[109]4
5#ifndef _STDIOFILE_H_
6#define _STDIOFILE_H_
7
8#include "virtfile.h"
[206]9#include <common/nonstd_stdio.h>
[109]10#include <common/nonstd_dir.h>
11
[281]12class StdioFileSystem : public VirtFileSystem
[109]13{
14public:
[281]15        VirtFILE *Vfopen(const char *path, const char *mode);
[295]16        bool Vfexists(const char* path);
[281]17        VirtDIR *Vopendir(const char* path);
[295]18        bool Vmkdir(const char* path) { return makeDirectory(path); }
19        bool Vdirexists(const char* path,bool is_writable) { return directoryExists(path,is_writable); }
[109]20};
21
[206]22#ifdef USE_MFILE
[281]23class StdioFILE : public VirtFILE
[109]24{
[281]25protected:
26        MFILE *file;
27public:
[295]28        StdioFILE(MFILE *f):VirtFILE("") { file = f; }
[296]29        StdioFILE(MFILE *f, const char* p):VirtFILE(p) { file = f; }
[281]30        static void setStdio();
31        size_t Vread(void *ptr, size_t size, size_t nmemb) { return mfread(ptr, size, nmemb, file); }
32        size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return mfwrite(ptr, size, nmemb, file); }
33        int Veof() { return mfeof(file); }
34        int Vputs(const char *s) { return mfputs(s, file); }
35        char *Vgets(char *s, int size) { return mfgets(s, size, file); }
36        int Vseek(long offset, int whence) { return mfseek(file, offset, whence); }
37        long Vtell() { return mftell(file); }
38        int Vflush() { return 0; /*NOT IMPLEMENTED!*/ }
[206]39
[281]40        ~StdioFILE() { if (file) mfclose(file); }
[206]41};
42#else
[281]43class StdioFILE : public VirtFILE
[206]44{
[281]45protected:
46        FILE *file;
47public:
[295]48        StdioFILE(FILE *f):VirtFILE("") { file = f; }
[296]49        StdioFILE(FILE *f, const char* p):VirtFILE(p) { file = f; }
[281]50        static void setStdio();
51        size_t Vread(void *ptr, size_t size, size_t nmemb) { return fread(ptr, size, nmemb, file); }
52        size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return fwrite(ptr, size, nmemb, file); }
53        int Veof() { return feof(file); }
54        int Vputc(int c) { return fputc(c, file); }
55        int Vputs(const char *s) { return fputs(s, file); }
56        int Vgetc() { return fgetc(file); }
57        char *Vgets(char *s, int size) { return fgets(s, size, file); }
58        int Vprintf(const char *format, va_list args) { return vfprintf(file, format, args); }
59        int Vseek(long offset, int whence) { return fseek(file, offset, whence); }
60        long Vtell() { return ftell(file); }
61        void Vrewind() { rewind(file); }
62        int Vflush() { return fflush(file); }
[109]63
[281]64        ~StdioFILE() { if (file) fclose(file); }
[109]65};
[206]66#endif
[109]67
[281]68
69#ifdef _WIN32
70#ifdef __BORLANDC__
71 typedef wDIR DIRTYPE;
72#else
73 typedef WDIR DIRTYPE;
74#endif
75#else
76 typedef DIR DIRTYPE;
77#endif
78
79class StdioDIR : public VirtDIR
[109]80{
[281]81        DIRTYPE *dir;
82#ifdef _WIN32
83        dirent de; //only used to convert wide string names (wdirent) to utf8 (dirent)
84#endif
85public:
86        StdioDIR(DIRTYPE *d) : dir(d) {}
87        ~StdioDIR()
88        {
89#ifdef _WIN32
90                if (dir) wclosedir(dir);
91#else
92                if (dir) closedir(dir);
93#endif
94        }
95        dirent* Vreaddir();
[109]96};
97
[281]98class StdioFILEDontClose : public StdioFILE
[109]99{
[281]100public:
[206]101#ifdef USE_MFILE
[281]102        StdioFILEDontClose(MFILE *f) : StdioFILE(f) {}
[206]103#else
[281]104        StdioFILEDontClose(FILE *f) : StdioFILE(f) {}
[206]105#endif
[281]106        ~StdioFILEDontClose() { file = 0; }
[109]107};
108
[299]109class StdioFileSystem_autoselect: public StdioFileSystem
110{
111public:
112StdioFileSystem_autoselect()
113        {
114        VirtFILE::selectFileSystem(this);
115        }
116};
117
[109]118#endif
Note: See TracBrowser for help on using the repository browser.