xtd 0.2.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
16namespace xtd {
18 namespace forms {
19 class assert_dialog;
20 }
22
24 namespace diagnostics {
26 class trace;
58 public:
60
65
67
73 [[nodiscard]] static auto auto_flush() noexcept -> bool;
78 static auto auto_flush(bool auto_flush) noexcept -> void;
79
83 [[nodiscard]] static auto indent_level() noexcept -> xtd::uint32;
87 static auto indent_level(xtd::uint32 indent_level) noexcept -> void;
88
92 [[nodiscard]] static auto indent_size() noexcept -> xtd::uint32;
96 static auto indent_size(xtd::uint32 indent_size) noexcept -> void;
97
102 [[nodiscard]] static auto listeners() -> listener_collection&;
107 static auto listeners(const listener_collection& listeners) -> void;
108
112 [[nodiscard]] static auto use_global_lock() noexcept -> bool;
116 static auto use_global_lock(bool use_global_lock) noexcept -> void;
118
120
125 static auto cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void;
130 static auto cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void;
136 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;
137
142 static auto fail(const xtd::string& message) -> void {
143 #if DEBUG
144 fail__(message);
145 #endif
146 }
147
152 static auto fail(const xtd::string& message, const xtd::string& detail_message) -> void {
153 #if DEBUG
154 fail__(message, detail_message);
155 #endif
156 }
157
159 static auto flush() -> void {
160 #if DEBUG
161 flush_();
162 #endif
163 }
164
166 static auto indent() noexcept -> void;
167
171 static auto print(const xtd::string& message) -> void {
172 #if DEBUG
173 write_line_(message);
174 #endif
175 }
176
180 template<typename ...args_t>
181 static auto print(const xtd::string& format, args_t&& ... args) -> void {
182 #if DEBUG
183 write_line_(xtd::string::format(format, args...));
184 #endif
185 }
186
187 template<typename ...args_t>
188 static auto print(const char* format, args_t&& ... args) -> void {
189 #if DEBUG
190 write_line_(xtd::string::format(format, args...));
191 #endif
192 }
194
198 static auto trace_error(const xtd::string& message) -> void {
199 #if DEBUG
200 trace_event_(xtd::diagnostics::trace_event_type::error, message);
201 #endif
202 }
203
207 template<typename ...objects_t>
208 static auto trace_error(const xtd::string& message, const objects_t& ... args) -> void {
209 #if DEBUG
210 trace_event_(xtd::diagnostics::trace_event_type::error, xtd::string::format(message, args...));
211 #endif
212 }
213
217 static auto trace_information(const xtd::string& message) -> void {
218 #if DEBUG
220 #endif
221 }
222
226 template<typename ...objects_t>
227 static auto trace_information(const xtd::string& message, const objects_t& ... args) -> void {
228 #if DEBUG
230 #endif
231 }
232
236 static auto trace_warning(const xtd::string& message) -> void {
237 #if DEBUG
238 trace_event_(xtd::diagnostics::trace_event_type::warning, message);
239 #endif
240 }
241
245 template<typename ...objects_t>
246 static auto trace_warning(const xtd::string& message, const objects_t& ... args) -> void {
247 #if DEBUG
249 #endif
250 }
251
253 static auto unindent() noexcept -> void;
254
259 static auto write(const xtd::string& message) -> void {
260 #if DEBUG
261 write_(message);
262 #endif
263 }
264
268 template<typename object_t>
269 static auto write(const object_t& message) -> void {
270 #if DEBUG
271 write_(xtd::string::format("{}", message));
272 #endif
273 }
274
280 template<typename object_t>
281 static auto write(const object_t& message, const xtd::string& category) -> void {
282 #if DEBUG
283 write_(xtd::string::format("{}", message), category);
284 #endif
285 }
286
291 template<typename ...args_t>
292 static auto write(const xtd::string& format, args_t&& ... args) -> void {
293 #if DEBUG
294 write_(xtd::string::format(format, args...));
295 #endif
296 }
297
298 template<typename ...args_t>
299 static auto write(const char* format, args_t&& ... args) -> void {
300 #if DEBUG
301 write_(xtd::string::format(format, args...));
302 #endif
303 }
305
311 static auto write_if(bool condition, const xtd::string& message) -> void {
312 #if DEBUG
313 if (condition) write_(message);
314 #endif
315 }
316
321 template<typename object_t>
322 static auto write_if(bool condition, const object_t& message) -> void {
323 #if DEBUG
324 if (condition) write_(xtd::string::format("{}", message));
325 #endif
326 }
327
333 template<typename object_t>
334 static auto write_if(bool condition, const object_t& message, const xtd::string& category) -> void {
335 #if DEBUG
336 if (condition) write_(xtd::string::format("{}", message), category);
337 #endif
338 }
339
344 static auto write_line() -> void {
345 #if DEBUG
346 write_line_("");
347 #endif
348 }
349
353 static auto write_line(const xtd::string& message) -> void {
354 #if DEBUG
355 write_line_(message);
356 #endif
357 }
358
362 template<typename object_t>
363 static auto write_line(const object_t& message) -> void {
364 #if DEBUG
365 write_line_(xtd::string::format("{}", message));
366 #endif
367 }
368
374 template<typename object_t>
375 static auto write_line(const object_t& message, const xtd::string& category) -> void {
376 #if DEBUG
377 write_line_(xtd::string::format("{}", message), category);
378 #endif
379 }
380
384 template<typename ...args_t>
385 static auto write_line(const xtd::string& format, args_t&& ... args) -> void {
386 #if DEBUG
387 write_line_(xtd::string::format(format, args...));
388 #endif
389 }
390
391 template<typename ...args_t>
392 static auto write_line(const char* format, args_t&& ... args) -> void {
393 #if DEBUG
394 write_line_(xtd::string::format(format, args...));
395 #endif
396 }
398
404 static auto write_line_if(bool condition, const xtd::string& message) -> void {
405 #if DEBUG
406 if (condition) write_line_(message);
407 #endif
408 }
409
414 template<typename object_t>
415 static auto write_line_if(bool condition, const object_t& message) -> void {
416 #if DEBUG
417 if (condition) write_line_(message);
418 #endif
419 }
420
426 template<typename object_t>
427 static auto write_line_if(bool condition, const object_t& message, const xtd::string& category) -> void {
428 #if DEBUG
429 if (condition) write_line_(message, category);
430 #endif
431 }
432
433
435 static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition) -> bool {return __should_aborted__(stack_frame, condition, xtd::string::empty_string);}
436 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);}
437 static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message, const xtd::string& detail_message) -> bool {
438 #if DEBUG
439 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
441 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
442 #endif
443 return false;
444 }
446
448
455 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
456 [[nodiscard]] static auto show_assert_dialog() noexcept -> bool;
462 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
463 static auto show_assert_dialog(bool show_assert_dialog) noexcept -> void;
465
466 private:
467 friend trace;
468 friend xtd::forms::assert_dialog;
469 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;
470 static auto assert_dialog_caption() -> xtd::string;
471 static auto internal_show_assert_dialog() noexcept -> bool;
472 static auto fail__(const xtd::string& message) -> void;
473 static auto fail__(const xtd::string& message, const xtd::string& detail_message) -> void;
474 static auto flush_() -> void;
475 static auto trace_event_(xtd::diagnostics::trace_event_type trace_event_type, const xtd::string& message) -> void;
476 static auto write_(const xtd::string& message) -> void;
477 static auto write_(const xtd::string& message, const xtd::string& category) -> void;
478 static auto write_line_(const xtd::string& message) -> void;
479 static auto write_line_(const xtd::string& message, const xtd::string& category) -> void;
480
481 inline static bool auto_flush_ = false;
482 inline static xtd::uint32 indent_level_ = 0;
483 inline static xtd::uint32 indent_size_ = 4;
484 static listener_collection& listeners_;
485 inline static bool use_global_lock_ = true;
486 };
487 }
488}
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:57
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:292
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:236
static auto fail(const xtd::string &message) -> void
Emits the specified error message.
Definition debug.hpp:142
static auto flush() -> void
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition debug.hpp:159
static auto write(const object_t &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:269
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.
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:427
static auto write_line() -> void
Writes a line terminator to the trace listeners in the listeners collection.
Definition debug.hpp:344
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:311
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:363
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:281
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:181
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:375
xtd::diagnostics::trace_listener_collection listener_collection
Represents a collection of xtd::diagnostics::trace_listener.
Definition debug.hpp:63
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:198
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:322
static auto unindent() noexcept -> void
Decreases the current indent_level by one.
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:171
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:152
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:415
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:227
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:208
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:246
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:385
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:334
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:217
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:353
static auto indent() noexcept -> void
Increases the current indent_level by one.
static auto write(const xtd::string &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:259
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:404
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
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 xtd::diagnostics::debugger class.
Contains xtd::environment class.
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:21
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
#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
void print(FILE *file, arg_t &&value)
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.