R-Type
R-Type project
Debug.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** KapEngine
4 ** File description:
5 ** Debug
6 */
7 
8 #ifndef DEBUG_HPP_
9 #define DEBUG_HPP_
10 
11 #include <string>
12 #include <ctime>
13 #include <iostream>
14 
15 #if KAPENGINE_THREAD_ACTIVE
16  #if KAPENGINE_BETA_ACTIVE
17  #include <mutex>
18  #endif
19 #endif
20 
21 #include "KapEngineSettings.hpp"
22 #include "Profiler/KapProfiler.hpp"
23 
24 namespace KapEngine {
25  class Debug {
26  public:
27 
31  static void log(std::string _msg, std::string prefix = "");
32 
33  static void log(char const* _msg, std::string prefix = "") {
34  PROFILER_FUNC_START();
35  log(std::string(_msg), prefix);
36  PROFILER_FUNC_END();
37  }
38 
39  static void log(const char *_msg, const char *fileName, int const line) {
40  PROFILER_FUNC_START();
41  log(std::string(_msg), fileName, line);
42  PROFILER_FUNC_END();
43  }
44 
45  static void log(std::string const& _msg, const char *fileName, int const line) {
46  PROFILER_FUNC_START();
47  log(std::string(_msg), "[" + colorGreen() + std::string(fileName) + colorNone() + " " + colorBlue() + "l. " + std::to_string(line) + colorNone() + "]");
48  PROFILER_FUNC_END();
49  }
50 
54  static void warning(std::string _msg, std::string prefix = "");
55 
56  static void warning(char const* _msg, std::string prefix = "") {
57  PROFILER_FUNC_START();
58  warning(std::string(_msg), prefix);
59  PROFILER_FUNC_END();
60  }
61 
62  static void warning(const char *_msg, const char *fileName, int const line) {
63  PROFILER_FUNC_START();
64  warning(std::string(_msg), fileName, line);
65  PROFILER_FUNC_END();
66  }
67 
68  static void warning(std::string const& _msg, const char *fileName, int const line) {
69  PROFILER_FUNC_START();
70  warning(std::string(_msg), "[" + colorYellow() + std::string(fileName) + colorNone() + " " + colorBlue() + "l. " + std::to_string(line) + colorNone() + "]");
71  PROFILER_FUNC_END();
72  }
76  static void error(std::string _msg, std::string prefix = "");
77 
78  static void error(char const* _msg, std::string prefix = "") {
79  PROFILER_FUNC_START();
80  error(std::string(_msg), prefix);
81  PROFILER_FUNC_END();
82  }
83 
84  static void error(const char *_msg, const char *fileName, int const line) {
85  PROFILER_FUNC_START();
86  error(std::string(_msg), fileName, line);
87  PROFILER_FUNC_END();
88  }
89 
90  static void error(std::string const& _msg, const char *fileName, int const line) {
91  PROFILER_FUNC_START();
92  error(std::string(_msg), "[" + colorRed() + std::string(fileName) + colorNone() + " " + colorBlue() + "l. " + std::to_string(line) + colorNone() + "]");
93  PROFILER_FUNC_END();
94  }
95 
96  static std::string colorNone() {
97  PROFILER_FUNC_START();
98  PROFILER_FUNC_END();
99  #ifdef __WINDOWS__
100  return "";
101  #else
102  return "\e[0m";
103  #endif
104  }
105 
106  static std::string colorRed() {
107  PROFILER_FUNC_START();
108  PROFILER_FUNC_END();
109  #ifdef __WINDOWS__
110  return "";
111  #else
112  return "\e[31m";
113  #endif
114  }
115 
116  static std::string colorYellow() {
117  PROFILER_FUNC_START();
118  PROFILER_FUNC_END();
119  #ifdef __WINDOWS__
120  return "";
121  #else
122  return "\e[33m";
123  #endif
124  }
125 
126  static std::string colorWhite() {
127  PROFILER_FUNC_START();
128  PROFILER_FUNC_END();
129  #ifdef __WINDOWS__
130  return "";
131  #else
132  return "\e[97m";
133  #endif
134  }
135 
136  static std::string colorBlue() {
137  PROFILER_FUNC_START();
138  PROFILER_FUNC_END();
139  #ifdef __WINDOWS__
140  return "";
141  #else
142  return "\e[34m";
143  #endif
144  }
145 
146  static std::string colorBlack() {
147  PROFILER_FUNC_START();
148  PROFILER_FUNC_END();
149  #ifdef __WINDOWS__
150  return "";
151  #else
152  return "\e[30m";
153  #endif
154  }
155 
156  static std::string colorGreen() {
157  PROFILER_FUNC_START();
158  PROFILER_FUNC_END();
159  #ifdef __WINDOWS__
160  return "";
161  #else
162  return "\e[32m";
163  #endif
164  }
165 
166  static std::string colorMagenta() {
167  PROFILER_FUNC_START();
168  PROFILER_FUNC_END();
169  #ifdef __WINDOWS__
170  return "";
171  #else
172  return "\e[35m";
173  #endif
174  }
175 
176  static std::string colorCyan() {
177  PROFILER_FUNC_START();
178  PROFILER_FUNC_END();
179  #ifdef __WINDOWS__
180  return "";
181  #else
182  return "\e[36m";
183  #endif
184  }
185 
186  static std::string colorBackgroundDefault() {
187  PROFILER_FUNC_START();
188  PROFILER_FUNC_END();
189  #ifdef __WINDOWS__
190  return "";
191  #else
192  return "\e[49m";
193  #endif
194  }
195 
196  static std::string colorBackgroundRed() {
197  PROFILER_FUNC_START();
198  PROFILER_FUNC_END();
199  #ifdef __WINDOWS__
200  return "";
201  #else
202  return "\e[101m";
203  #endif
204  }
205 
206  static std::string colorBackgroundYellow() {
207  PROFILER_FUNC_START();
208  PROFILER_FUNC_END();
209  #ifdef __WINDOWS__
210  return "";
211  #else
212  return "\e[103m";
213  #endif
214  }
215 
216  static std::string colorBackgroundWhite() {
217  PROFILER_FUNC_START();
218  PROFILER_FUNC_END();
219  #ifdef __WINDOWS__
220  return "";
221  #else
222  return "\e[107m";
223  #endif
224  }
225 
226  static std::string colorBackgroundBlue() {
227  PROFILER_FUNC_START();
228  PROFILER_FUNC_END();
229  #ifdef __WINDOWS__
230  return "";
231  #else
232  return "\e[104m";
233  #endif
234  }
235 
236  static std::string colorBackgroundBlack() {
237  PROFILER_FUNC_START();
238  PROFILER_FUNC_END();
239  #ifdef __WINDOWS__
240  return "";
241  #else
242  return "\e[40m";
243  #endif
244  }
245 
246  static std::string colorBackgroundGreen() {
247  PROFILER_FUNC_START();
248  PROFILER_FUNC_END();
249  #ifdef __WINDOWS__
250  return "";
251  #else
252  return "\e[102m";
253  #endif
254  }
255 
256  static std::string colorBackgroundMagenta() {
257  PROFILER_FUNC_START();
258  PROFILER_FUNC_END();
259  #ifdef __WINDOWS__
260  return "";
261  #else
262  return "\e[105m";
263  #endif
264  }
265 
266  static std::string colorBackgroundCyan() {
267  PROFILER_FUNC_START();
268  PROFILER_FUNC_END();
269  #ifdef __WINDOWS__
270  return "";
271  #else
272  return "\e[106m";
273  #endif
274  }
275 
276  static std::string boldStyle() {
277  PROFILER_FUNC_START();
278  PROFILER_FUNC_END();
279  #ifdef __WINDOWS__
280  return "";
281  #else
282  return "\e[1m";
283  #endif
284  }
285 
286  #if KAPENGINE_THREAD_ACTIVE
287  #if KAPENGINE_BETA_ACTIVE
288  static std::mutex logMutex;
289  #endif
290  #endif
291 
292  protected:
293  private:
294 
295  static std::string __getCDate() {
296  PROFILER_FUNC_START();
297  // current date/time based on current system
298  time_t now = std::time(0);
299 
300  // convert now to string form
301  char* dt = std::ctime(&now);
302  std::string _str(dt);
303  _str.pop_back();
304  PROFILER_FUNC_END();
305  return _str;
306  }
307  };
308 }
309 
310 #endif /* !DEBUG_HPP_ */
KapEngine::Debug::log
static void log(std::string _msg, std::string prefix="")
display a simple message
Definition: Debug.cpp:16
KapEngine::Debug
Definition: Debug.hpp:25
KapEngine::Debug::warning
static void warning(std::string _msg, std::string prefix="")
display a warning message
Definition: Debug.cpp:31
KapEngine
main namespace
Definition: Component.hpp:17
KapEngine::Debug::error
static void error(std::string _msg, std::string prefix="")
display an error message
Definition: Debug.cpp:45