Index: src/Actions/small_actions.cpp
===================================================================
--- src/Actions/small_actions.cpp	(revision 8bb2fdac28a006989f0feae29f712cc826b109ee)
+++ src/Actions/small_actions.cpp	(revision 13d5a97104c8a5c13d2e78b8d620f8f625a062ac)
@@ -55,6 +55,5 @@
 
 Action::state_ptr ChangeMoleculeNameAction::performUndo(Action::state_ptr _state) {
-  ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state.get());
-  ASSERT(state,"State passed to ChangeMoleculeNameAction::performUndo did not have correct type");
+  ChangeMoleculeNameState *state = assert_cast<ChangeMoleculeNameState*>(_state.get());
 
   string newName = state->mol->getName();
Index: src/Helpers/Assert.cpp
===================================================================
--- src/Helpers/Assert.cpp	(revision 8bb2fdac28a006989f0feae29f712cc826b109ee)
+++ src/Helpers/Assert.cpp	(revision 13d5a97104c8a5c13d2e78b8d620f8f625a062ac)
@@ -48,4 +48,10 @@
 Action _my_assert::defaultAction = Ask;
 std::vector<Assert::hook_t> _my_assert::hooks;
+
+std::map<std::string,bool> _wrapper::ignores;
+const char* _wrapper::message_ptr = "source pointer did not point to object of desired type";
+const char* _wrapper::message_ref = "source reference did not contain object of desired type";
+
+
 
 bool _my_assert::check(const bool res,
Index: src/Helpers/Assert.hpp
===================================================================
--- src/Helpers/Assert.hpp	(revision 8bb2fdac28a006989f0feae29f712cc826b109ee)
+++ src/Helpers/Assert.hpp	(revision 13d5a97104c8a5c13d2e78b8d620f8f625a062ac)
@@ -9,6 +9,9 @@
 #define ASSERT_HPP_
 
+#include<sstream>
 #include<string>
+#include<iostream>
 #include<vector>
+#include<map>
 
 /**
@@ -215,4 +218,57 @@
  */
 
+#ifndef NDEBUG
+  #ifndef STRINGIFY
+    #define STRINGIFY(x) #x
+  #endif
+
+  #ifdef __GNUC__
+    // on gcc we know how to exit to the Debugger
+    #define DEBUG_BREAK __builtin_trap()
+  #else
+    #define DEBUG_BREAK exit(1)
+  #endif
+
+  #define ASSERT(condition,message) \
+    do{\
+      static bool ignore = false;\
+      if(!ignore){\
+        if(Assert::_my_assert::check((condition),STRINGIFY(condition),(message),\
+                                     __FILE__,__LINE__,ignore)){\
+          Assert::_my_assert::doHooks();\
+          DEBUG_BREAK;\
+        }\
+      } \
+    }while(0)
+
+  #define ASSERT_NOCATCH(message) \
+		catch(Assert::AssertionFailure&){throw;}\
+		catch(...){\
+		  static bool ignore = false; \
+		  if(!ignore){\
+			  if(Assert::_my_assert::check(false,"Exception caught",(message),__FILE__,__LINE__,ignore)){\
+			    Assert::_my_assert::doHooks();\
+          DEBUG_BREAK;\
+			  }\
+		  }\
+		} do{(void)(0);}while(0)
+
+  #define assert_cast Assert::_wrapper(__LINE__,__FILE__)._convert
+
+  #define ASSERT_DO(action)    do{Assert::_my_assert::setDefault(action);}while(0)
+  #define ASSERT_HOOK(hook)    do{Assert::_my_assert::addHook(hook);}while(0)
+  #define ASSERT_UNHOOK(hook)  do{Assert::_my_assert::removeHook(hook);}while(0)
+  #define ASSERT_DEFAULT       (Assert::_myAssert::printDefault())
+#else
+  // we need to do something, so this is the usual solution (e.g. assert.h)
+  #define ASSERT(condition,message) (void)(0)
+  #define ASSERT_NOCATCH(message)   catch(...) {throw;} do{(void)(0);}while(0)
+  #define assert_cast static_cast
+  #define ASSERT_DO(action)         (void)(0)
+  #define ASSERT_HOOK(hook)         (void)(0)
+  #define ASSERT_UNHOOK(hook)       (void)(0)
+  #define ASSERT_DEFAULT            std::string("Deactivated")
+#endif
+
 namespace Assert{
 
@@ -238,70 +294,86 @@
     std::string message;
   };
+
+  //! @cond
+#ifndef NDEBUG
+    class _my_assert{
+    public:
+      static bool check(const bool res,
+                        const char* condition,
+                        const char* message,
+                        const char* filename,
+                        const int line,
+                        bool& ignore);
+      static void addHook(Assert::hook_t hook);
+      static void removeHook(Assert::hook_t hook);
+      static void doHooks();
+      static void setDefault(Assert::Action);
+      static Assert::Action getDefault();
+      static std::string printDefault();
+    private:
+      static Assert::Action defaultAction;
+      static std::vector<Assert::hook_t> hooks;
+    };
+
+
+  class _wrapper{
+  public:
+    _wrapper(int _line,const char* _file) :
+      line(_line),
+      file(_file)
+      {}
+
+    // Overloaded template for pointers
+    template<typename target,typename source>
+    target _convert(source *src){
+      std::stringstream sstr;
+      sstr << file << ":" << line;
+      bool &ignore = ignores[sstr.str()];
+
+      if(!ignore){
+        if(_my_assert::check(dynamic_cast<target>(src)==static_cast<target>(src),"type-safe typecast",
+                                       message_ptr,file,line,ignore)){
+          _my_assert::doHooks();
+          DEBUG_BREAK;
+        }
+      }
+      return static_cast<target>(src);
+    }
+
+    // Overloaded template for references
+    template<typename target, typename source>
+    target _convert(source &src){
+            std::stringstream sstr;
+      sstr << file << ":" << line;
+      bool &ignore = ignores[sstr.str()];
+
+      try{
+        target res =dynamic_cast<target>(src);
+        return res;
+      }
+      catch(...){
+        if(!ignore){
+          if(_my_assert::check(0,"type-safe typecast",message_ref,file,line,ignore)){
+            _my_assert::doHooks();
+            DEBUG_BREAK;
+          }
+        }
+      }
+      // The error was ignored. Just return whatever a static_cast would do
+      return static_cast<target>(src);
+    }
+  private:
+    int line;
+    const char *file;
+    static std::map<std::string,bool> ignores;
+    // this avoids duplication of the strings when templates are instantiated
+    static const char* message_ptr;
+    static const char* message_ref;
+  };
+#endif
+  //! @endcond
 }
 
