Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dc6bac0d60d2bae9a5e60696b282fd8cd915ac11
[simgrid.git] / include / xbt / asserts.h
1 /*  xbt/asserts.h -- assertion mecanism                                     */
2
3 /* Copyright (c) 2004,2005 Martin Quinson. All rights reserved.             */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef _XBT_ASSERTS_H
9 #define _XBT_ASSERTS_H
10
11 #include "xbt/misc.h"
12 #include "xbt/log.h"
13 #include "xbt/ex.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  * You can pass them a format message and arguments, just as if it where a printf.
22  * It is converted to a CRITICALn logging request.
23  *
24  * @{
25  */
26 #ifdef NDEBUG
27 #define xbt_assert(cond)
28 #define xbt_assert0(cond,msg)
29 #define xbt_assert1(cond,msg,a)
30 #define xbt_assert2(cond,msg,a,b)
31 #define xbt_assert3(cond,msg,a,b,c)
32 #define xbt_assert4(cond,msg,a,b,c,d)
33 #define xbt_assert5(cond,msg,a,b,c,d,e)
34 #define xbt_assert6(cond,msg,a,b,c,d,e,f)
35 #else
36      /** @brief The condition which failed will be displayed.
37          @hideinitializer  */
38 #define xbt_assert(cond)                  if (!(cond)) THROW1(0,0,"Assertion %s failed", #cond)
39      /** @hideinitializer  */
40 #define xbt_assert0(cond,msg)             if (!(cond)) THROW0(0,0,msg)
41      /** @hideinitializer  */
42 #define xbt_assert1(cond,msg,a)           if (!(cond)) THROW1(0,0,msg,a)
43      /** @hideinitializer  */
44 #define xbt_assert2(cond,msg,a,b)         if (!(cond)) THROW2(0,0,msg,a,b)
45      /** @hideinitializer  */
46 #define xbt_assert3(cond,msg,a,b,c)       if (!(cond)) THROW3(0,0,msg,a,b,c)
47      /** @hideinitializer  */
48 #define xbt_assert4(cond,msg,a,b,c,d)     if (!(cond)) THROW4(0,0,msg,a,b,c,d)
49      /** @hideinitializer  */
50 #define xbt_assert5(cond,msg,a,b,c,d,e)   if (!(cond)) THROW5(0,0,msg,a,b,c,d,e)
51      /** @hideinitializer  */
52 #define xbt_assert6(cond,msg,a,b,c,d,e,f) if (!(cond)) THROW6(0,0,msg,a,b,c,d,e,f)
53 #endif
54 /** @} */
55   SG_END_DECL()
56 #endif /* _XBT_ASSERTS_H */