summaryrefslogtreecommitdiff
path: root/include/services.h
diff options
context:
space:
mode:
authorNaram Qashat <cyberbotx@cyberbotx.com>2010-07-28 00:28:59 -0400
committerNaram Qashat <cyberbotx@cyberbotx.com>2010-07-28 00:28:59 -0400
commitaa9610a56ff18edd0703a3f391c90e1f8a761476 (patch)
tree5fceef5b811ffcb28bcea093b59604b94a2a89c1 /include/services.h
parent4700c9626861b193798b3cf3d53fb89a913c5819 (diff)
parenta2573a2c3067343ebf46292691671ba4bad855a8 (diff)
Merge branch '1.9' of ssh://anope.git.sf.net/gitroot/anope/anope into 1.9
Diffstat (limited to 'include/services.h')
-rw-r--r--include/services.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/include/services.h b/include/services.h
index 16f365a09..fdbaccbfc 100644
--- a/include/services.h
+++ b/include/services.h
@@ -39,8 +39,8 @@
#include <sys/stat.h> /* for umask() on some systems */
#include <sys/types.h>
-#include <assert.h>
#include <fcntl.h>
+#include <typeinfo>
#ifndef _WIN32
# include <unistd.h>
@@ -268,6 +268,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