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 "debugger.hpp"
12#include "stack_trace.hpp"
14
16#if defined(assert)
17#undef assert
18#endif
20
22namespace xtd {
24 namespace forms {
25 class assert_dialog;
26 }
28
30 namespace diagnostics {
32 class trace;
64 public:
66
71
73
79 [[nodiscard]] static auto auto_flush() noexcept -> bool;
84 static auto auto_flush(bool auto_flush) noexcept -> void;
85
89 [[nodiscard]] static auto indent_level() noexcept -> xtd::uint32;
93 static auto indent_level(xtd::uint32 indent_level) noexcept -> void;
94
98 [[nodiscard]] static auto indent_size() noexcept -> xtd::uint32;
102 static auto indent_size(xtd::uint32 indent_size) noexcept -> void;
103
108 [[nodiscard]] static auto listeners() -> listener_collection&;
114
118 [[nodiscard]] static auto use_global_lock() noexcept -> bool;
122 static auto use_global_lock(bool use_global_lock) noexcept -> void;
124
126
131 static auto assert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
132 #if DEBUG
133 if (__should_aborted__(stack_frame, condition, string::empty_string)) xtd::diagnostics::debugger::debug_break();
134 #endif
135 }
136
140 static auto assert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
141 #if DEBUG
142 if (__should_aborted__(stack_frame, condition, message)) xtd::diagnostics::debugger::debug_break();
143 #endif
144 }
145
150 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 {
151 #if DEBUG
152 if (__should_aborted__(stack_frame, condition, message, detail_message)) xtd::diagnostics::debugger::debug_break();
153 #endif
154 }
155
160 [[deprecated("Use xtd::diagnostics::debug::assert method - Will be removed in version 1.2.0.)")]]
162 #if DEBUG
163 if (__should_aborted__(stack_frame, condition, string::empty_string)) xtd::diagnostics::debugger::debug_break();
164 #endif
165 }
166
171 [[deprecated("Use xtd::diagnostics::debug::assert method - Will be removed in version 1.2.0.)")]]
172 static auto cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
173 #if DEBUG
174 if (__should_aborted__(stack_frame, condition, message)) xtd::diagnostics::debugger::debug_break();
175 #endif
176 }
177
183 [[deprecated("Use xtd::diagnostics::debug::assert method - Will be removed in version 1.2.0.)")]]
184 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 {
185 #if DEBUG
186 if (__should_aborted__(stack_frame, condition, message, detail_message)) xtd::diagnostics::debugger::debug_break();
187 #endif
188 }
189
194 static auto fail(const xtd::string& message) -> void {
195 #if DEBUG
197 #endif
198 }
199
204 static auto fail(const xtd::string& message, const xtd::string& detail_message) -> void {
205 #if DEBUG
206 xtd::environment::fail_fast(message + environment::new_line() + detail_message);
207 #endif
208 }
209
211 static auto flush() -> void {
212 #if DEBUG
213 flush_();
214 #endif
215 }
216
218 static auto indent() noexcept -> void;
219
223 static auto print(const xtd::string& message) -> void {
224 #if DEBUG
225 write_line_(message);
226 #endif
227 }
228
232 template<typename ...args_t>
233 static auto print(const xtd::string& format, args_t&& ... args) -> void {
234 #if DEBUG
235 write_line_(xtd::string::format(format, args...));
236 #endif
237 }
238
239 template<typename ...args_t>
240 static auto print(const char* format, args_t&& ... args) -> void {
241 #if DEBUG
242 write_line_(xtd::string::format(format, args...));
243 #endif
244 }
246
250 static auto trace_error(const xtd::string& message) -> void {
251 #if DEBUG
252 trace_event_(xtd::diagnostics::trace_event_type::error, message);
253 #endif
254 }
255
259 template<typename ...objects_t>
260 static auto trace_error(const xtd::string& message, const objects_t& ... args) -> void {
261 #if DEBUG
262 trace_event_(xtd::diagnostics::trace_event_type::error, xtd::string::format(message, args...));
263 #endif
264 }
265
269 static auto trace_information(const xtd::string& message) -> void {
270 #if DEBUG
272 #endif
273 }
274
278 template<typename ...objects_t>
279 static auto trace_information(const xtd::string& message, const objects_t& ... args) -> void {
280 #if DEBUG
282 #endif
283 }
284
288 static auto trace_warning(const xtd::string& message) -> void {
289 #if DEBUG
290 trace_event_(xtd::diagnostics::trace_event_type::warning, message);
291 #endif
292 }
293
297 template<typename ...objects_t>
298 static auto trace_warning(const xtd::string& message, const objects_t& ... args) -> void {
299 #if DEBUG
301 #endif
302 }
303
305 static auto unindent() noexcept -> void;
306
311 static auto write(const xtd::string& message) -> void {
312 #if DEBUG
313 write_(message);
314 #endif
315 }
316
320 template<typename object_t>
321 static auto write(const object_t& message) -> void {
322 #if DEBUG
323 write_(xtd::string::format("{}", message));
324 #endif
325 }
326
332 template<typename object_t>
333 static auto write(const object_t& message, const xtd::string& category) -> void {
334 #if DEBUG
335 write_(xtd::string::format("{}", message), category);
336 #endif
337 }
338
343 template<typename ...args_t>
344 static auto write(const xtd::string& format, args_t&& ... args) -> void {
345 #if DEBUG
346 write_(xtd::string::format(format, args...));
347 #endif
348 }
349
350 template<typename ...args_t>
351 static auto write(const char* format, args_t&& ... args) -> void {
352 #if DEBUG
353 write_(xtd::string::format(format, args...));
354 #endif
355 }
357
363 static auto write_if(bool condition, const xtd::string& message) -> void {
364 #if DEBUG
365 if (condition) write_(message);
366 #endif
367 }
368
373 template<typename object_t>
374 static auto write_if(bool condition, const object_t& message) -> void {
375 #if DEBUG
376 if (condition) write_(xtd::string::format("{}", message));
377 #endif
378 }
379
385 template<typename object_t>
386 static auto write_if(bool condition, const object_t& message, const xtd::string& category) -> void {
387 #if DEBUG
388 if (condition) write_(xtd::string::format("{}", message), category);
389 #endif
390 }
391
396 static auto write_line() -> void {
397 #if DEBUG
398 write_line_("");
399 #endif
400 }
401
405 static auto write_line(const xtd::string& message) -> void {
406 #if DEBUG
407 write_line_(message);
408 #endif
409 }
410
414 template<typename object_t>
415 static auto write_line(const object_t& message) -> void {
416 #if DEBUG
417 write_line_(xtd::string::format("{}", message));
418 #endif
419 }
420
426 template<typename object_t>
427 static auto write_line(const object_t& message, const xtd::string& category) -> void {
428 #if DEBUG
429 write_line_(xtd::string::format("{}", message), category);
430 #endif
431 }
432
436 template<typename ...args_t>
437 static auto write_line(const xtd::string& format, args_t&& ... args) -> void {
438 #if DEBUG
439 write_line_(xtd::string::format(format, args...));
440 #endif
441 }
442
443 template<typename ...args_t>
444 static auto write_line(const char* format, args_t&& ... args) -> void {
445 #if DEBUG
446 write_line_(xtd::string::format(format, args...));
447 #endif
448 }
450
456 static auto write_line_if(bool condition, const xtd::string& message) -> void {
457 #if DEBUG
458 if (condition) write_line_(message);
459 #endif
460 }
461
466 template<typename object_t>
467 static auto write_line_if(bool condition, const object_t& message) -> void {
468 #if DEBUG
469 if (condition) write_line_(message);
470 #endif
471 }
472
478 template<typename object_t>
479 static auto write_line_if(bool condition, const object_t& message, const xtd::string& category) -> void {
480 #if DEBUG
481 if (condition) write_line_(message, category);
482 #endif
483 }
484
485
487 static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition) -> bool {return __should_aborted__(stack_frame, condition, xtd::string::empty_string);}
488 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);}
489 static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message, const xtd::string& detail_message) -> bool {
490 #if DEBUG
491 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
493 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
494 #endif
495 return false;
496 }
498
500
507 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 1.2.0.")]]
508 [[nodiscard]] static auto show_assert_dialog() noexcept -> bool;
514 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 1.2.0.")]]
515 static auto show_assert_dialog(bool show_assert_dialog) noexcept -> void;
517
518 private:
519 friend trace;
520 friend xtd::forms::assert_dialog;
521 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;
522 static auto assert_dialog_caption() -> xtd::string;
523 static auto internal_show_assert_dialog() noexcept -> bool;
524 static auto flush_() -> void;
525 static auto trace_event_(xtd::diagnostics::trace_event_type trace_event_type, const xtd::string& message) -> void;
526 static auto write_(const xtd::string& message) -> void;
527 static auto write_(const xtd::string& message, const xtd::string& category) -> void;
528 static auto write_line_(const xtd::string& message) -> void;
529 static auto write_line_(const xtd::string& message, const xtd::string& category) -> void;
530
531 inline static bool auto_flush_ = false;
532 inline static xtd::uint32 indent_level_ = 0;
533 inline static xtd::uint32 indent_size_ = 4;
534 static listener_collection& listeners_;
535 inline static bool use_global_lock_ = true;
536 };
537 }
538}
539
542[[deprecated("Replaced by xtd::diagnostics::debug::assert - Will be removed in version 1.2.0.")]]
543inline auto assert_(bool condition, const xtd::string& message = xtd::string::empty_string, const xtd::string& detail_message = xtd::string::empty_string, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
544 xtd::diagnostics::debug::assert(condition, message, detail_message, stack_frame);
545}
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:119
Provides a set of methods and properties that help you debug the execution of your code....
Definition debug.hpp:63
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:131
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:344
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:288
static auto fail(const xtd::string &message) -> void
Emits the specified error message.
Definition debug.hpp:194
static auto flush() -> void
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition debug.hpp:211
static auto write(const object_t &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:321
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:161
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:479
static auto write_line() -> void
Writes a line terminator to the trace listeners in the listeners collection.
Definition debug.hpp:396
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:363
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:415
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:333
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:233
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:427
xtd::diagnostics::trace_listener_collection listener_collection
Represents a collection of xtd::diagnostics::trace_listener.
Definition debug.hpp:69
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:250
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:374
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:150
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:223
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:204
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:467
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:184
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:279
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:260
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:298
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:437
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:386
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:269
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:172
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:405
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:140
static auto write(const xtd::string &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:311
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:456
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.
static auto debug_break() -> void
Signals a breakpoint to an attached debugger.
Definition debugger.hpp:48
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.
static auto fail_fast() noexcept -> void
Immediately terminates the process .
Definition environment.hpp:572
static auto new_line() noexcept -> xtd::string
Gets the newline string defined for this environment.
Represents a common dialog box that displays assert dialog.
Definition assert_dialog.hpp:35
Contains core_export_ keyword.
Contains xtd::diagnostics::debugger class.
auto() -> void
Signals a breakpoint to an attached debugger.
Definition debugger.hpp:75
Contains xtd::environment class.
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:20
Contains xtd::diagnostics::stack_trace class.
Contains xtd::static_object class.
Contains xtd::string alias.
Contains xtd::diagnostics::trace_listener_collection class.