]> git.cworth.org Git - apitrace/blobdiff - trace_file.hpp
Merge remote-tracking branch 'origin/master' into on-demand-loading
[apitrace] / trace_file.hpp
index e3d797d3b20d3228f06711cfc9b3d31eef86c7a5..487121187fdd9dad368fe631445b3ffea218a80e 100644 (file)
@@ -62,22 +62,24 @@ public:
     std::string filename() const;
 
     bool open(const std::string &filename, File::Mode mode);
-    bool write(const void *buffer, int length);
-    bool read(void *buffer, int length);
+    bool write(const void *buffer, size_t length);
+    bool read(void *buffer, size_t length);
     void close();
     void flush(void);
     int getc();
+    bool skip(unsigned length);
 
     virtual bool supportsOffsets() const = 0;
     virtual File::Offset currentOffset();
     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, int length) = 0;
-    virtual bool rawRead(void *buffer, int length) = 0;
+    virtual bool rawWrite(const void *buffer, size_t length) = 0;
+    virtual bool rawRead(void *buffer, size_t length) = 0;
     virtual int rawGetc() = 0;
     virtual void rawClose() = 0;
     virtual void rawFlush() = 0;
+    virtual bool rawSkip(unsigned length) = 0;
 
 protected:
     std::string m_filename;
@@ -111,7 +113,7 @@ inline bool File::open(const std::string &filename, File::Mode mode)
     return m_isOpened;
 }
 
-inline bool File::write(const void *buffer, int length)
+inline bool File::write(const void *buffer, size_t length)
 {
     if (!m_isOpened || m_mode != File::Write) {
         return false;
@@ -119,7 +121,7 @@ inline bool File::write(const void *buffer, int length)
     return rawWrite(buffer, length);
 }
 
-inline bool File::read(void *buffer, int length)
+inline bool File::read(void *buffer, size_t length)
 {
     if (!m_isOpened || m_mode != File::Read) {
         return false;
@@ -148,6 +150,14 @@ inline int File::getc()
     return rawGetc();
 }
 
+inline bool File::skip(unsigned length)
+{
+    if (!m_isOpened || m_mode != File::Read) {
+        return false;
+    }
+    return rawSkip(length);
+}
+
 class ZLibFile : public File {
 public:
     ZLibFile(const std::string &filename = std::string(),
@@ -158,15 +168,50 @@ public:
     virtual bool supportsOffsets() const;
 protected:
     virtual bool rawOpen(const std::string &filename, File::Mode mode);
-    virtual bool rawWrite(const void *buffer, int length);
-    virtual bool rawRead(void *buffer, int length);
+    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(unsigned length);
 private:
     void *m_gzFile;
 };
 
+inline bool
+operator<(const File::Offset &one, const File::Offset &two)
+{
+    return one.chunk < two.chunk ||
+            (one.chunk == two.chunk && one.offsetInChunk < two.offsetInChunk);
+}
+
+inline bool
+operator==(const File::Offset &one, const File::Offset &two)
+{
+    return one.chunk == two.chunk &&
+            one.offsetInChunk == two.offsetInChunk;
+}
+
+inline bool
+operator>=(const File::Offset &one, const File::Offset &two)
+{
+    return one.chunk > two.chunk ||
+            (one.chunk == two.chunk && one.offsetInChunk >= two.offsetInChunk);
+}
+
+inline bool
+operator>(const File::Offset &one, const File::Offset &two)
+{
+    return two < one;
+}
+
+inline bool
+operator<=(const File::Offset &one, const File::Offset &two)
+{
+    return two >= one;
+}
+
+
 }
 
 #endif