summaryrefslogtreecommitdiff
path: root/include/services.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-07-27 21:31:13 -0400
committerAdam <Adam@anope.org>2010-07-27 21:31:13 -0400
commit4b870cc5f9671201dfad6fa836847cdd40aef519 (patch)
tree34aec3d880a22a8a828e5f5a7917e583cee92023 /include/services.h
parent66c0e280ee9d4940fe5a477d3e933ba4221e35db (diff)
Added debug_cast which uses dynamic_cast on debug builds, and static_cast on release builds
Diffstat (limited to 'include/services.h')
-rw-r--r--include/services.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/services.h b/include/services.h
index 16f365a09..8e1adcf01 100644
--- a/include/services.h
+++ b/include/services.h
@@ -41,6 +41,7 @@
#include <sys/types.h>
#include <assert.h>
#include <fcntl.h>
+#include <typeinfo>
#ifndef _WIN32
# include <unistd.h>
@@ -268,6 +269,22 @@ class DatabaseException : public CoreException
virtual ~DatabaseException() throw() { }
};
+/** Debug cast to be used instead of dynamic_cast, this uses dynamic_cast
+ * for debug builds and static_cast on releass builds to speed up the program
+ * because dynamic_cast relies on RTTI.
+ */
+template<typename T, typename O> inline T debug_cast(O ptr)
+{
+#ifdef DEBUG_BUILD
+ T ret = dynamic_cast<T>(ptr);
+ if (ret == NULL)
+ throw CoreException(Anope::string("debug_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail");
+ return ret;
+#else
+ return static_cast<T>(ptr);
+#endif
+}
+
/*************************************************************************/
/** Class with the ability to keep flags on items, they should extend from this