PandA-2024.02
dbgPrintHelper.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
47 #ifndef DBGPRINTHELPER_HPP
48 #define DBGPRINTHELPER_HPP
49 
50 #define NOUTPUT 0
51 
52 #include <iostream>
53 #include <string>
54 
59 #define OUTPUT_LEVEL_NONE 0
61 #define OUTPUT_LEVEL_MINIMUM 1
63 #define OUTPUT_LEVEL_VERBOSE 2
65 #define OUTPUT_LEVEL_PEDANTIC 3
67 #define OUTPUT_LEVEL_VERY_PEDANTIC 4
69 #define OUTPUT_LEVEL_VERY_VERY_PEDANTIC 5
71 
72 
77 #define DEBUG_LEVEL_NONE 0
79 #define DEBUG_LEVEL_MINIMUM 1
81 #define DEBUG_LEVEL_VERBOSE 2
83 #define DEBUG_LEVEL_PEDANTIC 3
85 #define DEBUG_LEVEL_VERY_PEDANTIC 4
87 #define DEBUG_LEVEL_PARANOIC 5
89 #define DEBUG_LEVEL_INFINITE 11
91 
93 
94 extern size_t indentation;
95 
96 extern std::ostream null_stream;
97 
99 extern std::string panda_message;
100 
101 // If we are producing a release, then no debug message will be printed at all,
102 // independently of the debug level chosen: all the debug instructions are evicted
103 // from the code, thus speeding up the execution.
104 #ifdef NDEBUG
105 
108 #define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex) void(0)
109 #define PRINT_DBG_STRING(dbgLevel, curDbgLevel, mex) void(0)
110 #define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex) void(0)
111 
112 #else
113 
120 #define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex) \
121  (((dbgLevel) <= (curDbgLevel)) ? std::cerr << mex << std::endl : std::cerr)
122 
132 #define PRINT_DBG_STRING(dbgLevel, curDbgLevel, mex) (((dbgLevel) <= (curDbgLevel)) ? std::cerr << mex : std::cerr)
133 
140 #define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex) \
141  (((dbgLevel) <= (curDbgLevel)) ? \
142  (panda_message = mex, \
143  (std::string(panda_message) == "-->") ? \
144  (null_stream << (indentation += 2)) : \
145  ((std::string(panda_message).substr(0, 3) == "-->") ? \
146  (std::cerr << std::string(indentation += 2, ' ') << std::string(panda_message).substr(3) \
147  << std::endl) : \
148  ((std::string(panda_message).substr(0, 3) == "---") ? \
149  (std::cerr << std::string(indentation + 2, ' ') << std::string(panda_message).substr(3) \
150  << std::endl) : \
151  ((std::string(panda_message) == "<--") ? \
152  (null_stream << (indentation -= 2)) : \
153  ((std::string(panda_message).substr(0, 3) == "<--") ? \
154  (std::cerr << std::string(indentation, ' ') << std::string(panda_message).substr(3) \
155  << std::endl, \
156  null_stream << (indentation -= 2)) : \
157  (std::cerr << std::string(indentation, ' ') << panda_message << std::endl)))))) : \
158  (std::cerr))
159 
160 #endif
161 
162 #if NOUTPUT
163 
164 #define INDENT_OUT_MEX(profLevel, curprofLevel, mex) (void(0))
165 #define PRINT_OUT_MEX(profLevel, curprofLevel, mex) (void(0))
166 #define PRINT_OUT_STRING(profLevel, curprofLevel, mex) (void(0))
167 
168 #else
169 
170 #define INDENT_OUT_MEX(outLevel, curOutLevel, mex) \
171  (((outLevel) <= (curOutLevel)) ? \
172  (panda_message = mex, \
173  (std::string(panda_message) == "-->") ? \
174  (null_stream << (indentation += 2)) : \
175  ((std::string(panda_message).substr(0, 3) == "-->") ? \
176  (std::cerr << std::string(indentation += 2, ' ') << std::string(panda_message).substr(3) \
177  << std::endl) : \
178  ((std::string(panda_message).substr(0, 3) == "---") ? \
179  (std::cerr << std::string(indentation + 2, ' ') << std::string(panda_message).substr(3) \
180  << std::endl) : \
181  ((std::string(panda_message) == "<--") ? \
182  (null_stream << (indentation -= 2)) : \
183  ((std::string(panda_message).substr(0, 3) == "<--") ? \
184  (std::cerr << std::string(indentation, ' ') << std::string(panda_message).substr(3) \
185  << std::endl, \
186  null_stream << (indentation -= 2)) : \
187  (std::cerr << std::string(indentation, ' ') << panda_message << std::endl)))))) : \
188  (std::cerr))
189 
190 #define PRINT_OUT_MEX(profLevel, curprofLevel, mex) \
191  (((profLevel) <= (curprofLevel)) ? std::cerr << mex << std::endl : std::cerr)
192 
193 #define PRINT_OUT_STRING(profLevel, curprofLevel, mex) (((profLevel) <= (curprofLevel)) ? std::cerr << mex : std::cerr)
194 
195 #endif
196 
197 #define PRINT_MSG(mex) std::cerr << mex << std::endl
198 #define PRINT_STRING(mex) std::cerr << mex
199 
200 #endif
std::string panda_message
This is the message to be printed.
std::ostream null_stream
size_t indentation
The current indentation for debug messages.

Generated on Mon Feb 12 2024 13:02:56 for PandA-2024.02 by doxygen 1.8.13