Flow123d  jenkins-Flow123d-windows32-release-multijob-51
global_defs.h
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file global_defs.h
26  * @brief Global macros to enhance readability and debugging, general constants.
27  *
28  */
29 
30 #ifndef GLOBAL_DEFS_H
31 #define GLOBAL_DEFS_H
32 
33 //Make sure that headers necessary for following macros are included.
34 #include <stdint.h>
35 #include <string.h>
36 #include <stdlib.h>
37 
38 #include "system/exc_common.hh"
39 
40 
41 /*! @brief Debugging macros.
42  *
43  * The macro ASSERT has to be used for assertion tests. An error occures if
44  * given condition is violated. Macro accepts additional variables to print.
45  *
46  * Example:
47  * @verbatim
48  * ASSERT( i<size , "Array X overflow: index %d >= alocated size %d.\n",i,size);
49  * @endverbatim
50  *
51  * The macro INPUT_CHECK should be used for assertions about user input. So
52  * they produce User Error instead of Program error.
53  *
54  * The macro DBGMSG should be used for debugging messages,
55  * so they can be removed in production version.
56  *
57  * WARN_ASSERT - can be used for consistency tests in debugging version.
58  *
59  * @{
60  */
61 #define INPUT_CHECK(i,...) do { if (!(i)) xprintf(UsrErr,__VA_ARGS__); } while (0)
62 
63 /**
64  * Actually there are following debugging switches
65  * DEBUG_MESSAGES - use various debugging messages introduced by DBGMSG
66  * DEBUG_ASSERTS - use assertion checks introduced by ASSERT
67  * DEBUG_PROFILER - use profiling introduced by START_TIMER, END_TIMER
68  *
69  * You can turn all off defining: Flow123d_NODEBUG
70  * or turn all on defining: Flow123d_DEBUG
71  *
72  * Flow123d_DEBUG overrides Flow123d_NODEBUG
73  */
74 
75 
76 #ifdef Flow123d_NODEBUG
77 
78 #undef DEBUG_MESSAGES
79 #undef DEBUG_ASSERTS
80 #undef DEBUG_PROFILER
81 
82 #endif
83 
84 
85 #ifdef Flow123d_DEBUG
86 
87 #define DEBUG_MESSAGES
88 #define DEBUG_ASSERTS
89 #define DEBUG_PROFILER
90 
91 #endif
92 
93 
94 #ifdef DEBUG_ASSERTS
95 
96 /**
97  * Just quick hack to fix some unit tests.
98  * TODO:
99  * We should make better implementation, rather minimizing
100  * usage of macros. And make robust "system" part, that
101  * is MPI aware, but not MPI dependent.
102  */
103 #ifdef DEBUG_ASSERTS_WITHOUT_MPI
104 #define MPI_Comm_rank(A, B)
105 #endif // DEBUG_ASSERTS_WITHOUT_MPI
106 
107 #define ASSERT(i,...) do {\
108  if (!(i)) {\
109  char msg[1024];\
110  sprintf( msg, __VA_ARGS__);\
111  int rank=-1;\
112  MPI_Comm_rank(MPI_COMM_WORLD, &rank);\
113  THROW( ExcAssertMsg() << EI_Message(std::string(msg)) << EI_MPI_Rank(rank) );\
114  }} while (0)
115 
116 #define WARN_ASSERT(i,...) do { if (!(i)) xprintf(Warn,__VA_ARGS__); } while (0)
117 
118 
119 #else
120 
121 #define ASSERT(...)
122 #define WARN_ASSERT(...)
123 
124 #endif
125 
126 
127 
128 #ifdef DEBUG_ASSERTS
129 
130 #define ASSERT_EQUAL( a, b) do {\
131  stringstream ss; ss << (a) << " != " << (b); \
132  ASSERT( ((a) == (b)), "Violated assert: %s == %s,\n observed: %s.\n",#a, #b, ss.str().c_str()); \
133  } while (0)
134 #else
135 
136 #define ASSERT_EQUAL( a, b)
137 
138 #endif
139 
140 
141 
142 #ifdef DEBUG_ASSERTS
143 
144 #define ASSERT_LESS( a, b) do {\
145  stringstream ss; ss << (a) << " >= " << (b); \
146  ASSERT( ((a) < (b)) , "Violated assert: %s < %s,\n observed: %s.\n",#a,#b, ss.str().c_str()); \
147  } while (0)
148 
149 
150 
151 
152 #if defined(ASSERT_LE) && defined(FLOW123D_INCLUDES_GTEST)
153 #undef ASSERT_LE
154 #endif
155 
156 
157 #define ASSERT_LE( a, b) do {\
158  stringstream ss; ss << (a) << " > " << (b); \
159  ASSERT( ((a) <= (b)) , "Violated assert: %s <= %s,\n observed: %s.\n",#a,#b, ss.str().c_str()); \
160  } while (0)
161 
162 #else
163 
164 #define ASSERT_LESS( a, b)
165 #define ASSERT_LE( a, b)
166 
167 #endif
168 
169 
170 
171 
172 #ifdef DEBUG_MESSAGES
173 
174 #define DBGMSG(...) do { xprintf(MsgDbg,__VA_ARGS__); fflush(NULL); } while (0)
175 
176 
177 /**
178  * Usage:
179  * DBGCOUT( << "xy" <<endl );
180  */
181 #define DBGCOUT(...) do { std::cout << " DBG (" \
182  << __FILE__ << ", " \
183  << __func__ << ", " \
184  << __LINE__ << ")" \
185  __VA_ARGS__; } while(0)
186 
187 
188 /**
189  * Usage:
190  * DBGVAR( arma::vec( "1 2 3" ) );
191  */
192 #define DBGVAR( var ) DBGCOUT( << #var << " = " << var << endl )
193 
194 #else
195 
196 #define DBGMSG(...)
197 #define DBGCOUT(...)
198 #define DBGVAR(var)
199 
200 #endif
201 
202 
203 #ifdef DEBUG_ASSERTS
204 
205 static const int debug_asserts_view = 1;
206 
207 #else
208 
209 static const int debug_asserts_view = 0;
210 
211 #endif
212 
213 ///@}
214 
215 #endif // GLOBAL_DEFS_H
static const int debug_asserts_view
Definition: global_defs.h:209