Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding licence, getting rid of useless includes and cosmetics
[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 #include "xbt/ex.h"
15   
16 SG_BEGIN_DECL()
17
18 /**
19  * @addtogroup XBT_error
20  * @brief Those are the SimGrid version of the good ol' assert macro.
21  *
22  * <center><table><tr><td><b>Top</b>    <td> [\ref index]::[\ref XBT_API]
23  *                <tr><td><b>Prev</b>   <td> [\ref XBT_log]
24  *                <tr><td><b>Next</b>   <td> [\ref XBT_config]     </table></center>
25  *
26  * You can pass them a format message and arguments, just as if it where a printf.
27  * It is converted to a CRITICALn logging request.
28  *
29  * @{
30  */
31 void xbt_abort(void) _XBT_GNUC_NORETURN;
32 void xbt_die(const char *msg) _XBT_GNUC_NORETURN;
33
34 #ifdef NDEBUG
35 #define xbt_assert(cond)
36 #define xbt_assert0(cond,msg)
37 #define xbt_assert1(cond,msg,a)
38 #define xbt_assert2(cond,msg,a,b)
39 #define xbt_assert3(cond,msg,a,b,c)
40 #define xbt_assert4(cond,msg,a,b,c,d)
41 #define xbt_assert5(cond,msg,a,b,c,d,e)
42 #define xbt_assert6(cond,msg,a,b,c,d,e,f)
43 #else
44      /** @brief The condition which failed will be displayed.
45          @hideinitializer  */
46 #define xbt_assert(cond)                  if (!(cond)) THROW1(0,0,"Assertion %s failed", #cond)
47      /** @hideinitializer  */
48 #define xbt_assert0(cond,msg)             if (!(cond)) THROW0(0,0,msg)
49      /** @hideinitializer  */
50 #define xbt_assert1(cond,msg,a)           if (!(cond)) THROW1(0,0,msg,a)
51      /** @hideinitializer  */
52 #define xbt_assert2(cond,msg,a,b)         if (!(cond)) THROW2(0,0,msg,a,b)
53      /** @hideinitializer  */
54 #define xbt_assert3(cond,msg,a,b,c)       if (!(cond)) THROW3(0,0,msg,a,b,c)
55      /** @hideinitializer  */
56 #define xbt_assert4(cond,msg,a,b,c,d)     if (!(cond)) THROW4(0,0,msg,a,b,c,d)
57      /** @hideinitializer  */
58 #define xbt_assert5(cond,msg,a,b,c,d,e)   if (!(cond)) THROW5(0,0,msg,a,b,c,d,e)
59      /** @hideinitializer  */
60 #define xbt_assert6(cond,msg,a,b,c,d,e,f) if (!(cond)) THROW6(0,0,msg,a,b,c,d,e,f)
61 #endif
62      
63
64 /** @} */     
65   
66 SG_END_DECL()
67
68 #endif /* _XBT_ASSERTS_H */