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. |
---|
4 | |
---|
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 | size_t Vread(void *ptr, size_t size, size_t nmemb); |
---|
19 | size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { str.append((const char*)ptr, (int)(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, (int)strlen(s)); return 0; } |
---|
23 | int Vgetc(); |
---|
24 | char *Vgets(char *s, int size); |
---|
25 | int Vseek(long offset, int whence); |
---|
26 | long Vtell() { return pos; } |
---|
27 | int Vflush() { return 0; } |
---|
28 | }; |
---|
29 | |
---|
30 | /** this version owns the string object */ |
---|
31 | class StringFILE2 : public StringFILE |
---|
32 | { |
---|
33 | SString string; |
---|
34 | public: |
---|
35 | StringFILE2(const SString& s) :StringFILE(string), string(s) {} |
---|
36 | StringFILE2() :StringFILE(string) {} |
---|
37 | const SString& getString() { return string; } |
---|
38 | }; |
---|
39 | |
---|
40 | class StringFileSystem : public VirtFileSystem |
---|
41 | { |
---|
42 | public: |
---|
43 | VirtFileSystem *chain; |
---|
44 | StringFileSystem(VirtFileSystem *_chain = NULL) :chain(_chain) {} |
---|
45 | VirtFILE *Vfopen(const char* path, const char*mode); |
---|
46 | int Vfexists(const char* path); |
---|
47 | VirtDIR *Vopendir(const char* path); |
---|
48 | static const char PREFIX[]; |
---|
49 | static bool isStringPath(const char* path); |
---|
50 | }; |
---|
51 | |
---|
52 | #endif |
---|