summaryrefslogtreecommitdiff
path: root/includes/Handle.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-12-04 01:19:09 -0800
committerPixel <pixel@nobis-crew.org>2011-12-04 01:20:10 -0800
commitd440c3f50a918a932293ad98bcec96eaa4683222 (patch)
tree33e8e42a8e4506ae9da70cdb44dd133bde7f7219 /includes/Handle.h
parente5577eb7a643ce7885e5d14660a6d24254161622 (diff)
Reworked some things in the architecture, mainly exceptions and asserts.
-) Removed Assert() -) Added AAssert(), IAssert(), RAssert(), TAssert() and Failure() -) Reworked all asserts in the code, and added meaningful messages to them. -) Changed the way the startup code is generated; BALAU_STARTUP is no longer necessary.
Diffstat (limited to 'includes/Handle.h')
-rw-r--r--includes/Handle.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/includes/Handle.h b/includes/Handle.h
index cc66a22..e3ff356 100644
--- a/includes/Handle.h
+++ b/includes/Handle.h
@@ -29,7 +29,7 @@ class BaseEvent;
class Handle {
public:
- virtual ~Handle() { Assert(m_refCount == 0); }
+ virtual ~Handle() { AAssert(m_refCount == 0, "Do not use handles directly; warp them in IO<>"); }
virtual void close() throw (GeneralException) = 0;
virtual bool isClosed() = 0;
virtual bool isEOF() = 0;
@@ -107,7 +107,12 @@ class IO : public IOBase {
template<class U>
bool isA() { return !!dynamic_cast<U *>(m_h); }
IO<T> & operator=(const IO<T> & io) { if (m_h) m_h->delRef(); setHandle(io.m_h); return *this; }
- T * operator->() { Assert(m_h); T * r = dynamic_cast<T *>(m_h); Assert(r); return r; }
+ T * operator->() {
+ AAssert(m_h, "Can't use %s->() with a null Handle", ClassName(this).c_str());
+ T * r = dynamic_cast<T *>(m_h);
+ AAssert(r, "%s->() used with an incompatible Handle type", ClassName(this).c_str());
+ return r;
+ }
bool isNull() { return dynamic_cast<T *>(m_h); }
};
@@ -129,7 +134,7 @@ class SeekableHandle : public Handle {
class ReadOnly : public Handle {
public:
- ReadOnly(IO<Handle> & io) : m_io(io) { Assert(m_io->canRead()); }
+ ReadOnly(IO<Handle> & io) : m_io(io) { AAssert(m_io->canRead(), "You need to use ReadOnly with a Handle that can at least read"); }
virtual void close() throw (GeneralException) { m_io->close(); }
virtual bool isClosed() { return m_io->isClosed(); }
virtual bool isEOF() { return m_io->isEOF(); }
@@ -151,7 +156,7 @@ class ReadOnly : public Handle {
class WriteOnly : public Handle {
public:
- WriteOnly(IO<Handle> & io) : m_io(io) { Assert(m_io->canWrite()); }
+ WriteOnly(IO<Handle> & io) : m_io(io) { AAssert(m_io->canWrite(), "You need to use WriteOnly with a Handle that can at least write"); }
virtual void close() throw (GeneralException) { m_io->close(); }
virtual bool isClosed() { return m_io->isClosed(); }
virtual bool isEOF() { return m_io->isEOF(); }