-#ifndef NDEBUG
-  #ifndef STRINGIFY
-    #define STRINGIFY(x) #x
-  #endif
-
-  #ifdef __GNUC__
-    // on gcc we know how to exit to the Debugger
-    #define DEBUG_BREAK __builtin_trap()
-  #else
-    #define DEBUG_BREAK exit(1)
-  #endif
-
-  #define ASSERT(condition,message) \
-    do{\
-      static bool ignore = false;\
-      if(!ignore){\
-        if(_my_assert::check((condition),STRINGIFY(condition),(message),__FILE__,__LINE__,ignore)){\
-          _my_assert::doHooks();\
-          DEBUG_BREAK;\
-        }\
-      } \
-    }while(0)
-
-  #define ASSERT_NOCATCH(message) \
-		catch(Assert::AssertionFailure&){throw;}\
-		catch(...){\
-		  static bool ignore = false; \
-		  _my_assert::check(false,"Exception caught",(message),__FILE__,__LINE__,ignore);\
-		} do{(void)(0);}while(0)
-
-  #define ASSERT_DO(action)    do{_my_assert::setDefault(action);}while(0)
-  #define ASSERT_HOOK(hook)    do{_my_assert::addHook(hook);}while(0)
-  #define ASSERT_UNHOOK(hook)  do{_my_assert::removeHook(hook);}while(0)
-  #define ASSERT_DEFAULT       (_myAssert::printDefault())
-#else
-  // we need to do something, so this is the usual solution (e.g. assert.h)
-  #define ASSERT(condition,message) (void)(0)
-  #define ASSERT_NOCATCH(message)   catch(...) {throw;} do{(void)(0);}while(0)
-  #define ASSERT_DO(action)         (void)(0)
-  #define ASSERT_HOOK(hook)         (void)(0)
-  #define ASSERT_UNHOOK(hook)       (void)(0)
-  #define ASSERT_DEFAULT            std::string("Deactivated")
-#endif
-
-//! @cond
-class _my_assert{
-public:
-  static bool check(const bool res,
-                    const char* condition,
-                    const char* message,
-                    const char* filename,
-                    const int line,
-                    bool& ignore);
-  static void addHook(Assert::hook_t hook);
-  static void removeHook(Assert::hook_t hook);
-  static void doHooks();
-  static void setDefault(Assert::Action);
-  static Assert::Action getDefault();
-  static std::string printDefault();
-private:
-  static Assert::Action defaultAction;
-  static std::vector<Assert::hook_t> hooks;
-};
-//! @endcond
+
 
 
