From 3fedf9f3fff7c8ceadd077fc7ed4eff4c4108026 Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 17 Sep 2007 08:33:25 +0000 Subject: Adding "GetRemaining" to Buffer class, and enabling the read method to allow null buffers. --- include/Buffer.h | 3 ++- lib/Buffer.cc | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/Buffer.h b/include/Buffer.h index 73225bc..47c5c5a 100644 --- a/include/Buffer.h +++ b/include/Buffer.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Buffer.h,v 1.22 2007-06-23 15:36:02 pixel Exp $ */ +/* $Id: Buffer.h,v 1.23 2007-09-17 08:33:25 pixel Exp $ */ #ifndef __BUFFER_H__ #define __BUFFER_H__ @@ -43,6 +43,7 @@ class Buffer : public Handle { virtual Buffer operator=(const Buffer &); virtual bool CanWatch() const; virtual ssize_t GetSize() const; + virtual ssize_t GetRemaining() const; virtual bool CanSeek() const; virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException); virtual off_t tell() const; diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 575503c..7def194 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Buffer.cc,v 1.28 2007-06-23 15:36:02 pixel Exp $ */ +/* $Id: Buffer.cc,v 1.29 2007-09-17 08:33:25 pixel Exp $ */ #include #ifdef HAVE_CONFIG_H @@ -66,7 +66,8 @@ ssize_t Buffer::read(void *buf, size_t count) throw (GeneralException) { return 0; } - memcpy(buf, buffer + ptr, count); + if (buf) + memcpy(buf, buffer + ptr, count); ptr += count; if (!seekable) { @@ -123,6 +124,10 @@ ssize_t Buffer::GetSize() const { return realsiz; } +ssize_t Buffer::GetRemaining() const { + return realsiz - ptr; +} + Byte Buffer::operator[](size_t p) const { if (p >= realsiz) { return 0; -- cgit v1.2.3