| 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 <common/nonstd_stl.h> |
|---|
| 10 | #include <string.h> |
|---|
| 11 | |
|---|
| 12 | class StringFILE : public VirtFILE |
|---|
| 13 | { |
|---|
| 14 | protected: |
|---|
| 15 | string& str; |
|---|
| 16 | int pos; |
|---|
| 17 | public: |
|---|
| 18 | StringFILE(string& s): VirtFILE(""), str(s), pos(0) {} |
|---|
| 19 | size_t Vread(void *ptr, size_t size, size_t nmemb); |
|---|
| 20 | size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { str.append((const char*)ptr, (int)(size*nmemb)); return size*nmemb; } |
|---|
| 21 | int Veof() { return pos >= int(str.size()); } |
|---|
| 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; } |
|---|
| 29 | }; |
|---|
| 30 | |
|---|
| 31 | /** this version owns the string object */ |
|---|
| 32 | class StringFILE2 : public StringFILE |
|---|
| 33 | { |
|---|
| 34 | string str; |
|---|
| 35 | public: |
|---|
| 36 | StringFILE2(const string& s) :StringFILE(str), str(s) {} |
|---|
| 37 | StringFILE2() :StringFILE(str) {} |
|---|
| 38 | const string& getString() { return str; } |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | class StringFileSystem : public ChainFileSystem |
|---|
| 42 | { |
|---|
| 43 | public: |
|---|
| 44 | StringFileSystem(VirtFileSystem *_chain = NULL):ChainFileSystem(_chain) {} |
|---|
| 45 | VirtFILE *Vfopen(const char* path, const char*mode); |
|---|
| 46 | static const char PREFIX[]; |
|---|
| 47 | static bool isStringPath(const char* path); |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | #endif |
|---|