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

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

Sources support both 32-bit and 64-bit, and more compilers

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
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{
13  protected:
14SString& str;
15long pos;
16  public:
17StringFILE(SString& s):str(s),pos(0) {}
18size_t Vread(void *ptr, size_t size, size_t nmemb);
19size_t Vwrite(const void *ptr, size_t size, size_t nmemb) {str.append((const char*)ptr,(int)(size*nmemb)); return size*nmemb;}
20int Veof() {return pos>=str.len();}
21int Vputc(int c) {str+=(char)c; return c;}
22int Vputs(const char *s) {str.append(s,(int)strlen(s)); return 0;}
23int Vgetc();
24char *Vgets(char *s, int size);
25int Vseek(long offset, int whence);
26long Vtell() {return pos;}
27int Vflush() {return 0;}
28};
29
30/** this version owns the string object */
31class StringFILE2: public StringFILE
32{
33SString string;
34  public:
35StringFILE2(const SString& s):StringFILE(string),string(s) {}
36StringFILE2():StringFILE(string) {}
37const SString& getString() {return string;}
38};
39
40class StringFileSystem: public VirtFileSystem
41{
42  public:
43VirtFileSystem *chain;
44StringFileSystem(VirtFileSystem *_chain=NULL):chain(_chain) {}
45VirtFILE *Vfopen(const char* path,const char*mode);
46int Vfexists(const char* path);
47VirtDIR *Vopendir(const char* path);
48static const char PREFIX[];
49static bool isStringPath(const char* path);
50};
51
52#endif
Note: See TracBrowser for help on using the repository browser.