Flow123d
jenkins-Flow123d-windows32-release-multijob-28
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
system
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
#ifdef Flow123d_NODEBUG
76
77
#undef DEBUG_MESSAGES
78
#undef DEBUG_ASSERTS
79
#undef DEBUG_PROFILER
80
81
#endif
82
83
84
#ifdef Flow123d_DEBUG
85
86
#define DEBUG_MESSAGES
87
#define DEBUG_ASSERTS
88
#define DEBUG_PROFILER
89
90
#endif
91
92
93
#ifdef DEBUG_ASSERTS
94
95
/**
96
* Just quick hack to fix some unit tests.
97
* TODO:
98
* We should make better implementation, rather minimizing
99
* usage of macros. And make robust "system" part, that
100
* is MPI aware, but not MPI dependent.
101
*/
102
#ifdef DEBUG_ASSERTS_WITHOUT_MPI
103
#define MPI_Comm_rank(A, B)
104
#endif // DEBUG_ASSERTS_WITHOUT_MPI
105
106
#define ASSERT(i,...) do {\
107
if (!(i)) {\
108
char msg[1024];\
109
sprintf( msg, __VA_ARGS__);\
110
int rank=-1;\
111
MPI_Comm_rank(MPI_COMM_WORLD, &rank);\
112
THROW( ExcAssertMsg() << EI_Message(std::string(msg)) << EI_MPI_Rank(rank) );\
113
}} while (0)
114
115
#define WARN_ASSERT(i,...) do { if (!(i)) xprintf(Warn,__VA_ARGS__); } while (0)
116
117
118
#else
119
120
#define ASSERT(...)
121
#define WARN_ASSERT(...)
122
123
#endif
124
125
126
127
#ifdef DEBUG_ASSERTS
128
129
#define ASSERT_EQUAL( a, b) do {\
130
stringstream ss; ss << (a) << " != " << (b); \
131
ASSERT( ((a) == (b)), "Violated assert: %s == %s,\n observed: %s.\n",#a, #b, ss.str().c_str()); \
132
} while (0)
133
#else
134
135
#define ASSERT_EQUAL( a, b)
136
137
#endif
138
139
140
141
#ifdef DEBUG_ASSERTS
142
143
#define ASSERT_LESS( a, b) do {\
144
stringstream ss; ss << (a) << " >= " << (b); \
145
ASSERT( ((a) < (b)) , "Violated assert: %s < %s,\n observed: %s.\n",#a,#b, ss.str().c_str()); \
146
} while (0)
147
148
149
150
151
#if defined(ASSERT_LE) && defined(FLOW123D_INCLUDES_GTEST)
152
#undef ASSERT_LE
153
#endif
154
155
156
#define ASSERT_LE( a, b) do {\
157
stringstream ss; ss << (a) << " > " << (b); \
158
ASSERT( ((a) <= (b)) , "Violated assert: %s <= %s,\n observed: %s.\n",#a,#b, ss.str().c_str()); \
159
} while (0)
160
161
#else
162
163
#define ASSERT_LESS( a, b)
164
#define ASSERT_LE( a, b)
165
166
#endif
167
168
169
170
171
#ifdef DEBUG_MESSAGES
172
173
#define DBGMSG(...) do { xprintf(MsgDbg,__VA_ARGS__); fflush(NULL); } while (0)
174
175
176
/**
177
* Usage:
178
* DBGCOUT( << "xy" <<endl );
179
*/
180
#define DBGCOUT(...) do { std::cout << " DBG (" \
181
<< __FILE__ << ", " \
182
<< __func__ << ", " \
183
<< __LINE__ << ")" \
184
__VA_ARGS__; } while(0)
185
186
187
/**
188
* Usage:
189
* DBGVAR( arma::vec( "1 2 3" ) );
190
*/
191
#define DBGVAR( var ) DBGCOUT( << #var << " = " << var << endl )
192
193
#else
194
195
#define DBGMSG(...)
196
#define DBGCOUT(...)
197
#define DBGVAR(var)
198
199
#endif
200
201
///@}
202
203
#endif // GLOBAL_DEFS_H
exc_common.hh
Generated on Tue Aug 19 2014 23:38:30 for Flow123d by
1.8.7