Flow123d
JS_before_hm-1623-gd361259
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
system
global_defs.h
Go to the documentation of this file.
1
/*!
2
*
3
* Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4
*
5
* This program is free software; you can redistribute it and/or modify it under
6
* the terms of the GNU General Public License version 3 as published by the
7
* Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
*
13
*
14
* @file global_defs.h
15
* @brief Global macros to enhance readability and debugging, general constants.
16
*/
17
18
#ifndef GLOBAL_DEFS_H
19
#define GLOBAL_DEFS_H
20
21
//Make sure that headers necessary for following macros are included.
22
#include <stdint.h>
23
#include <
string.h
>
24
#include <stdlib.h>
25
26
#include "
system/exc_common.hh
"
27
#include "config.h"
28
#include "
mpi.h
"
29
#include "
logger.hh
"
30
31
/**
32
* Actually there are following debugging switches
33
* FLOW123D_DEBUG_MESSAGES - use various debugging messages introduced by DBGCOUT
34
* FLOW123D_DEBUG_ASSERTS - use assertion checks introduced by ASSERT
35
* FLOW123D_DEBUG_PROFILER - use profiling introduced by START_TIMER, END_TIMER
36
*
37
* You can turn all off defining: FLOW123D_NODEBUG
38
* or turn all on defining: FLOW123D_DEBUG
39
*
40
* FLOW123D_DEBUG overrides FLOW123D_NODEBUG
41
*/
42
43
44
#ifdef FLOW123D_NODEBUG
45
46
#undef FLOW123D_DEBUG_MESSAGES
47
#undef FLOW123D_DEBUG_ASSERTS
48
#undef FLOW123D_DEBUG_PROFILER
49
50
#endif
51
52
53
#ifdef FLOW123D_DEBUG
54
55
#define FLOW123D_DEBUG_MESSAGES
56
#define FLOW123D_DEBUG_ASSERTS
57
#define FLOW123D_DEBUG_PROFILER
58
59
#endif
60
61
62
#include "
asserts.hh
"
63
64
65
66
#ifdef FLOW123D_DEBUG_ASSERTS
67
68
/**
69
* Just quick hack to fix some unit tests.
70
* TODO:
71
* We should make better implementation, rather minimizing
72
* usage of macros. And make robust "system" part, that
73
* is MPI aware, but not MPI dependent.
74
*/
75
//#ifdef FLOW123D_DEBUG_ASSERTS_WITHOUT_MPI
76
//#define MPI_Comm_rank(A, B)
77
//#endif // FLOW123D_DEBUG_ASSERTS_WITHOUT_MPI
78
79
#define OLD_ASSERT(i,...) do {\
80
if (!(i)) {\
81
char msg[1024];\
82
sprintf( msg, __VA_ARGS__);\
83
int rank=-1;\
84
THROW( ExcAssertMsg() << EI_Message(std::string(msg)) << EI_MPI_Rank(rank) );\
85
}} while (0)
86
87
88
#define OLD_ASSERT_EQUAL( a, b) do {\
89
stringstream ss; ss << (a) << " != " << (b); \
90
OLD_ASSERT( ((a) == (b)), "Violated assert: %s == %s,\n observed: %s.\n",#a, #b, ss.str().c_str()); \
91
} while (0)
92
93
#define OLD_ASSERT_LESS( a, b) do {\
94
stringstream ss; ss << (a) << " >= " << (b); \
95
OLD_ASSERT( ((a) < (b)) , "Violated assert: %s < %s,\n observed: %s.\n",#a,#b, ss.str().c_str()); \
96
} while (0)
97
98
#define OLD_ASSERT_LE( a, b) do {\
99
stringstream ss; ss << (a) << " > " << (b); \
100
OLD_ASSERT( ((a) <= (b)) , "Violated assert: %s <= %s,\n observed: %s.\n",#a,#b, ss.str().c_str()); \
101
} while (0)
102
103
#define OLD_ASSERT_PTR( ptr ) do {\
104
OLD_ASSERT( ((ptr) != nullptr) , "Null pointer: %s\n", #ptr ); \
105
} while (0)
106
#else
107
108
#define OLD_ASSERT(...)
109
#define OLD_WARN_ASSERT(...)
110
#define OLD_ASSERT_EQUAL( a, b)
111
#define OLD_ASSERT_LESS( a, b)
112
#define OLD_ASSERT_LE( a, b)
113
#define OLD_ASSERT_PTR( ptr )
114
115
#endif
116
117
118
119
120
#ifdef FLOW123D_DEBUG_MESSAGES
121
122
/**
123
* Usage:
124
* DBGCOUT( << "xy" <<endl );
125
*/
126
#define DBGCOUT(...) do { std::cout << " DBG (" \
127
<< __FILE__ << ", " \
128
<< __func__ << ", " \
129
<< __LINE__ << ")" \
130
__VA_ARGS__; } while(0)
131
132
133
/**
134
* Usage:
135
* DBGVAR( arma::vec( "1 2 3" ) );
136
*/
137
#define DBGVAR( var ) DBGCOUT( << #var << " = " << var << endl )
138
139
#else
140
141
#define DBGCOUT(...)
142
#define DBGVAR(var)
143
144
#endif
145
146
147
148
149
/**
150
* These macros are necessary in classes that contain Input::Type::Abstract (PARENT macro)
151
* and in classes contain descendant of this Abstract (CHILD macro) if these descendants
152
* are initialized through methods of @p Input::Factory class.
153
*
154
* These macros are necessary for initializing of static variables in classes that contain
155
* descendants of parent Abstract.
156
*/
157
#define FLOW123D_FORCE_LINK_IN_CHILD(x) int force_link_##x = 0;
158
#define _TOKENPASTE(x, y) func_ ## x ## y // helper macro
159
#define _TOKENPASTE2(x, y) _TOKENPASTE(x, y) // helper macro
160
#define FLOW123D_FORCE_LINK_IN_PARENT(x) extern int force_link_##x; void _TOKENPASTE2(x, __LINE__)(void) { force_link_##x = 1; }
161
162
163
///@}
164
165
#endif // GLOBAL_DEFS_H
string.h
asserts.hh
Definitions of ASSERTS.
logger.hh
exc_common.hh
mpi.h
Generated by
1.8.11