debug.h
Go to the documentation of this file.
1 
17 #ifndef __Debug_H
18 #define __Debug_H
19 #include <iostream>
20 #include <fstream>
21 #include <ctime>
22 #include "aruco_export.h"
23 #include <map>
24 #include <string>
25 namespace aruco
26 {
27 
29 {
30 private:
31  static int level; // 0(no debug), 1 medium, 2 high
32  static bool isInited;
33 
34  static std::map<std::string, std::string> strings;
35 
36 public:
37  static void init();
38  static void setLevel(int l);
39  static int getLevel();
40 
41 
42 
43  static void addString(std::string &label, std::string &data);
44  static std::string getString(std::string &str);
45 
46 
47  static std::string getFileName(std::string filepath)
48  {
49  // go backwards until finding a separator or start
50  size_t i;
51  for (i = filepath.size() - 1; i != 0; i--)
52  {
53  if (filepath[i] == '\\' || filepath[i] == '/')
54  break;
55  }
56  std::string fn;
57  fn.reserve(filepath.size() - i);
58  for (size_t s = i; s < filepath.size(); s++)
59  fn.push_back(filepath[s]);
60  return fn;
61  }
62 
63 #ifdef WIN32
64 #define __func__ __FUNCTION__
65 #endif
66 };
67 
68 
69 // message print
70 #if (defined DEBUG || defined _DEBUG)
71 #define _debug_exec(level, x) \
72  { \
73  if (Debug::getLevel() >= level) \
74  { \
75  x \
76  } \
77  }
78 #define _debug_exec_(x) x
79 #ifndef WIN32
80 #define _debug_msg(x, level) \
81  { \
82  Debug::init(); \
83  if (Debug::getLevel() >= level) \
84  std::cout << "#" << Debug::getFileName(__FILE__) << ":" << __LINE__ << ":" \
85  << __func__ << "#" << x << std::endl; \
86  }
87 
88 #define _debug_msg_(x) \
89  { \
90  Debug::init(); \
91  if (Debug::getLevel() >= 5) \
92  std::cout << "#" << Debug::getFileName(__FILE__) << ":" << __LINE__ << ":" \
93  << __func__ << "#" << x << std::endl; \
94  }
95 
96 #else
97 #define _debug_msg(x, level) \
98  { \
99  Debug::init(); \
100  if (Debug::getLevel() >= level) \
101  std::cout << __func__ << ":" << Debug::getFileName(__FILE__) << ":" << __LINE__ \
102  << ": " << x << std::endl; \
103  }
104 
105 #define _debug_msg_(x) \
106  { \
107  Debug::init(); \
108  if (Debug::getLevel() >= 5) \
109  std::cout << __func__ << ":" << Debug::getFileName(__FILE__) << ":" << __LINE__ \
110  << ": " << x << std::endl; \
111  }
112 
113 #endif
114 
115 #else
116 #define _debug_msg(x, level)
117 #define _debug_msg_(x)
118 #define _debug_exec(level, x) ;
119 #define _debug_exec_(x) ;
120 
121 #endif
122 
123 
124 
125 } // namespace aruco
126 
127 #endif
aruco::Debug::level
static int level
Definition: debug.h:31
aruco_export.h
aruco::Debug::isInited
static bool isInited
Definition: debug.h:32
aruco::Debug::strings
static std::map< std::string, std::string > strings
Definition: debug.h:34
aruco::Debug
Definition: debug.h:28
ARUCO_EXPORT
#define ARUCO_EXPORT
Definition: aruco_export.h:30
aruco::Debug::getFileName
static std::string getFileName(std::string filepath)
Definition: debug.h:47
aruco
Definition: cameraparameters.h:24


aruco
Author(s): Rafael Muñoz Salinas , Bence Magyar
autogenerated on Sat Sep 23 2023 02:26:45