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