X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_file.hpp;h=0c176aabe652c4699a707da6f475ba9973c34372;hb=HEAD;hp=4b1b70ddad6f6bd886ac7aa51c28f5604b281faf;hpb=ae2b4d32ed56e3ac193cc7205aeb58082c448ce8;p=apitrace diff --git a/common/trace_file.hpp b/common/trace_file.hpp index 4b1b70d..0c176aa 100644 --- a/common/trace_file.hpp +++ b/common/trace_file.hpp @@ -31,7 +31,12 @@ #include #include -namespace Trace { + +#define SNAPPY_BYTE1 'a' +#define SNAPPY_BYTE2 't' + + +namespace trace { class File { public: @@ -49,8 +54,10 @@ public: }; public: - static bool isZLibCompressed(const std::string &filename); - static bool isSnappyCompressed(const std::string &filename); + static File *createZLib(void); + static File *createSnappy(void); + static File *createForRead(const char *filename); + static File *createForWrite(const char *filename); public: File(const std::string &filename = std::string(), File::Mode mode = File::Read); @@ -61,7 +68,7 @@ public: bool open(const std::string &filename, File::Mode mode); bool write(const void *buffer, size_t length); - bool read(void *buffer, size_t length); + size_t read(void *buffer, size_t length); void close(); void flush(void); int getc(); @@ -74,7 +81,7 @@ public: protected: virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0; virtual bool rawWrite(const void *buffer, size_t length) = 0; - virtual bool rawRead(void *buffer, size_t length) = 0; + virtual size_t rawRead(void *buffer, size_t length) = 0; virtual int rawGetc() = 0; virtual void rawClose() = 0; virtual void rawFlush() = 0; @@ -115,10 +122,10 @@ inline bool File::write(const void *buffer, size_t length) return rawWrite(buffer, length); } -inline bool File::read(void *buffer, size_t length) +inline size_t File::read(void *buffer, size_t length) { if (!m_isOpened || m_mode != File::Read) { - return false; + return 0; } return rawRead(buffer, length); } @@ -162,28 +169,6 @@ inline bool File::skip(size_t length) return rawSkip(length); } -class ZLibFile : public File { -public: - ZLibFile(const std::string &filename = std::string(), - File::Mode mode = File::Read); - virtual ~ZLibFile(); - - - virtual bool supportsOffsets() const; - virtual File::Offset currentOffset(); -protected: - virtual bool rawOpen(const std::string &filename, File::Mode mode); - virtual bool rawWrite(const void *buffer, size_t length); - virtual bool rawRead(void *buffer, size_t length); - virtual int rawGetc(); - virtual void rawClose(); - virtual void rawFlush(); - virtual bool rawSkip(size_t length); - virtual int rawPercentRead(); -private: - void *m_gzFile; - double m_endOffset; -}; inline bool operator<(const File::Offset &one, const File::Offset &two) @@ -219,6 +204,6 @@ operator<=(const File::Offset &one, const File::Offset &two) } -} +} /* namespace trace */ #endif