xtd 0.2.0
Loading...
Searching...
No Matches
debug.hpp
Go to the documentation of this file.
1
4#pragma once
5#include <cstdint>
6#include <cstdlib>
7#include "../add_last_arg_to_command.hpp"
8#include "../core_export.hpp"
9#include "../environment.hpp"
10#include "../static.hpp"
11#include "../string.hpp"
13#include "debugger.hpp"
14#include "stack_trace.hpp"
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
142 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
147 static void cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
153 static void cassert(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
154
159 static void fail(const xtd::string& message) {
160 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
161 fail__(message);
162 #endif
163 }
169 static void fail(const xtd::string& message, const xtd::string& detail_message) {
170 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
171 fail__(message, detail_message);
172 #endif
173 }
174
176 static void flush() {
177 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
178 flush_();
179 #endif
180 }
181
183 static void indent() noexcept;
184
188 static void print(const xtd::string& message) {
189 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
190 write_line_(message);
191 #endif
192 }
197 template<typename ...args_t>
198 static void print(const xtd::string& format, args_t&& ... args) {
199 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
200 write_line_(xtd::string::format(format, args...));
201 #endif
202 }
204 template<typename ...args_t>
205 static void print(const char* format, args_t&& ... args) {
206 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
207 write_line_(xtd::string::format(format, args...));
208 #endif
209 }
211
215 static void trace_error(const xtd::string& message) {
216 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
217 trace_event_(trace_event_type::error, message);
218 #endif
219 }
224 template<typename ...objects_t>
225 static void trace_error(const xtd::string& message, const objects_t& ... args) {
226 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
227 trace_event_(trace_event_type::error, xtd::string::format(message, args...));
228 #endif
229 }
230
234 static void trace_information(const xtd::string& message) {
235 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
236 trace_event_(trace_event_type::information, message);
237 #endif
238 }
243 template<typename ...objects_t>
244 static void trace_information(const xtd::string& message, const objects_t& ... args) {
245 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
246 trace_event_(trace_event_type::information, xtd::string::format(message, args...));
247 #endif
248 }
249
253 static void trace_warning(const xtd::string& message) {
254 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
255 trace_event_(trace_event_type::warning, message);
256 #endif
257 }
262 template<typename ...objects_t>
263 static void trace_warning(const xtd::string& message, const objects_t& ... args) {
264 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
265 trace_event_(trace_event_type::warning, xtd::string::format(message, args...));
266 #endif
267 }
268
270 static void unindent() noexcept;
271
276 static void write(const xtd::string& message) {
277 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
278 write_(message);
279 #endif
280 }
285 template<typename object_t>
286 static void write(const object_t& message) {
287 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
288 write_(xtd::string::format("{}", message));
289 #endif
290 }
297 template<typename object_t>
298 static void write(const object_t& message, const xtd::string& category) {
299 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
300 write_(xtd::string::format("{}", message), category);
301 #endif
302 }
308 template<typename ...args_t>
309 static void write(const xtd::string& format, args_t&& ... args) {
310 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
311 write_(string::format(format, args...));
312 #endif
313 }
315 template<typename ...args_t>
316 static void write(const char* format, args_t&& ... args) {
317 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
318 write_(string::format(format, args...));
319 #endif
320 }
322
328 static void write_if(bool condition, const xtd::string& message) {
329 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
330 if (condition) write_(message);
331 #endif
332 }
333 template<typename object_t>
339 static void write_if(bool condition, const object_t& message) {
340 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
341 if (condition) write_(xtd::string::format("{}", message));
342 #endif
343 }
350 template<typename object_t>
351 static void write_if(bool condition, const object_t& message, const xtd::string& category) {
352 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
353 if (condition) write_(xtd::string::format("{}", message), category);
354 #endif
355 }
356
361 static void write_line() {
362 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
363 write_line_("");
364 #endif
365 }
370 static void write_line(const xtd::string& message) {
371 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
372 write_line_(message);
373 #endif
374 }
379 template<typename object_t>
380 static void write_line(const object_t& message) {
381 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
382 write_line_(xtd::string::format("{}", message));
383 #endif
384 }
391 template<typename object_t>
392 static void write_line(const object_t& message, const xtd::string& category) {
393 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
394 write_line_(xtd::string::format("{}", message), category);
395 #endif
396 }
401 template<typename ...args_t>
402 static void write_line(const xtd::string& format, args_t&& ... args) {
403 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
404 write_line_(string::format(format, args...));
405 #endif
406 }
408 template<typename ...args_t>
409 static void write_line(const char* format, args_t&& ... args) {
410 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
411 write_line_(string::format(format, args...));
412 #endif
413 }
415
421 static void write_line_if(bool condition, const xtd::string& message) {
422 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
423 if (condition) write_line_(message);
424 #endif
425 }
431 template<typename object_t>
432 static void write_line_if(bool condition, const object_t& message) {
433 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
434 if (condition) write_line_(message);
435 #endif
436 }
443 template<typename object_t>
444 static void write_line_if(bool condition, const object_t& message, const xtd::string& category) {
445 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
446 if (condition) write_line_(message, category);
447 #endif
448 }
449
451 static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {return __should_aborted__(condition, xtd::string::empty_string, stack_frame);}
452 static inline bool __should_aborted__(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {return __should_aborted__(condition, message, xtd::string::empty_string, stack_frame);}
453 static inline bool __should_aborted__(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
454 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
455 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
457 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
458 #endif
459 return false;
460 }
463
464 private:
465 friend trace;
467 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);
468 static xtd::string assert_dialog_caption();
469 static bool internal_show_assert_dialog() noexcept;
470 static void fail__(const xtd::string& message);
471 static void fail__(const xtd::string& message, const xtd::string& detail_message);
472 static void flush_();
473 static void trace_event_(trace_event_type trace_event_type, const xtd::string& message);
474 static void write_(const xtd::string& message);
475 static void write_(const xtd::string& message, const xtd::string& category);
476 static void write_line_(const xtd::string& message);
477 static void write_line_(const xtd::string& message, const xtd::string& category);
478
479 inline static bool auto_flush_ = false;
480 inline static uint32 indent_level_ = 0;
481 inline static uint32 indent_size_ = 4;
482 static listener_collection& listeners_;
483 static xtd::string source_name_;
484 };
485 }
486}
Contains xtd::diagnostics::assert_dialog_result enum class.
Represents text as a sequence of character units.
Definition basic_string.hpp:79
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.hpp:124
Provides a set of methods and properties that help you debug the execution of your code....
Definition debug.hpp:59
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.hpp:351
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.hpp:244
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.hpp:361
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.hpp:298
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.hpp:432
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.hpp:380
static void write(const xtd::string &format, args_t &&... args)
Writes a formatted string to the trace listeners in the listeners collection.
Definition debug.hpp:309
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.hpp:225
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.hpp:444
static void fail(const xtd::string &message, const xtd::string &detail_message)
Emits an error message and a detailed error message.
Definition debug.hpp:169
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.hpp:370
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.hpp:339
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.hpp:198
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.hpp:215
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.hpp:253
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:286
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition debug.hpp:176
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.hpp:402
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.hpp:234
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.hpp:392
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.hpp:263
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.hpp:328
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.hpp:421
Provides the default output methods and behavior for tracing.
Definition default_trace_listener.hpp:33
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:47
static stack_frame current(const xtd::source_location &value=xtd::source_location::current()) noexcept
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
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.hpp:35
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
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 ...
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:20
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#define core_export_
Define shared library export.
Definition core_export.hpp:13
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
@ 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).
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
void print(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition print.hpp:13
Contains xtd::diagnostics::trace_listener_collection class.
Contains xtd::diagnostics::debugger class.
Contains xtd::diagnostics::stack_trace class.