]> git.lyx.org Git - lyx.git/blob - src/support/LAssert.h
6a937266024f62faa7a5fa1e7b9fa94b6b73e94c
[lyx.git] / src / support / LAssert.h
1 // -*- C++ -*-
2 #ifndef LASSERT_H
3 #define LASSERT_H
4
5 #include "support/lyxlib.h"
6
7 extern void emergencyCleanup();
8
9 namespace lyx {
10
11 #ifdef ENABLE_ASSERTIONS
12
13 /** Live assertion.
14     This is a debug tool to ensure that the assertion holds. If it don't hole
15     we run #emergencyCleanup()# and then #lyx::abort".
16     @param assertion this should evaluate to true unless you want an abort.
17 */
18 template<class A>
19 inline
20 void Assert(A assertion)
21 {
22         if (!assertion) {
23                 ::emergencyCleanup();
24                 lyx::abort();
25         }
26 }
27
28 #else
29
30 /** Dummy assertion.
31     When compiling without assertions we use this no-op function.
32 */
33 template<class A>
34 inline
35 void Assert(A /*assertion*/) {}
36
37 #endif /* ENABLE_ASSERTIONS */
38
39 } // end of namespace LyX
40
41 #endif /* LASSERT_H */