[121] | 1 | // This file is a part of the Framsticks GDK. |
---|
| 2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
| 3 | // Refer to http://www.framsticks.com/ for further information. |
---|
| 4 | |
---|
[109] | 5 | #ifndef _STRINGFILE_H_ |
---|
| 6 | #define _STRINGFILE_H_ |
---|
| 7 | |
---|
| 8 | #include "virtfile.h" |
---|
| 9 | #include <frams/util/sstring.h> |
---|
| 10 | |
---|
| 11 | class StringFILE: public VirtFILE |
---|
| 12 | { |
---|
| 13 | protected: |
---|
| 14 | SString& str; |
---|
| 15 | long pos; |
---|
| 16 | public: |
---|
| 17 | StringFILE(SString& s):str(s),pos(0) {} |
---|
| 18 | int Vread(void *ptr, size_t size, size_t nmemb); |
---|
| 19 | int Vwrite(const void *ptr, size_t size, size_t nmemb) {str.append((const char*)ptr,size*nmemb); return size*nmemb;} |
---|
| 20 | int Veof() {return pos>=str.len();} |
---|
| 21 | int Vputc(int c) {str+=(char)c; return c;} |
---|
| 22 | int Vputs(const char *s) {str.append(s,strlen(s)); return 0;} |
---|
| 23 | int Vgetc(); |
---|
| 24 | char *Vgets(char *s, int size); |
---|
| 25 | int Vprintf(const char *format, va_list args); |
---|
| 26 | int Vseek(long offset, int whence); |
---|
| 27 | int Vtell() {return pos;} |
---|
| 28 | void Vrewind() {pos=0;} |
---|
| 29 | int Vflush() {return 0;} |
---|
| 30 | }; |
---|
| 31 | |
---|
| 32 | /** this version owns the string object */ |
---|
| 33 | class StringFILE2: public StringFILE |
---|
| 34 | { |
---|
| 35 | SString string; |
---|
| 36 | public: |
---|
| 37 | StringFILE2(const SString& s):StringFILE(string),string(s) {} |
---|
| 38 | StringFILE2():StringFILE(string) {} |
---|
| 39 | const SString& getString() {return string;} |
---|
| 40 | }; |
---|
| 41 | |
---|
| 42 | class StringFileSystem: public VirtFileSystem |
---|
| 43 | { |
---|
| 44 | public: |
---|
| 45 | VirtFileSystem *chain; |
---|
| 46 | StringFileSystem(VirtFileSystem *_chain):chain(_chain) {} |
---|
| 47 | VirtFILE *Vfopen(const char* path,const char*mode); |
---|
| 48 | int Vfexists(const char* path); |
---|
| 49 | VirtDIR *Vopendir(const char* path); |
---|
| 50 | static const char PREFIX[]; |
---|
| 51 | static bool isStringPath(const char* path); |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | #endif |
---|