xtd 1.0.0
Loading...
Searching...
No Matches
debug.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "../core_export.hpp"
7#include "../environment.hpp"
8#include "../static.hpp"
9#include "../string.hpp"
11#include "debug_break.hpp"
12#include "debugger.hpp"
13#include "stack_trace.hpp"
15#include <cassert>
16
18#if defined(assert)
19#undef assert
20#endif
22
24namespace xtd {
26 namespace forms {
27 class assert_dialog;
28 }
30
32 namespace diagnostics {
34 class trace;
66 public:
68
73
75
81 [[nodiscard]] static auto auto_flush() noexcept -> bool;
86 static auto auto_flush(bool auto_flush) noexcept -> void;
87
91 [[nodiscard]] static auto indent_level() noexcept -> xtd::uint32;
95 static auto indent_level(xtd::uint32 indent_level) noexcept -> void;
96
100 [[nodiscard]] static auto indent_size() noexcept -> xtd::uint32;
104 static auto indent_size(xtd::uint32 indent_size) noexcept -> void;
105
110 [[nodiscard]] static auto listeners() -> listener_collection&;
115 static auto listeners(const listener_collection& listeners) -> void;
116
120 [[nodiscard]] static auto use_global_lock() noexcept -> bool;
124 static auto use_global_lock(bool use_global_lock) noexcept -> void;
126
128
133 static auto assert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
134 #if DEBUG
135 if (__should_aborted__(stack_frame, condition, string::empty_string)) debug_break_();
136 #endif
137 }
138
142 static auto assert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
143 #if DEBUG
144 if (__should_aborted__(stack_frame, condition, message)) debug_break_();
145 #endif
146 }
147
152 static auto assert(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
153 #if DEBUG
154 if (__should_aborted__(stack_frame, condition, message, detail_message)) debug_break_();
155 #endif
156 }
157
162 [[deprecated("Use xtd::diagnostics::debug::assert method - Will be removed in version 1.2.0.)")]]
164 #if DEBUG
165 if (__should_aborted__(stack_frame, condition, string::empty_string)) debug_break_();
166 #endif
167 }
168
173 [[deprecated("Use xtd::diagnostics::debug::assert method - Will be removed in version 1.2.0.)")]]
174 static auto cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
175 #if DEBUG
176 if (__should_aborted__(stack_frame, condition, message)) debug_break_();
177 #endif
178 }
179
185 [[deprecated("Use xtd::diagnostics::debug::assert method - Will be removed in version 1.2.0.)")]]
186 static auto cassert(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
187 #if DEBUG
188 if (__should_aborted__(stack_frame, condition, message, detail_message)) debug_break_();
189 #endif
190 }
191
196 static auto fail(const xtd::string& message) -> void {
197 #if DEBUG
198 fail__(message);
199 #endif
200 }
201
206 static auto fail(const xtd::string& message, const xtd::string& detail_message) -> void {
207 #if DEBUG
208 fail__(message, detail_message);
209 #endif
210 }
211
213 static auto flush() -> void {
214 #if DEBUG
215 flush_();
216 #endif
217 }
218
220 static auto indent() noexcept -> void;
221
225 static auto print(const xtd::string& message) -> void {
226 #if DEBUG
227 write_line_(message);
228 #endif
229 }
230
234 template<typename ...args_t>
235 static auto print(const xtd::string& format, args_t&& ... args) -> void {
236 #if DEBUG
237 write_line_(xtd::string::format(format, args...));
238 #endif
239 }
240
241 template<typename ...args_t>
242 static auto print(const char* format, args_t&& ... args) -> void {
243 #if DEBUG
244 write_line_(xtd::string::format(format, args...));
245 #endif
246 }
248
252 static auto trace_error(const xtd::string& message) -> void {
253 #if DEBUG
254 trace_event_(xtd::diagnostics::trace_event_type::error, message);
255 #endif
256 }
257
261 template<typename ...objects_t>
262 static auto trace_error(const xtd::string& message, const objects_t& ... args) -> void {
263 #if DEBUG
264 trace_event_(xtd::diagnostics::trace_event_type::error, xtd::string::format(message, args...));
265 #endif
266 }
267
271 static auto trace_information(const xtd::string& message) -> void {
272 #if DEBUG
274 #endif
275 }
276
280 template<typename ...objects_t>
281 static auto trace_information(const xtd::string& message, const objects_t& ... args) -> void {
282 #if DEBUG
284 #endif
285 }
286
290 static auto trace_warning(const xtd::string& message) -> void {
291 #if DEBUG
292 trace_event_(xtd::diagnostics::trace_event_type::warning, message);
293 #endif
294 }
295
299 template<typename ...objects_t>
300 static auto trace_warning(const xtd::string& message, const objects_t& ... args) -> void {
301 #if DEBUG
303 #endif
304 }
305
307 static auto unindent() noexcept -> void;
308
313 static auto write(const xtd::string& message) -> void {
314 #if DEBUG
315 write_(message);
316 #endif
317 }
318
322 template<typename object_t>
323 static auto write(const object_t& message) -> void {
324 #if DEBUG
325 write_(xtd::string::format("{}", message));
326 #endif
327 }
328
334 template<typename object_t>
335 static auto write(const object_t& message, const xtd::string& category) -> void {
336 #if DEBUG
337 write_(xtd::string::format("{}", message), category);
338 #endif
339 }
340
345 template<typename ...args_t>
346 static auto write(const xtd::string& format, args_t&& ... args) -> void {
347 #if DEBUG
348 write_(xtd::string::format(format, args...));
349 #endif
350 }
351
352 template<typename ...args_t>
353 static auto write(const char* format, args_t&& ... args) -> void {
354 #if DEBUG
355 write_(xtd::string::format(format, args...));
356 #endif
357 }
359
365 static auto write_if(bool condition, const xtd::string& message) -> void {
366 #if DEBUG
367 if (condition) write_(message);
368 #endif
369 }
370
375 template<typename object_t>
376 static auto write_if(bool condition, const object_t& message) -> void {
377 #if DEBUG
378 if (condition) write_(xtd::string::format("{}", message));
379 #endif
380 }
381
387 template<typename object_t>
388 static auto write_if(bool condition, const object_t& message, const xtd::string& category) -> void {
389 #if DEBUG
390 if (condition) write_(xtd::string::format("{}", message), category);
391 #endif
392 }
393
398 static auto write_line() -> void {
399 #if DEBUG
400 write_line_("");
401 #endif
402 }
403
407 static auto write_line(const xtd::string& message) -> void {
408 #if DEBUG
409 write_line_(message);
410 #endif
411 }
412
416 template<typename object_t>
417 static auto write_line(const object_t& message) -> void {
418 #if DEBUG
419 write_line_(xtd::string::format("{}", message));
420 #endif
421 }
422
428 template<typename object_t>
429 static auto write_line(const object_t& message, const xtd::string& category) -> void {
430 #if DEBUG
431 write_line_(xtd::string::format("{}", message), category);
432 #endif
433 }
434
438 template<typename ...args_t>
439 static auto write_line(const xtd::string& format, args_t&& ... args) -> void {
440 #if DEBUG
441 write_line_(xtd::string::format(format, args...));
442 #endif
443 }
444
445 template<typename ...args_t>
446 static auto write_line(const char* format, args_t&& ... args) -> void {
447 #if DEBUG
448 write_line_(xtd::string::format(format, args...));
449 #endif
450 }
452
458 static auto write_line_if(bool condition, const xtd::string& message) -> void {
459 #if DEBUG
460 if (condition) write_line_(message);
461 #endif
462 }
463
468 template<typename object_t>
469 static auto write_line_if(bool condition, const object_t& message) -> void {
470 #if DEBUG
471 if (condition) write_line_(message);
472 #endif
473 }
474
480 template<typename object_t>
481 static auto write_line_if(bool condition, const object_t& message, const xtd::string& category) -> void {
482 #if DEBUG
483 if (condition) write_line_(message, category);
484 #endif
485 }
486
487
489 static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition) -> bool {return __should_aborted__(stack_frame, condition, xtd::string::empty_string);}
490 static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message) -> bool {return __should_aborted__(stack_frame, condition, message, xtd::string::empty_string);}
491 static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message, const xtd::string& detail_message) -> bool {
492 #if DEBUG
493 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
495 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
496 #endif
497 return false;
498 }
500
502
509 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 1.2.0.")]]
510 [[nodiscard]] static auto show_assert_dialog() noexcept -> bool;
516 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 1.2.0.")]]
517 static auto show_assert_dialog(bool show_assert_dialog) noexcept -> void;
519
520 private:
521 friend trace;
522 friend xtd::forms::assert_dialog;
523 static auto assert_dialog(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame) -> xtd::diagnostics::assert_dialog_result;
524 static auto assert_dialog_caption() -> xtd::string;
525 static auto internal_show_assert_dialog() noexcept -> bool;
526 static auto fail__(const xtd::string& message) -> void;
527 static auto fail__(const xtd::string& message, const xtd::string& detail_message) -> void;
528 static auto flush_() -> void;
529 static auto trace_event_(xtd::diagnostics::trace_event_type trace_event_type, const xtd::string& message) -> void;
530 static auto write_(const xtd::string& message) -> void;
531 static auto write_(const xtd::string& message, const xtd::string& category) -> void;
532 static auto write_line_(const xtd::string& message) -> void;
533 static auto write_line_(const xtd::string& message, const xtd::string& category) -> void;
534
535 inline static bool auto_flush_ = false;
536 inline static xtd::uint32 indent_level_ = 0;
537 inline static xtd::uint32 indent_size_ = 4;
538 static listener_collection& listeners_;
539 inline static bool use_global_lock_ = true;
540 };
541 }
542}
Contains add_last_arg_to_command_ macro.
Contains xtd::diagnostics::assert_dialog_result enum class.
static const basic_string empty_string
Definition basic_string.hpp:111
Provides a set of methods and properties that help you debug the execution of your code....
Definition debug.hpp:65
static auto assert(bool condition, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current()) -> void
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
Definition debug.hpp:133
static auto write(const xtd::string &format, args_t &&... args) -> void
Writes a formatted string to the trace listeners in the listeners collection.
Definition debug.hpp:346
static auto trace_warning(const xtd::string &message) -> void
Writes a warning message to the trace listeners in the listeners collection using the specified messa...
Definition debug.hpp:290
static auto fail(const xtd::string &message) -> void
Emits the specified error message.
Definition debug.hpp:196
static auto flush() -> void
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition debug.hpp:213
static auto write(const object_t &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:323
static auto cassert(bool condition, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current()) -> void
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
Definition debug.hpp:163
static auto write_line_if(bool condition, const object_t &message, const xtd::string &category) -> void
Writes a category name and message followed by a line terminator to the trace listeners in the Listen...
Definition debug.hpp:481
static auto write_line() -> void
Writes a line terminator to the trace listeners in the listeners collection.
Definition debug.hpp:398
static auto write_if(bool condition, const xtd::string &message) -> void
Writes a message to the trace listeners in the Listeners collection if a condition is true.
Definition debug.hpp:365
static auto write_line(const object_t &message) -> void
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition debug.hpp:417
static auto write(const object_t &message, const xtd::string &category) -> void
Writes a category name and message to the trace listeners in the listeners collection.
Definition debug.hpp:335
static auto print(const xtd::string &format, args_t &&... args) -> void
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition debug.hpp:235
static auto write_line(const object_t &message, const xtd::string &category) -> void
Writes a category name and message followed by a line terminator to the trace listeners in the listen...
Definition debug.hpp:429
static auto cassert(bool condition, const xtd::string &message, const xtd::string &detail_message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current()) -> void
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
Definition debug.hpp:186
xtd::diagnostics::trace_listener_collection listener_collection
Represents a collection of xtd::diagnostics::trace_listener.
Definition debug.hpp:71
static auto trace_error(const xtd::string &message) -> void
Writes an error message to the trace listeners in the Listeners collection using the specified messag...
Definition debug.hpp:252
static auto write_if(bool condition, const object_t &message) -> void
Writes a message to the trace listeners in the Listeners collection if a condition is true.
Definition debug.hpp:376
static auto unindent() noexcept -> void
Decreases the current indent_level by one.
static auto assert(bool condition, const xtd::string &message, const xtd::string &detail_message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current()) -> void
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
Definition debug.hpp:152
static auto auto_flush() noexcept -> bool
Gets whether xtd::diagnostics::debug::flush should be called on the xtd::diagnostics::debug::Listener...
static auto print(const xtd::string &message) -> void
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition debug.hpp:225
static auto indent_level() noexcept -> xtd::uint32
Gets the indent level.
static auto fail(const xtd::string &message, const xtd::string &detail_message) -> void
Emits an error message and a detailed error message.
Definition debug.hpp:206
static auto listeners() -> listener_collection &
Gets the collection of listeners that is monitoring the trace output.
static auto write_line_if(bool condition, const object_t &message) -> void
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition debug.hpp:469
static auto trace_information(const xtd::string &message, const objects_t &... args) -> void
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition debug.hpp:281
static auto trace_error(const xtd::string &message, const objects_t &... args) -> void
Writes an error message to the trace listeners in the listeners collection using the specified array ...
Definition debug.hpp:262
static auto trace_warning(const xtd::string &message, const objects_t &... args) -> void
Writes a warning message to the trace listeners in the listeners collection using the specified array...
Definition debug.hpp:300
static auto write_line(const xtd::string &format, args_t &&... args) -> void
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition debug.hpp:439
static auto write_if(bool condition, const object_t &message, const xtd::string &category) -> void
Writes a category name and message to the trace listeners in the Listeners collection if a condition ...
Definition debug.hpp:388
static auto trace_information(const xtd::string &message) -> void
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition debug.hpp:271
static auto cassert(bool condition, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current()) -> void
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
Definition debug.hpp:174
static auto indent_size() noexcept -> xtd::uint32
Gets the number of spaces in an indent.
static auto write_line(const xtd::string &message) -> void
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition debug.hpp:407
static auto indent() noexcept -> void
Increases the current indent_level by one.
static auto assert(bool condition, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current()) -> void
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
Definition debug.hpp:142
static auto write(const xtd::string &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:313
static auto write_line_if(bool condition, const xtd::string &message) -> void
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition debug.hpp:458
static auto show_assert_dialog() noexcept -> bool
Gets a value indicating whether the assert dialog should be show.
static auto use_global_lock() noexcept -> bool
Gets a value indicating whether the global lock should be used.
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:46
static auto current(const xtd::diagnostics::source_location &value=xtd::diagnostics::source_location::current()) noexcept -> xtd::diagnostics::stack_frame
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.hpp:29
Provides a set of methods and properties that help you debug the execution of your code....
Definition trace.hpp:38
static auto exit() -> void
Terminates this process and returns an exit code to the operating system.
Represents a common dialog box that displays assert dialog.
Definition assert_dialog.hpp:35
Contains core_export_ keyword.
Contains debug_break_ keyword.
Contains xtd::diagnostics::debugger class.
Contains xtd::environment class.
#define debug_break_()
Signals a breakpoint to an attached debugger.
Definition debug_break.hpp:21
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
auto format(const xtd::string &fmt, args_t &&... args) -> xtd::string
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:21
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:38
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
assert_dialog_result
Specifies identifiers to indicate the return value of an assert dialog box.
Definition assert_dialog_result.hpp:25
trace_event_type
Identifies the type of event that has caused the trace.
Definition trace_event_type.hpp:25
@ retry
The assert dialog return value is Retry (usually sent from a button labeled Retry).
Definition assert_dialog_result.hpp:29
@ abort
The assert dialog return value is Abort (usually sent from a button labeled Abort).
Definition assert_dialog_result.hpp:27
@ warning
Warning Noncritical problem.
Definition trace_event_type.hpp:31
@ information
Informational message.
Definition trace_event_type.hpp:33
@ error
Recoverable error.
Definition trace_event_type.hpp:29
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:219
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
auto print(FILE *file, arg_t &&value) -> void
Writes the text representation of the specified value to the file output stream.
Definition print.hpp:19
Contains xtd::diagnostics::stack_trace class.
Contains xtd::static_object class.
Contains xtd::string alias.
Contains xtd::diagnostics::trace_listener_collection class.