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