source: cpp/common/virtfile/stringfile.h @ 932

Last change on this file since 932 was 887, checked in by Maciej Komosinski, 5 years ago

StringFILE::Vwrite() returns a proper value now as the standard requires

  • 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 <common/nonstd_stl.h>
10#include <string.h>
11
12class StringFILE : public VirtFILE
13{
14protected:
15        string& str;
16        int pos;
17public:
18        StringFILE(string& s,int _pos=0): VirtFILE(""), str(s), pos(_pos) {}
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 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        const string& getString() { return str; }
31};
32
33/** this version owns the string object */
34class StringFILE2 : public StringFILE
35{
36        string str;
37public:
38        StringFILE2(const string& s,int pos=0) :StringFILE(str,pos), str(s) {}
39        StringFILE2() :StringFILE(str) {}
40};
41
42class StringFileSystem : public ChainFileSystem
43{
44public:
45        StringFileSystem(VirtFileSystem *_chain = NULL):ChainFileSystem(_chain) {}
46        VirtFILE *Vfopen(const char* path, const char*mode);
47        static const char PREFIX[];
48        static bool isStringPath(const char* path);
49};
50
51#endif
Note: See TracBrowser for help on using the repository browser.