From d440c3f50a918a932293ad98bcec96eaa4683222 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 4 Dec 2011 01:19:09 -0800 Subject: 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. --- includes/Handle.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'includes/Handle.h') 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 bool isA() { return !!dynamic_cast(m_h); } IO & operator=(const IO & io) { if (m_h) m_h->delRef(); setHandle(io.m_h); return *this; } - T * operator->() { Assert(m_h); T * r = dynamic_cast(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(m_h); + AAssert(r, "%s->() used with an incompatible Handle type", ClassName(this).c_str()); + return r; + } bool isNull() { return dynamic_cast(m_h); } }; @@ -129,7 +134,7 @@ class SeekableHandle : public Handle { class ReadOnly : public Handle { public: - ReadOnly(IO & io) : m_io(io) { Assert(m_io->canRead()); } + ReadOnly(IO & 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 & io) : m_io(io) { Assert(m_io->canWrite()); } + WriteOnly(IO & 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(); } -- cgit v1.2.3