From 5b3d5349bedf37ec6fcf03bac04cf33129fc176a Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Tue, 26 Apr 2011 17:49:03 +0000 Subject: [PATCH] add helper available() git-svn-id: http://skia.googlecode.com/svn/trunk@1188 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkReader32.h | 4 ++++ include/core/SkWriter32.h | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/core/SkReader32.h b/include/core/SkReader32.h index 1c72a87eb7..598723ce70 100644 --- a/include/core/SkReader32.h +++ b/include/core/SkReader32.h @@ -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) { diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h index aeeb37de4b..7ec170c160 100644 --- a/include/core/SkWriter32.h +++ b/include/core/SkWriter32.h @@ -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.