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 "../string.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;
60 public:
62
67
69
75 static bool auto_flush() noexcept;
80 static void auto_flush(bool auto_flush) noexcept;
81
85 static uint32 indent_level() noexcept;
89 static void indent_level(uint32 indent_level) noexcept;
90
94 static uint32 indent_size() noexcept;
98 static void indent_size(uint32 indent_size) noexcept;
99
104 static listener_collection& listeners() noexcept;
109 static void listeners(const listener_collection& listeners) noexcept;
110
116 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
117 static bool show_assert_dialog() noexcept;
123 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
124 static void show_assert_dialog(bool show_assert_dialog) noexcept;
125
129 static bool use_global_lock() noexcept;
133 static void use_global_lock(bool use_global_lock) noexcept;
135
137
144 static void cassert(bool condition);
148 static void cassert(bool condition, const xtd::string& message);
153 static void cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame);
158 static void cassert(bool condition, const xtd::string& message, const xtd::string& detail_message);
164 static void cassert(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame);
168 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame);
169
174 static void fail(const xtd::string& message) {
175 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
176 fail__(message);
177 #endif
178 }
184 static void fail(const xtd::string& message, const xtd::string& detail_message) {
185 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
186 fail__(message, detail_message);
187 #endif
188 }
189
191 static void flush() {
192 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
193 flush_();
194 #endif
195 }
196
198 static void indent() noexcept;
199
203 static void print(const xtd::string& message) {
204 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
205 write_line_(message);
206 #endif
207 }
212 template<typename ...args_t>
213 static void print(const xtd::string& format, args_t&& ... args) {
214 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
215 write_line_(xtd::string::format(format, args...));
216 #endif
217 }
219 template<typename ...args_t>
220 static void print(const char* format, args_t&& ... args) {
221 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
222 write_line_(xtd::string::format(format, args...));
223 #endif
224 }
226
230 static void trace_error(const xtd::string& message) {
231 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
232 trace_event_(trace_event_type::error, message);
233 #endif
234 }
239 template<typename ...objects_t>
240 static void trace_error(const xtd::string& message, const objects_t& ... args) {
241 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
242 trace_event_(trace_event_type::error, xtd::string::format(message, args...));
243 #endif
244 }
245
249 static void trace_information(const xtd::string& message) {
250 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
251 trace_event_(trace_event_type::information, message);
252 #endif
253 }
258 template<typename ...objects_t>
259 static void trace_information(const xtd::string& message, const objects_t& ... args) {
260 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
261 trace_event_(trace_event_type::information, xtd::string::format(message, args...));
262 #endif
263 }
264
268 static void trace_warning(const xtd::string& message) {
269 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
270 trace_event_(trace_event_type::warning, message);
271 #endif
272 }
277 template<typename ...objects_t>
278 static void trace_warning(const xtd::string& message, const objects_t& ... args) {
279 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
280 trace_event_(trace_event_type::warning, xtd::string::format(message, args...));
281 #endif
282 }
283
285 static void unindent() noexcept;
286
291 static void write(const xtd::string& message) {
292 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
293 write_(message);
294 #endif
295 }
300 template<typename object_t>
301 static void write(const object_t& message) {
302 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
303 write_(xtd::string::format("{}", message));
304 #endif
305 }
312 template<typename object_t>
313 static void write(const object_t& message, const xtd::string& category) {
314 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
315 write_(xtd::string::format("{}", message), category);
316 #endif
317 }
323 template<typename ...args_t>
324 static void write(const xtd::string& format, args_t&& ... args) {
325 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
326 write_(string::format(format, args...));
327 #endif
328 }
330 template<typename ...args_t>
331 static void write(const char* format, args_t&& ... args) {
332 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
333 write_(string::format(format, args...));
334 #endif
335 }
337
343 static void write_if(bool condition, const xtd::string& message) {
344 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
345 if (condition) write_(message);
346 #endif
347 }
348 template<typename object_t>
354 static void write_if(bool condition, const object_t& message) {
355 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
356 if (condition) write_(xtd::string::format("{}", message));
357 #endif
358 }
365 template<typename object_t>
366 static void write_if(bool condition, const object_t& message, const xtd::string& category) {
367 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
368 if (condition) write_(xtd::string::format("{}", message), category);
369 #endif
370 }
371
376 static void write_line() {
377 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
378 write_line_("");
379 #endif
380 }
385 static void write_line(const xtd::string& message) {
386 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
387 write_line_(message);
388 #endif
389 }
394 template<typename object_t>
395 static void write_line(const object_t& message) {
396 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
397 write_line_(xtd::string::format("{}", message));
398 #endif
399 }
406 template<typename object_t>
407 static void write_line(const object_t& message, const xtd::string& category) {
408 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
409 write_line_(xtd::string::format("{}", message), category);
410 #endif
411 }
416 template<typename ...args_t>
417 static void write_line(const xtd::string& format, args_t&& ... args) {
418 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
419 write_line_(string::format(format, args...));
420 #endif
421 }
423 template<typename ...args_t>
424 static void write_line(const char* format, args_t&& ... args) {
425 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
426 write_line_(string::format(format, args...));
427 #endif
428 }
430
436 static void write_line_if(bool condition, const xtd::string& message) {
437 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
438 if (condition) write_line_(message);
439 #endif
440 }
446 template<typename object_t>
447 static void write_line_if(bool condition, const object_t& message) {
448 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
449 if (condition) write_line_(message);
450 #endif
451 }
458 template<typename object_t>
459 static void write_line_if(bool condition, const object_t& message, const xtd::string& category) {
460 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
461 if (condition) write_line_(message, category);
462 #endif
463 }
464
466 static inline bool __should_aborted__(bool condition) {return __should_aborted__(condition, xtd::string::empty_string, csf_);}
467 static inline bool __should_aborted__(bool condition, const xtd::string& message) {return __should_aborted__(condition, message, csf_);}
468 static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, xtd::string::empty_string, stack_frame);}
469 static inline bool __should_aborted__(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, message, xtd::string::empty_string, stack_frame);}
470 static inline bool __should_aborted__(bool condition, const xtd::string& message, const xtd::string& detail_message) {return __should_aborted__(condition, message, detail_message, csf_);}
471 static inline bool __should_aborted__(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame) {
472 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
473 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
475 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
476 #endif
477 return false;
478 }
481
482 private:
483 friend trace;
485 static xtd::diagnostics::assert_dialog_result assert_dialog(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame);
486 static xtd::string assert_dialog_caption();
487 static bool internal_show_assert_dialog() noexcept;
488 static void fail__(const xtd::string& message);
489 static void fail__(const xtd::string& message, const xtd::string& detail_message);
490 static void flush_();
491 static void trace_event_(trace_event_type trace_event_type, const xtd::string& message);
492 static void write_(const xtd::string& message);
493 static void write_(const xtd::string& message, const xtd::string& category);
494 static void write_line_(const xtd::string& message);
495 static void write_line_(const xtd::string& message, const xtd::string& category);
496
497 inline static bool auto_flush_ = false;
498 inline static uint32 indent_level_ = 0;
499 inline static uint32 indent_size_ = 4;
500 static listener_collection& listeners_;
501 static xtd::string source_name_;
502 };
503 }
504}
505
529#define cassert_(...) \
530 add_last_arg_to_command_(cassert, (csf_), __VA_ARGS__)
Contains xtd::diagnostics::assert_dialog_result enum class.
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.h:124
Represents text as a sequence of character units.
Definition basic_string.h:79
static void write_if(bool condition, const object_t &message, const xtd::string &category)
Writes a category name and message to the trace listeners in the Listeners collection if a condition ...
Definition debug.h:366
static void trace_information(const xtd::string &message, const objects_t &... args)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition debug.h:259
static void indent() noexcept
Increases the current indent_level by one.
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition debug.h:376
static void write(const object_t &message, const xtd::string &category)
Writes a category name and message to the trace listeners in the listeners collection.
Definition debug.h:313
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:447
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:395
static void write(const xtd::string &format, args_t &&... args)
Writes a formatted string to the trace listeners in the listeners collection.
Definition debug.h:324
static bool auto_flush() noexcept
Gets whether xtd::diagnostics::debug::flush should be called on the xtd::diagnostics::debug::Listener...
static void trace_error(const xtd::string &message, const objects_t &... args)
Writes an error message to the trace listeners in the listeners collection using the specified array ...
Definition debug.h:240
static void write_line_if(bool condition, const object_t &message, const xtd::string &category)
Writes a category name and message followed by a line terminator to the trace listeners in the Listen...
Definition debug.h:459
static void fail(const xtd::string &message, const xtd::string &detail_message)
Emits an error message and a detailed error message.
Definition debug.h:184
static void write_line(const xtd::string &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition debug.h:385
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:354
static void print(const xtd::string &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition debug.h:213
static void trace_error(const xtd::string &message)
Writes an error message to the trace listeners in the Listeners collection using the specified messag...
Definition debug.h:230
static void trace_warning(const xtd::string &message)
Writes a warning message to the trace listeners in the listeners collection using the specified messa...
Definition debug.h:268
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition debug.h:301
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition debug.h:191
static void write_line(const xtd::string &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition debug.h:417
static void unindent() noexcept
Decreases the current indent_level by one.
static void trace_information(const xtd::string &message)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition debug.h:249
static void write_line(const object_t &message, const xtd::string &category)
Writes a category name and message followed by a line terminator to the trace listeners in the listen...
Definition debug.h:407
static void trace_warning(const xtd::string &message, const objects_t &... args)
Writes a warning message to the trace listeners in the listeners collection using the specified array...
Definition debug.h:278
static void write_if(bool condition, const xtd::string &message)
Writes a message to the trace listeners in the Listeners collection if a condition is true.
Definition debug.h:343
static void write_line_if(bool condition, const xtd::string &message)
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition debug.h:436
Provides a set of methods and properties that help you debug the execution of your code....
Definition debug.h:59
Provides the default output methods and behavior for tracing.
Definition default_trace_listener.h:33
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.h:40
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.h:29
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:35
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:114
Contains xtd::diagnostics::debugger class.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
#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
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.h:23
assert_dialog_result
Specifies identifiers to indicate the return value of an assert dialog box.
Definition assert_dialog_result.h:25
@ 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.