20 static bool isZLibCompressed(const std::string &filename);
21 static bool isSnappyCompressed(const std::string &filename);
23 File(const std::string &filename = std::string(),
24 File::Mode mode = File::Read);
27 bool isOpened() const;
28 File::Mode mode() const;
30 std::string filename() const;
32 bool open(const std::string &filename, File::Mode mode);
33 bool write(const void *buffer, int length);
34 bool read(void *buffer, int length);
36 void flush(FlushType type = FlushShallow);
40 virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0;
41 virtual bool rawWrite(const void *buffer, int length) = 0;
42 virtual bool rawRead(void *buffer, int length) = 0;
43 virtual int rawGetc() = 0;
44 virtual void rawClose() = 0;
45 virtual void rawFlush(FlushType type) = 0;
48 std::string m_filename;
53 inline bool File::isOpened() const
58 inline File::Mode File::mode() const
63 inline std::string File::filename() const
68 inline bool File::open(const std::string &filename, File::Mode mode)
73 m_isOpened = rawOpen(filename, mode);
79 inline bool File::write(const void *buffer, int length)
81 if (!m_isOpened || m_mode != File::Write) {
84 return rawWrite(buffer, length);
87 inline bool File::read(void *buffer, int length)
89 if (!m_isOpened || m_mode != File::Read) {
92 return rawRead(buffer, length);
95 inline void File::close()
103 inline void File::flush(File::FlushType type)
108 inline int File::getc()
110 if (!m_isOpened || m_mode != File::Read) {
116 class ZLibFile : public File {
118 ZLibFile(const std::string &filename = std::string(),
119 File::Mode mode = File::Read);
123 virtual bool rawOpen(const std::string &filename, File::Mode mode);
124 virtual bool rawWrite(const void *buffer, int length);
125 virtual bool rawRead(void *buffer, int length);
126 virtual int rawGetc();
127 virtual void rawClose();
128 virtual void rawFlush(FlushType type);