]> git.cworth.org Git - apitrace/blob - trace_file.hpp
Export SnappyFile class to its own file.
[apitrace] / trace_file.hpp
1 #ifndef TRACE_FILE_HPP
2 #define TRACE_FILE_HPP
3
4 #include <string>
5 #include <fstream>
6
7 namespace Trace {
8
9 class File {
10 public:
11     enum Mode {
12         Read,
13         Write
14     };
15     enum FlushType {
16         FlushShallow,
17         FlushDeep
18     };
19 public:
20     static bool isZLibCompressed(const std::string &filename);
21     static bool isSnappyCompressed(const std::string &filename);
22 public:
23     File(const std::string &filename = std::string(),
24          File::Mode mode = File::Read);
25     virtual ~File();
26
27     bool isOpened() const;
28     File::Mode mode() const;
29     std::string filename() const;
30
31     bool open(const std::string &filename, File::Mode mode);
32     bool write(const void *buffer, int length);
33     bool read(void *buffer, int length);
34     void close();
35     void flush(FlushType type = FlushShallow);
36     int getc();
37
38 protected:
39     virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0;
40     virtual bool rawWrite(const void *buffer, int length) = 0;
41     virtual bool rawRead(void *buffer, int length) = 0;
42     virtual int rawGetc() = 0;
43     virtual void rawClose() = 0;
44     virtual void rawFlush(FlushType type) = 0;
45
46 protected:
47     std::string m_filename;
48     File::Mode m_mode;
49     bool m_isOpened;
50 };
51
52 class ZLibFile : public File {
53 public:
54     ZLibFile(const std::string &filename = std::string(),
55              File::Mode mode = File::Read);
56     virtual ~ZLibFile();
57
58 protected:
59     virtual bool rawOpen(const std::string &filename, File::Mode mode);
60     virtual bool rawWrite(const void *buffer, int length);
61     virtual bool rawRead(void *buffer, int length);
62     virtual int rawGetc();
63     virtual void rawClose();
64     virtual void rawFlush(FlushType type);
65 private:
66     void *m_gzFile;
67 };
68
69 }
70
71 #endif