From: Zack Rusin Date: Thu, 25 Aug 2011 01:54:56 +0000 (-0400) Subject: Inline some File methods. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=124cd34846abf59579fe7cbd819a3a719a07a29f;p=apitrace Inline some File methods. --- diff --git a/trace_file.cpp b/trace_file.cpp index 758ecd7..c7227c6 100644 --- a/trace_file.cpp +++ b/trace_file.cpp @@ -25,75 +25,11 @@ File::File(const std::string &filename, } } - File::~File() { close(); } -bool File::isOpened() const -{ - return m_isOpened; -} - -File::Mode File::mode() const -{ - return m_mode; -} - -std::string File::filename() const -{ - return m_filename; -} - -bool File::open(const std::string &filename, File::Mode mode) -{ - if (m_isOpened) { - close(); - } - m_isOpened = rawOpen(filename, mode); - m_mode = mode; - - return m_isOpened; -} - -bool File::write(const void *buffer, int length) -{ - if (!m_isOpened || m_mode != File::Write) { - return false; - } - return rawWrite(buffer, length); -} - -bool File::read(void *buffer, int length) -{ - if (!m_isOpened || m_mode != File::Read) { - return false; - } - return rawRead(buffer, length); -} - -void File::close() -{ - if (m_isOpened) { - rawClose(); - m_isOpened = false; - } -} - -void File::flush(FlushType type) -{ - rawFlush(type); -} - -int File::getc() -{ - if (!m_isOpened || m_mode != File::Read) { - return 0; - } - return rawGetc(); -} - bool File::isZLibCompressed(const std::string &filename) { std::fstream stream(filename.c_str(), diff --git a/trace_file.hpp b/trace_file.hpp index f1a63f2..fc42e9b 100644 --- a/trace_file.hpp +++ b/trace_file.hpp @@ -26,6 +26,7 @@ public: bool isOpened() const; File::Mode mode() const; + std::string filename() const; bool open(const std::string &filename, File::Mode mode); @@ -49,6 +50,69 @@ protected: bool m_isOpened; }; +inline bool File::isOpened() const +{ + return m_isOpened; +} + +inline File::Mode File::mode() const +{ + return m_mode; +} + +inline std::string File::filename() const +{ + return m_filename; +} + +inline bool File::open(const std::string &filename, File::Mode mode) +{ + if (m_isOpened) { + close(); + } + m_isOpened = rawOpen(filename, mode); + m_mode = mode; + + return m_isOpened; +} + +inline bool File::write(const void *buffer, int length) +{ + if (!m_isOpened || m_mode != File::Write) { + return false; + } + return rawWrite(buffer, length); +} + +inline bool File::read(void *buffer, int length) +{ + if (!m_isOpened || m_mode != File::Read) { + return false; + } + return rawRead(buffer, length); +} + +inline void File::close() +{ + if (m_isOpened) { + rawClose(); + m_isOpened = false; + } +} + +inline void File::flush(File::FlushType type) +{ + rawFlush(type); +} + +inline int File::getc() +{ + if (!m_isOpened || m_mode != File::Read) { + return 0; + } + return rawGetc(); +} + class ZLibFile : public File { public: ZLibFile(const std::string &filename = std::string(),