]> git.lyx.org Git - lyx.git/blobdiff - src/support/LAssert.h
change call to shared_ptr::reset, move some using declarations around
[lyx.git] / src / support / LAssert.h
index 0463c9e7306c75c6943500c4e08dd9bf5051f16b..6a937266024f62faa7a5fa1e7b9fa94b6b73e94c 100644 (file)
@@ -2,42 +2,40 @@
 #ifndef LASSERT_H
 #define LASSERT_H
 
-//namespace LyX {
+#include "support/lyxlib.h"
 
-#define HAVE_TEMPLATE
-#ifdef HAVE_TEMPLATE
-//template<class X, class A> inline void Assert(A assertion)
-template<class A> inline void Assert(A assertion)
-{
-       //if (!assertion) throw X();
-       if (!assertion) {
-               abort();
-       }
-}
+extern void emergencyCleanup();
+
+namespace lyx {
+
+#ifdef ENABLE_ASSERTIONS
 
-#ifdef HAVE_PARTIAL_SPECIALIZATION
-// Not too sure if this is the correct way to specialize
-template<class A> inline void Assert(A * ptr)
+/** Live assertion.
+    This is a debug tool to ensure that the assertion holds. If it don't hole
+    we run #emergencyCleanup()# and then #lyx::abort".
+    @param assertion this should evaluate to true unless you want an abort.
+*/
+template<class A>
+inline
+void Assert(A assertion)
 {
-       if (!ptr) {
-               abort();
+       if (!assertion) {
+               ::emergencyCleanup();
+               lyx::abort();
        }
 }
-#endif
-
-//template<class A, class E> inline void Assert(A assertion, E except)
-//{
-//     if (!assertion) except;
-//}
 
 #else
 
-inline void lyx_assert(...)
-{
-       // nothing
-}
+/** Dummy assertion.
+    When compiling without assertions we use this no-op function.
+*/
+template<class A>
+inline
+void Assert(A /*assertion*/) {}
+
+#endif /* ENABLE_ASSERTIONS */
 
-#endif
-#endif
+} // end of namespace LyX
 
-//} // end of namespace LyX
+#endif /* LASSERT_H */