Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d0f486405fd302e8d06543d3422b5e1be1efc1f8
[simgrid.git] / include / xbt / asserts.h
1 /* $Id$ */
2 /*  xbt/asserts.h -- assertion mecanism                                     */
3
4 /* Copyright (c) 2004,2005 Martin Quinson. All rights reserved.             */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #ifndef _XBT_ASSERTS_H
10 #define _XBT_ASSERTS_H
11
12 #include "xbt/misc.h"
13 #include "xbt/log.h"
14   
15 SG_BEGIN_DECL()
16
17 /**
18  * @addtogroup XBT_error
19  * @brief Those are the SimGrid version of the good ol' assert macro.
20  *
21  * <center><table><tr><td><b>Top</b>    <td> [\ref index]::[\ref XBT_API]
22  *                <tr><td><b>Prev</b>   <td> [\ref XBT_log]
23  *                <tr><td><b>Next</b>   <td> [\ref XBT_config]     </table></center>
24  *
25  * You can pass them a format message and arguments, just as if it where a printf.
26  * It is converted to a CRITICALn logging request.
27  *
28  * @{
29  */
30 #ifdef NDEBUG
31 #define xbt_assert(cond)
32 #define xbt_assert0(cond,msg)
33 #define xbt_assert1(cond,msg,a)
34 #define xbt_assert2(cond,msg,a,b)
35 #define xbt_assert3(cond,msg,a,b,c)
36 #define xbt_assert4(cond,msg,a,b,c,d)
37 #define xbt_assert5(cond,msg,a,b,c,d,e)
38 #define xbt_assert6(cond,msg,a,b,c,d,e,f)
39 #else
40      /** @brief The condition which failed will be displayed.
41          @hideinitializer  */
42 #define xbt_assert(cond)                  if (!(cond)) { CRITICAL1("Assertion %s failed", #cond); xbt_abort(); }
43      /** @hideinitializer  */
44 #define xbt_assert0(cond,msg)             if (!(cond)) { CRITICAL0(msg); xbt_abort(); }
45      /** @hideinitializer  */
46 #define xbt_assert1(cond,msg,a)           if (!(cond)) { CRITICAL1(msg,a); xbt_abort(); }
47      /** @hideinitializer  */
48 #define xbt_assert2(cond,msg,a,b)         if (!(cond)) { CRITICAL2(msg,a,b); xbt_abort(); }
49      /** @hideinitializer  */
50 #define xbt_assert3(cond,msg,a,b,c)       if (!(cond)) { CRITICAL3(msg,a,b,c); xbt_abort(); }
51      /** @hideinitializer  */
52 #define xbt_assert4(cond,msg,a,b,c,d)     if (!(cond)) { CRITICAL4(msg,a,b,c,d); xbt_abort(); }
53      /** @hideinitializer  */
54 #define xbt_assert5(cond,msg,a,b,c,d,e)   if (!(cond)) { CRITICAL5(msg,a,b,c,d,e); xbt_abort(); }
55      /** @hideinitializer  */
56 #define xbt_assert6(cond,msg,a,b,c,d,e,f) if (!(cond)) { CRITICAL6(msg,a,b,c,d,e,f); xbt_abort(); }
57 #endif
58      
59 void xbt_abort(void) _XBT_GNUC_NORETURN;
60 void xbt_die(const char *msg) _XBT_GNUC_NORETURN;
61
62 /** @} */     
63   
64 SG_END_DECL()
65
66 #endif /* _XBT_ASSERTS_H */