xtd 0.2.0
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
4#pragma once
5#include <cstdint>
6#include <cstdlib>
7#include "../add_last_arg_to_command.h"
8#include "../core_export.h"
9#include "../environment.h"
10#include "../static.h"
11#include "../ustring.h"
13#include "debugger.h"
14#include "stack_trace.h"
16
18namespace xtd {
20 namespace forms {
21 class assert_dialog;
22 }
24
26 namespace diagnostics {
28 class trace;
58 public:
60
65
67
73 static bool auto_flush() noexcept;
78 static void auto_flush(bool auto_flush) noexcept;
79
83 static uint32 indent_level() noexcept;
87 static void indent_level(uint32 indent_level) noexcept;
88
92 static uint32 indent_size() noexcept;
96 static void indent_size(uint32 indent_size) noexcept;
97
102 static listener_collection& listeners() noexcept;
107 static void listeners(const listener_collection& listeners) noexcept;
108
114 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
115 static bool show_assert_dialog() noexcept;
121 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
122 static void show_assert_dialog(bool show_assert_dialog) noexcept;
123
127 static bool use_global_lock() noexcept;
131 static void use_global_lock(bool use_global_lock) noexcept;
133
135
142 static void cassert(bool condition);
146 static void cassert(bool condition, const xtd::ustring& message);
151 static void cassert(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame);
156 static void cassert(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message);
162 static void cassert(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message, const xtd::diagnostics::stack_frame& stack_frame);
166 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame);
167
172 static void fail(const xtd::ustring& message) {
173 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
174 fail__(message);
175 #endif
176 }
182 static void fail(const xtd::ustring& message, const xtd::ustring& detail_message) {
183 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
184 fail__(message, detail_message);
185 #endif
186 }
187
189 static void flush() {
190 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
191 flush_();
192 #endif
193 }
194
196 static void indent() noexcept;
197
201 static void print(const xtd::ustring& message) {
202 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
203 write_line_(message);
204 #endif
205 }
210 template<typename ...args_t>
211 static void print(const xtd::ustring& format, args_t&& ... args) {
212 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
213 write_line_(xtd::ustring::format(format, args...));
214 #endif
215 }
217 template<typename ...args_t>
218 static void print(const char* format, args_t&& ... args) {
219 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
220 write_line_(xtd::ustring::format(format, args...));
221 #endif
222 }
224
228 static void trace_error(const xtd::ustring& message) {
229 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
230 trace_event_(trace_event_type::error, message);
231 #endif
232 }
237 template<typename ...objects_t>
238 static void trace_error(const xtd::ustring& message, const objects_t& ... args) {
239 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
240 trace_event_(trace_event_type::error, xtd::ustring::format(message, args...));
241 #endif
242 }
243
247 static void trace_information(const xtd::ustring& message) {
248 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
249 trace_event_(trace_event_type::information, message);
250 #endif
251 }
256 template<typename ...objects_t>
257 static void trace_information(const xtd::ustring& message, const objects_t& ... args) {
258 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
259 trace_event_(trace_event_type::information, xtd::ustring::format(message, args...));
260 #endif
261 }
262
266 static void trace_warning(const xtd::ustring& message) {
267 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
268 trace_event_(trace_event_type::warning, message);
269 #endif
270 }
275 template<typename ...objects_t>
276 static void trace_warning(const xtd::ustring& message, const objects_t& ... args) {
277 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
278 trace_event_(trace_event_type::warning, xtd::ustring::format(message, args...));
279 #endif
280 }
281
283 static void unindent() noexcept;
284
289 static void write(const xtd::ustring& message) {
290 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
291 write_(message);
292 #endif
293 }
298 template<typename object_t>
299 static void write(const object_t& message) {
300 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
301 write_(xtd::ustring::format("{}", message));
302 #endif
303 }
310 template<typename object_t>
311 static void write(const object_t& message, const xtd::ustring& category) {
312 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
313 write_(xtd::ustring::format("{}", message), category);
314 #endif
315 }
321 template<typename ...args_t>
322 static void write(const xtd::ustring& format, args_t&& ... args) {
323 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
324 write_(ustring::format(format, args...));
325 #endif
326 }
328 template<typename ...args_t>
329 static void write(const char* format, args_t&& ... args) {
330 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
331 write_(ustring::format(format, args...));
332 #endif
333 }
335
341 static void write_if(bool condition, const xtd::ustring& message) {
342 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
343 if (condition) write_(message);
344 #endif
345 }
346 template<typename object_t>
352 static void write_if(bool condition, const object_t& message) {
353 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
354 if (condition) write_(xtd::ustring::format("{}", message));
355 #endif
356 }
363 template<typename object_t>
364 static void write_if(bool condition, const object_t& message, const xtd::ustring& category) {
365 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
366 if (condition) write_(xtd::ustring::format("{}", message), category);
367 #endif
368 }
369
374 static void write_line() {
375 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
376 write_line_("");
377 #endif
378 }
383 static void write_line(const xtd::ustring& message) {
384 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
385 write_line_(message);
386 #endif
387 }
392 template<typename object_t>
393 static void write_line(const object_t& message) {
394 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
395 write_line_(xtd::ustring::format("{}", message));
396 #endif
397 }
404 template<typename object_t>
405 static void write_line(const object_t& message, const xtd::ustring& category) {
406 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
407 write_line_(xtd::ustring::format("{}", message), category);
408 #endif
409 }
414 template<typename ...args_t>
415 static void write_line(const xtd::ustring& format, args_t&& ... args) {
416 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
417 write_line_(ustring::format(format, args...));
418 #endif
419 }
421 template<typename ...args_t>
422 static void write_line(const char* format, args_t&& ... args) {
423 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
424 write_line_(ustring::format(format, args...));
425 #endif
426 }
428
434 static void write_line_if(bool condition, const xtd::ustring& message) {
435 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
436 if (condition) write_line_(message);
437 #endif
438 }
444 template<typename object_t>
445 static void write_line_if(bool condition, const object_t& message) {
446 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
447 if (condition) write_line_(message);
448 #endif
449 }
456 template<typename object_t>
457 static void write_line_if(bool condition, const object_t& message, const xtd::ustring& category) {
458 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
459 if (condition) write_line_(message, category);
460 #endif
461 }
462
464 static inline bool __should_aborted__(bool condition) {return __should_aborted__(condition, "", csf_);}
465 static inline bool __should_aborted__(bool condition, const xtd::ustring& message) {return __should_aborted__(condition, message, csf_);}
466 static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, "", stack_frame);}
467 static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, message, "", stack_frame);}
468 static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message) {return __should_aborted__(condition, message, detail_message, csf_);}
469 static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message, const xtd::diagnostics::stack_frame& stack_frame) {
470 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
471 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
473 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
474 #endif
475 return false;
476 }
479
480 private:
481 friend trace;
483 static xtd::diagnostics::assert_dialog_result assert_dialog(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message, const xtd::diagnostics::stack_frame& stack_frame);
484 static xtd::ustring assert_dialog_caption();
485 static bool internal_show_assert_dialog() noexcept;
486 static void fail__(const xtd::ustring& message);
487 static void fail__(const xtd::ustring& message, const xtd::ustring& detail_message);
488 static void flush_();
489 static void trace_event_(trace_event_type trace_event_type, const xtd::ustring& message);
490 static void write_(const xtd::ustring& message);
491 static void write_(const xtd::ustring& message, const xtd::ustring& category);
492 static void write_line_(const xtd::ustring& message);
493 static void write_line_(const xtd::ustring& message, const xtd::ustring& category);
494
495 inline static bool auto_flush_ = false;
496 inline static uint32 indent_level_ = 0;
497 inline static uint32 indent_size_ = 4;
498 static listener_collection& listeners_;
499 static xtd::ustring source_name_;
500 };
501 }
502}
503
525#define cassert_(...) \
526 add_last_arg_to_command_(cassert, (csf_), __VA_ARGS__)
Contains xtd::diagnostics::assert_dialog_result enum class.
Provides a set of methods and properties that help you debug the execution of your code....
Definition debug.h:57
static void write_if(bool condition, const xtd::ustring &message)
Writes a message to the trace listeners in the Listeners collection if a condition is true.
Definition debug.h:341
static void write_line(const object_t &message, const xtd::ustring &category)
Writes a category name and message followed by a line terminator to the trace listeners in the listen...
Definition debug.h:405
static void trace_information(const xtd::ustring &message)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition debug.h:247
static void write_line_if(bool condition, const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition debug.h:434
static void write_line_if(bool condition, const object_t &message, const xtd::ustring &category)
Writes a category name and message followed by a line terminator to the trace listeners in the Listen...
Definition debug.h:457
static void indent() noexcept
Increases the current indent_level by one.
static void print(const xtd::ustring &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition debug.h:211
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition debug.h:374
static void trace_error(const xtd::ustring &message)
Writes an error message to the trace listeners in the Listeners collection using the specified messag...
Definition debug.h:228
static void trace_information(const xtd::ustring &message, const objects_t &... args)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition debug.h:257
static void write_line_if(bool condition, const object_t &message)
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition debug.h:445
static void write_line(const object_t &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition debug.h:393
static void write(const xtd::ustring &format, args_t &&... args)
Writes a formatted string to the trace listeners in the listeners collection.
Definition debug.h:322
static bool auto_flush() noexcept
Gets whether xtd::diagnostics::debug::flush should be called on the xtd::diagnostics::debug::Listener...
static void trace_warning(const xtd::ustring &message, const objects_t &... args)
Writes a warning message to the trace listeners in the listeners collection using the specified array...
Definition debug.h:276
static void write_if(bool condition, const object_t &message, const xtd::ustring &category)
Writes a category name and message to the trace listeners in the Listeners collection if a condition ...
Definition debug.h:364
static void trace_warning(const xtd::ustring &message)
Writes a warning message to the trace listeners in the listeners collection using the specified messa...
Definition debug.h:266
static void write_if(bool condition, const object_t &message)
Writes a message to the trace listeners in the Listeners collection if a condition is true.
Definition debug.h:352
static void write_line(const xtd::ustring &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition debug.h:415
static void write(const object_t &message, const xtd::ustring &category)
Writes a category name and message to the trace listeners in the listeners collection.
Definition debug.h:311
static void write_line(const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition debug.h:383
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition debug.h:299
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition debug.h:189
static void trace_error(const xtd::ustring &message, const objects_t &... args)
Writes an error message to the trace listeners in the listeners collection using the specified array ...
Definition debug.h:238
static void unindent() noexcept
Decreases the current indent_level by one.
static void fail(const xtd::ustring &message, const xtd::ustring &detail_message)
Emits an error message and a detailed error message.
Definition debug.h:182
Provides the default output methods and behavior for tracing.
Definition default_trace_listener.h:31
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.h:37
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.h:27
static void exit()
Terminates this process and returns an exit code to the operating system.
Represents a common dialog box that displays assert dialog.
Definition assert_dialog.h:33
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:110
Contains xtd::diagnostics::debugger class.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:1131
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define core_export_
Define shared library export.
Definition core_export.h:13
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition types.h:241
assert_dialog_result
Specifies identifiers to indicate the return value of an assert dialog box.
Definition assert_dialog_result.h:23
@ retry
The assert dialog return value is Retry (usually sent from a button labeled Retry).
@ abort
The assert dialog return value is Abort (usually sent from a button labeled Abort).
@ print
The PRINT key.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::diagnostics::stack_trace class.
Contains xtd::diagnostics::trace_listener_collection class.