[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. |
---|
[121] | 4 | |
---|
[109] | 5 | #ifndef _STRINGFILE_H_ |
---|
| 6 | #define _STRINGFILE_H_ |
---|
| 7 | |
---|
| 8 | #include "virtfile.h" |
---|
| 9 | #include <frams/util/sstring.h> |
---|
| 10 | |
---|
[282] | 11 | class StringFILE : public VirtFILE |
---|
[109] | 12 | { |
---|
[282] | 13 | protected: |
---|
| 14 | SString& str; |
---|
| 15 | long pos; |
---|
| 16 | public: |
---|
[295] | 17 | StringFILE(SString& s): VirtFILE(""), str(s), pos(0) {} |
---|
[282] | 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; } |
---|
[109] | 28 | }; |
---|
| 29 | |
---|
| 30 | /** this version owns the string object */ |
---|
[282] | 31 | class StringFILE2 : public StringFILE |
---|
[109] | 32 | { |
---|
[282] | 33 | SString string; |
---|
| 34 | public: |
---|
| 35 | StringFILE2(const SString& s) :StringFILE(string), string(s) {} |
---|
| 36 | StringFILE2() :StringFILE(string) {} |
---|
| 37 | const SString& getString() { return string; } |
---|
[109] | 38 | }; |
---|
| 39 | |
---|
[295] | 40 | class StringFileSystem : public ChainFileSystem |
---|
[109] | 41 | { |
---|
[282] | 42 | public: |
---|
[295] | 43 | StringFileSystem(VirtFileSystem *_chain = NULL):ChainFileSystem(_chain) {} |
---|
[282] | 44 | VirtFILE *Vfopen(const char* path, const char*mode); |
---|
| 45 | static const char PREFIX[]; |
---|
| 46 | static bool isStringPath(const char* path); |
---|
[109] | 47 | }; |
---|
| 48 | |
---|
| 49 | #endif |
---|