LifeV
LifeAssert.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6 Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8 This file is part of LifeV.
9 
10 LifeV is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 
15 LifeV is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 /*!
27  @file
28  @brief Assert macros for LifeV
29 
30  @date 19-02-2005
31  @author Christophe Prud'homme <christophe.prudhomme@epfl.ch>
32 
33  @maintainer Radu Popescu <radu.popescu@epfl.ch>
34 */
35 
36 /*! \page macros_page LifeV Macros
37  \section assert_macros Assertion Macros
38 
39  \subsection assertions Assertions
40 
41  LifeV defines a few macros to test pre and post conditions. To
42  enable them all you define the preprocessing variable \c
43  LIFEV_CHECK_ALL . This is done easily by configuring LifeV with the
44  flag \c --enable-debug which will include the option
45  \c -DLIFEV_CHECK_ALL
46 
47  -# #LIFEV_ASSERT
48 
49  \subsection hints LifeV C++ Compiler Hints
50 
51  -# #INLINE
52  -# #LIFEV_RESTRICT
53 
54  \subsection attribute_macro LifeV Attribute Macros
55 
56  -# #LIFEV_EXPORT and #LIFEV_NO_EXPORT
57  -# #LIFEV_PACKED
58  -# #LIFEV_DEPRECATED
59  -# #LIFEV_ISLIKELY and #LIFEV_ISUNLIKELY
60 */
61 
62 #ifndef LIFE_ASSERT_H
63 #define LIFE_ASSERT_H 1
64 
65 #include <lifev/core/util/LifeAssertSmart.hpp>
66 
67 #define ABORT() std::abort()
68 
69 #define ERROR_MSG(A) LIFEV_ASSERT( 0 ).error( A );
70 #define RETURN_UNDEFINED ERROR_MSG("undefined return"); return 0;
71 #define ASSERT0(X,A) LIFEV_ASSERT( X ).error( A );
72 #define ASSERT_PRE0(X,A) LIFEV_ASSERT( X ).error( "Precondition Error" );
73 #define ASSERT_POS0(X,A) LIFEV_ASSERT( X ).error( "Postcondition Error" );
74 #define ASSERT_INV0(X,A) LIFEV_ASSERT( X ).error( "Invariant Error : " );
75 #define ASSERT_BD0(X) LIFEV_ASSERT( X ).error( "Array bounds error" );
76 
77 #ifdef LIFEV_CHECK_ALL
78 #define CHECK_KN
79 #define TEST_PRE
80 #define TEST_POS
81 #define TEST_INV
82 #define TEST_BOUNDS
83 #define NOINLINE
84 #define HAVE_LIFEV_DEBUG
85 #endif /* LIFEV_CHECK_ALL */
86 
87 #ifdef HAVE_LIFEV_DEBUG
88 #define ASSERT(X,A) ASSERT0(X,A)
89 #else
90 #define ASSERT(X,A)
91 #endif
92 
93 #ifdef TEST_PRE
94 #define ASSERT_PRE(X,A) ASSERT_PRE0(X,A)
95 #else
96 #define ASSERT_PRE(X,A)
97 #endif
98 
99 #ifdef TEST_POS
100 #define ASSERT_POS(X,A) ASSERT_POS0(X,A)
101 #else
102 #define ASSERT_POS(X,A)
103 #endif
104 
105 #ifdef TEST_INV
106 #define ASSERT_INV(X,A) ASSERT_INV0(X,A)
107 #else
108 #define ASSERT_INV(X,A)
109 #endif
110 
111 #ifdef TEST_BOUNDS
112 #define ASSERT_BD(X) ASSERT_BD0(X)
113 #else
114 #define ASSERT_BD(X)
115 #endif
116 
117 #endif /* LIFE_ASSERT_H */
#define ERROR_MSG(A)
Definition: LifeAssert.hpp:69
#define LIFEV_ASSERT(expr)