summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-11-15 23:03:02 -0800
committerPixel <pixel@nobis-crew.org>2011-11-15 23:03:02 -0800
commit06f6cac6bb79d5d9a0ba99ed530a5a0a208bb48b (patch)
tree3f7b45109aa4b4eb8245ab0e85de0960edd4d652 /includes
parentdb098e95abd5297a33359218fdc49faa2f93bbb5 (diff)
Adding two Handle restricters: ReadOnly and WriteOnly.
Diffstat (limited to 'includes')
-rw-r--r--includes/Handle.h44
1 files changed, 44 insertions, 0 deletions
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<Handle> & 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<Handle> m_io;
+};
+
+class WriteOnly {
+ public:
+ WriteOnly(IO<Handle> & 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<Handle> m_io;
+};
+
};