diff options
Diffstat (limited to 'common/trace_file.hpp')
-rw-r--r-- | common/trace_file.hpp | 60 |
1 files changed, 10 insertions, 50 deletions
diff --git a/common/trace_file.hpp b/common/trace_file.hpp index 0c176aab..17e6756b 100644 --- a/common/trace_file.hpp +++ b/common/trace_file.hpp @@ -24,26 +24,17 @@ **************************************************************************/ -#ifndef TRACE_FILE_HPP -#define TRACE_FILE_HPP +#pragma once #include <string> #include <fstream> #include <stdint.h> -#define SNAPPY_BYTE1 'a' -#define SNAPPY_BYTE2 't' - - namespace trace { class File { public: - enum Mode { - Read, - Write - }; struct Offset { Offset(uint64_t _chunk = 0, uint32_t _offsetInChunk = 0) : chunk(_chunk), @@ -57,20 +48,15 @@ public: 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); + File(const std::string &filename = std::string()); virtual ~File(); bool isOpened() const; - File::Mode mode() const; - bool open(const std::string &filename, File::Mode mode); - bool write(const void *buffer, size_t length); + bool open(const std::string &filename); size_t read(void *buffer, size_t length); void close(); - void flush(void); int getc(); bool skip(size_t length); int percentRead(); @@ -79,17 +65,14 @@ public: virtual File::Offset currentOffset() = 0; virtual void setCurrentOffset(const File::Offset &offset); protected: - virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0; - virtual bool rawWrite(const void *buffer, size_t length) = 0; + virtual bool rawOpen(const std::string &filename) = 0; virtual size_t rawRead(void *buffer, size_t length) = 0; virtual int rawGetc() = 0; virtual void rawClose() = 0; - virtual void rawFlush() = 0; virtual bool rawSkip(size_t length) = 0; virtual int rawPercentRead() = 0; protected: - File::Mode m_mode; bool m_isOpened; }; @@ -98,33 +81,19 @@ inline bool File::isOpened() const return m_isOpened; } -inline File::Mode File::mode() const -{ - return m_mode; -} - -inline bool File::open(const std::string &filename, File::Mode mode) +inline bool File::open(const std::string &filename) { if (m_isOpened) { close(); } - m_isOpened = rawOpen(filename, mode); - m_mode = mode; + m_isOpened = rawOpen(filename); return m_isOpened; } -inline bool File::write(const void *buffer, size_t length) -{ - if (!m_isOpened || m_mode != File::Write) { - return false; - } - return rawWrite(buffer, length); -} - inline size_t File::read(void *buffer, size_t length) { - if (!m_isOpened || m_mode != File::Read) { + if (!m_isOpened) { return 0; } return rawRead(buffer, length); @@ -132,7 +101,7 @@ inline size_t File::read(void *buffer, size_t length) inline int File::percentRead() { - if (!m_isOpened || m_mode != File::Read) { + if (!m_isOpened) { return 0; } return rawPercentRead(); @@ -146,16 +115,9 @@ inline void File::close() } } -inline void File::flush(void) -{ - if (m_mode == File::Write) { - rawFlush(); - } -} - inline int File::getc() { - if (!m_isOpened || m_mode != File::Read) { + if (!m_isOpened) { return -1; } return rawGetc(); @@ -163,7 +125,7 @@ inline int File::getc() inline bool File::skip(size_t length) { - if (!m_isOpened || m_mode != File::Read) { + if (!m_isOpened) { return false; } return rawSkip(length); @@ -205,5 +167,3 @@ operator<=(const File::Offset &one, const File::Offset &two) } /* namespace trace */ - -#endif |