]> git.cworth.org Git - apitrace/blobdiff - trace_file.hpp
Fix writing/reading compressed length of the chunks.
[apitrace] / trace_file.hpp
index f1a63f2affaf73262729767f58d788c59c8ae288..fc42e9b9e7f27ccdc0685d7833d14077bfd99272 100644 (file)
@@ -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(),