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

Last change on this file since 282 was 282, checked in by Maciej Komosinski, 9 years ago

Formatted source

  • Property svn:eol-style set to native
File size: 1.5 KB
RevLine 
[121]1// This file is a part of the Framsticks GDK.
[197]2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
[121]3// Refer to http://www.framsticks.com/ for further information.
4
[109]5#ifndef _STRINGFILE_H_
6#define _STRINGFILE_H_
7
8#include "virtfile.h"
9#include <frams/util/sstring.h>
10
[282]11class StringFILE : public VirtFILE
[109]12{
[282]13protected:
14        SString& str;
15        long pos;
16public:
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; }
[109]28};
29
30/** this version owns the string object */
[282]31class StringFILE2 : public StringFILE
[109]32{
[282]33        SString string;
34public:
35        StringFILE2(const SString& s) :StringFILE(string), string(s) {}
36        StringFILE2() :StringFILE(string) {}
37        const SString& getString() { return string; }
[109]38};
39
[282]40class StringFileSystem : public VirtFileSystem
[109]41{
[282]42public:
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);
[109]50};
51
52#endif
Note: See TracBrowser for help on using the repository browser.