add helper available()
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 26 Apr 2011 17:49:03 +0000 (17:49 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 26 Apr 2011 17:49:03 +0000 (17:49 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@1188 2bbb7eff-a529-9590-31e7-b0007b416f81

include/core/SkReader32.h
include/core/SkWriter32.h

index 1c72a87..598723c 100644 (file)
@@ -43,6 +43,10 @@ public:
     bool eof() const { return fCurr >= fStop; }
     const void* base() const { return fBase; }
     const void* peek() const { return fCurr; }
+
+    uint32_t available() const { return fStop - fCurr; }
+    bool isAvailable(uint32_t size) const { return fCurr + size <= fStop; }
+    
     void rewind() { fCurr = fBase; }
 
     void setOffset(size_t offset) {
index aeeb37d..7ec170c 100644 (file)
@@ -70,6 +70,14 @@ public:
     
     // write count bytes (must be a multiple of 4)
     void writeMul4(const void* values, size_t size) {
+        this->write(values, size);
+    }
+
+    /**
+     *  Write size bytes from values. size must be a multiple of 4, though
+     *  values need not be 4-byte aligned.
+     */
+    void write(const void* values, size_t size) {
         SkASSERT(SkAlign4(size) == size);
         // if we could query how much is avail in the current block, we might
         // copy that much, and then alloc the rest. That would reduce the waste
@@ -83,7 +91,7 @@ public:
     uint32_t  size() const { return fSize; }
     void      reset();
     uint32_t* reserve(size_t size); // size MUST be multiple of 4
-    
+
     // return the address of the 4byte int at the specified offset (which must
     // be a multiple of 4. This does not allocate any new space, so the returned
     // address is only valid for 1 int.