source: cpp/frams/virtfile/stringfile.h @ 334

Last change on this file since 334 was 295, checked in by Maciej Komosinski, 10 years ago

Reorganizations and extensions of directory/file/filesystem IO classes

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
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
11class StringFILE : public VirtFILE
12{
13protected:
14        SString& str;
15        long pos;
16public:
17        StringFILE(SString& s): VirtFILE(""), 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 */
31class StringFILE2 : public StringFILE
32{
33        SString string;
34public:
35        StringFILE2(const SString& s) :StringFILE(string), string(s) {}
36        StringFILE2() :StringFILE(string) {}
37        const SString& getString() { return string; }
38};
39
40class StringFileSystem : public ChainFileSystem
41{
42public:
43        StringFileSystem(VirtFileSystem *_chain = NULL):ChainFileSystem(_chain) {}
44        VirtFILE *Vfopen(const char* path, const char*mode);
45        static const char PREFIX[];
46        static bool isStringPath(const char* path);
47};
48
49#endif
Note: See TracBrowser for help on using the repository browser.