Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "Change those functions to public for use external parser."
[simgrid.git] / include / xbt / asserts.h
1 /*  xbt/asserts.h -- assertion mecanism                                     */
2
3 /* Copyright (c) 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
4  * 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  * You can pass them a format message and arguments, just as if it where a
23  * printf.
24  * It is converted to a CRITICALn logging request.
25  * Be careful: the boolean expression that you want to test should not have
26  * side effects, because assertions are disabled at compile time if NDEBUG
27  * is set.
28  *
29  * @{
30  */
31 #ifdef NDEBUG
32 #define xbt_assert(cond)
33 #define xbt_assert0(cond,msg)
34 #define xbt_assert1(cond,msg,a)
35 #define xbt_assert2(cond,msg,a,b)
36 #define xbt_assert3(cond,msg,a,b,c)
37 #define xbt_assert4(cond,msg,a,b,c,d)
38 #define xbt_assert5(cond,msg,a,b,c,d,e)
39 #define xbt_assert6(cond,msg,a,b,c,d,e,f)
40 #else
41      /** @brief The condition which failed will be displayed.
42          @hideinitializer  */
43 #define xbt_assert(cond)                  do { if (!(cond)) THROW1(0,0,"Assertion %s failed", #cond); } while (0)
44      /** @hideinitializer  */
45 #define xbt_assert0(cond,msg)             do { if (!(cond)) THROW0(0,0,msg); } while (0)
46      /** @hideinitializer  */
47 #define xbt_assert1(cond,msg,a)           do { if (!(cond)) THROW1(0,0,msg,a); } while (0)
48      /** @hideinitializer  */
49 #define xbt_assert2(cond,msg,a,b)         do { if (!(cond)) THROW2(0,0,msg,a,b); } while (0)
50      /** @hideinitializer  */
51 #define xbt_assert3(cond,msg,a,b,c)       do { if (!(cond)) THROW3(0,0,msg,a,b,c); } while (0)
52      /** @hideinitializer  */
53 #define xbt_assert4(cond,msg,a,b,c,d)     do { if (!(cond)) THROW4(0,0,msg,a,b,c,d); } while (0)
54      /** @hideinitializer  */
55 #define xbt_assert5(cond,msg,a,b,c,d,e)   do { if (!(cond)) THROW5(0,0,msg,a,b,c,d,e); } while (0)
56      /** @hideinitializer  */
57 #define xbt_assert6(cond,msg,a,b,c,d,e,f) do { if (!(cond)) THROW6(0,0,msg,a,b,c,d,e,f); } while (0)
58 #endif
59 /** @} */
60     SG_END_DECL()
61 #endif                          /* _XBT_ASSERTS_H */