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

Last change on this file since 109 was 109, checked in by sz, 8 years ago

source reorganization (see README)
new feature added: part/joint shapes (see frams/_demos/part_shapes.cpp)

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1#ifndef _STRINGFILE_H_
2#define _STRINGFILE_H_
3
4#include "virtfile.h"
5#include <frams/util/sstring.h>
6
7class StringFILE: public VirtFILE
8{
9  protected:
10SString& str;
11long pos;
12  public:
13StringFILE(SString& s):str(s),pos(0) {}
14int Vread(void *ptr, size_t size, size_t nmemb);
15int Vwrite(const void *ptr, size_t size, size_t nmemb) {str.append((const char*)ptr,size*nmemb); return size*nmemb;}
16int Veof() {return pos>=str.len();}
17int Vputc(int c) {str+=(char)c; return c;}
18int Vputs(const char *s) {str.append(s,strlen(s)); return 0;}
19int Vgetc();
20char *Vgets(char *s, int size);
21int Vprintf(const char *format, va_list args);
22int Vseek(long offset, int whence);
23int Vtell() {return pos;}
24void Vrewind() {pos=0;}
25int Vflush() {return 0;}
26};
27
28/** this version owns the string object */
29class StringFILE2: public StringFILE
30{
31SString string;
32  public:
33StringFILE2(const SString& s):StringFILE(string),string(s) {}
34StringFILE2():StringFILE(string) {}
35const SString& getString() {return string;}
36};
37
38class StringFileSystem: public VirtFileSystem
39{
40  public:
41VirtFileSystem *chain;
42StringFileSystem(VirtFileSystem *_chain):chain(_chain) {}
43VirtFILE *Vfopen(const char* path,const char*mode);
44int Vfexists(const char* path);
45VirtDIR *Vopendir(const char* path);
46static const char PREFIX[];
47static bool isStringPath(const char* path);
48};
49
50#endif
Note: See TracBrowser for help on using the repository browser.