Flow123d  master-f44eb46
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_PERMANENT
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 
67 #ifdef FLOW123D_DEBUG_MESSAGES
68 
69 /**
70  * Usage:
71  * DBGCOUT( << "xy" <<endl );
72  */
73 #define DBGCOUT(...) do { std::cout << " DBG (" \
74  << __FILE__ << ", " \
75  << __func__ << ", " \
76  << __LINE__ << ")" \
77  __VA_ARGS__; } while(0)
78 
79 
80 /**
81  * Usage:
82  * DBGVAR( arma::vec( "1 2 3" ) );
83  */
84 #define DBGVAR( var ) DBGCOUT( << #var << " = " << var << endl )
85 
86 #else
87 
88 #define DBGCOUT(...)
89 #define DBGVAR(var)
90 
91 #endif
92 
93 
94 
95 
96 /**
97  * These macros are necessary in classes that contain Input::Type::Abstract (PARENT macro)
98  * and in classes contain descendant of this Abstract (CHILD macro) if these descendants
99  * are initialized through methods of @p Input::Factory class.
100  *
101  * These macros are necessary for initializing of static variables in classes that contain
102  * descendants of parent Abstract.
103  */
104 #define FLOW123D_FORCE_LINK_IN_CHILD(x) int force_link_##x = 0;
105 #define _TOKENPASTE(x, y) func_ ## x ## y // helper macro
106 #define _TOKENPASTE2(x, y) _TOKENPASTE(x, y) // helper macro
107 #define FLOW123D_FORCE_LINK_IN_PARENT(x) extern int force_link_##x; void _TOKENPASTE2(x, __LINE__)(void) { force_link_##x = 1; }
108 
109 
110 ///@}
111 
112 #endif // GLOBAL_DEFS_H
Definitions of ASSERTS.