utils/debug.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 João Borrego
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
24 #ifndef _DEBUG_HH_
25 #define _DEBUG_HH_
26 
27 #include <iostream>
28 #include <string.h>
29 
31 #define VERBOSE
32 
34 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
35 
36 #ifdef VERBOSE
37 #define debugPrint(x) do { \
39  std::cout << "\033[1;32m" << x; \
40 } while (0)
41 #else
42 #define debugPrint(x) do {} while (0)
43 #endif
44 
45 #ifdef VERBOSE
46 #define debugPrintTrace(x) do { \
48  std::cout << "\033[1;33m" << \
49  "[Dbg] [" << __FILENAME__ << ":" << __LINE__ << ":" << __func__ << "] " << \
50  x << "\n";\
51 } while (0)
52 #else
53 #define debugPrintTrace(x) do {} while (0)
54 #endif
55 
56 #ifdef VERBOSE
57 #define errorPrintTrace(x) do { \
59  std::cerr << "\033[1;31m" << \
60  "[Err] [" << __FILENAME__ << ":" << __LINE__ << ":" << __func__ << "] " << \
61  x << "\n";\
62 } while (0)
63 #else
64 #define errorPrintTrace(x) do {} while (0)
65 #endif
66 
67 #endif