From 06f6cac6bb79d5d9a0ba99ed530a5a0a208bb48b Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 15 Nov 2011 23:03:02 -0800 Subject: Adding two Handle restricters: ReadOnly and WriteOnly. --- includes/Handle.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/includes/Handle.h b/includes/Handle.h index 0eea93c..b1398d1 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -108,4 +108,48 @@ class SeekableHandle : public Handle { off_t m_wOffset, m_rOffset; }; +class ReadOnly { + public: + ReadOnly(IO & io) : m_io(io) { Assert(m_io->canRead()); } + virtual void close() throw (GeneralException) { m_io->close(); } + virtual bool isClosed() { return m_io->isClosed(); } + virtual bool isEOF() { return m_io->isEOF(); } + virtual bool canSeek() { return m_io->canSeek(); } + virtual bool canRead() { return true; } + virtual bool canWrite() { return false; } + virtual const char * getName() { return m_io->getName(); } + virtual ssize_t read(void * buf, size_t count) throw (GeneralException) { return m_io->read(buf, count); } + virtual ssize_t write(const void * buf, size_t count) throw (GeneralException) { throw GeneralException("Can't write"); } + virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { m_io->rseek(offset, whence); } + virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { throw GeneralException("Can't write"); } + virtual off_t rtell() throw (GeneralException) { return m_io->rtell(); } + virtual off_t wtell() throw (GeneralException) { throw GeneralException("Can't write"); } + virtual off_t getSize() { return m_io->getSize(); } + virtual time_t getMTime() { return m_io->getMTime(); } + private: + IO m_io; +}; + +class WriteOnly { + public: + WriteOnly(IO & io) : m_io(io) { Assert(m_io->canWrite()); } + virtual void close() throw (GeneralException) { m_io->close(); } + virtual bool isClosed() { return m_io->isClosed(); } + virtual bool isEOF() { return m_io->isEOF(); } + virtual bool canSeek() { return m_io->canSeek(); } + virtual bool canRead() { return false; } + virtual bool canWrite() { return true; } + virtual const char * getName() { return m_io->getName(); } + virtual ssize_t read(void * buf, size_t count) throw (GeneralException) { throw GeneralException("Can't read"); } + virtual ssize_t write(const void * buf, size_t count) throw (GeneralException) { return m_io->write(buf, count); } + virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { throw GeneralException("Can't read"); } + virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { return m_io->wseek(offset, whence); } + virtual off_t rtell() throw (GeneralException) { throw GeneralException("Can't read"); } + virtual off_t wtell() throw (GeneralException) { return m_io->wtell(); } + virtual off_t getSize() { return m_io->getSize(); } + virtual time_t getMTime() { return m_io->getMTime(); } + private: + IO m_io; +}; + }; -- cgit v1.2.3