/usr/include/zim/fstream.h is in libzim-dev 1.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | /*
* Copyright (C) 2010 Tommi Maekitalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
* NON-INFRINGEMENT. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef ZIM_FSTREAM_H
#define ZIM_FSTREAM_H
#include <iostream>
#include <vector>
#include <zim/zim.h>
#include <zim/smartptr.h>
#include <zim/cache.h>
#include <zim/refcounted.h>
namespace zim
{
class streambuf : public std::streambuf
{
struct FileInfo : public RefCounted
{
std::string fname;
zim::offset_type fsize;
FileInfo() { }
FileInfo(const std::string& fname_, int fd);
};
struct OpenfileInfo : public RefCounted
{
std::string fname;
int fd;
explicit OpenfileInfo(const std::string& fname);
~OpenfileInfo();
};
typedef SmartPtr<FileInfo> FileInfoPtr;
typedef std::vector<FileInfoPtr> FilesType;
typedef SmartPtr<OpenfileInfo> OpenfileInfoPtr;
typedef Cache<std::string, OpenfileInfoPtr> OpenFilesCacheType;
std::vector<char> buffer;
FilesType files;
OpenFilesCacheType openFilesCache;
OpenfileInfoPtr currentFile;
zim::offset_type currentPos;
std::streambuf::int_type overflow(std::streambuf::int_type ch);
std::streambuf::int_type underflow();
int sync();
void setCurrentFile(const std::string& fname, zim::offset_type off);
mutable time_t mtime;
public:
streambuf(const std::string& fname, unsigned bufsize, unsigned openFilesCache);
void seekg(zim::offset_type off);
void setBufsize(unsigned s)
{ buffer.resize(s); }
zim::offset_type fsize() const;
time_t getMTime() const;
};
class ifstream : public std::istream
{
streambuf myStreambuf;
public:
explicit ifstream(const std::string& fname, unsigned bufsize = 8192, unsigned openFilesCache = 5)
: std::istream(0),
myStreambuf(fname, bufsize, openFilesCache)
{
init(&myStreambuf);
}
void seekg(zim::offset_type off) { myStreambuf.seekg(off); }
void setBufsize(unsigned s) { myStreambuf.setBufsize(s); }
zim::offset_type fsize() const { return myStreambuf.fsize(); }
time_t getMTime() const { return myStreambuf.getMTime(); }
};
}
#endif // ZIM_FSTREAM_H
|