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>
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
114 static bool use_global_lock() noexcept;
118 static void use_global_lock(bool use_global_lock) noexcept;
120
122
127 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
132 static void cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
138 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());
139
144 static void fail(const xtd::string& message) {
145 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
146 fail__(message);
147 #endif
148 }
149
154 static void fail(const xtd::string& message, const xtd::string& detail_message) {
155 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
156 fail__(message, detail_message);
157 #endif
158 }
159
161 static void flush() {
162 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
163 flush_();
164 #endif
165 }
166
168 static void indent() noexcept;
169
173 static void print(const xtd::string& message) {
174 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
175 write_line_(message);
176 #endif
177 }
178
182 template<class ...args_t>
183 static void print(const xtd::string& format, args_t&& ... args) {
184 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
185 write_line_(xtd::string::format(format, args...));
186 #endif
187 }
188
189 template<class ...args_t>
190 static void print(const char* format, args_t&& ... args) {
191 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
192 write_line_(xtd::string::format(format, args...));
193 #endif
194 }
196
200 static void trace_error(const xtd::string& message) {
201 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
202 trace_event_(trace_event_type::error, message);
203 #endif
204 }
205
209 template<class ...objects_t>
210 static void trace_error(const xtd::string& message, const objects_t& ... args) {
211 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
212 trace_event_(trace_event_type::error, xtd::string::format(message, args...));
213 #endif
214 }
215
219 static void trace_information(const xtd::string& message) {
220 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
221 trace_event_(trace_event_type::information, message);
222 #endif
223 }
224
228 template<class ...objects_t>
229 static void trace_information(const xtd::string& message, const objects_t& ... args) {
230 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
231 trace_event_(trace_event_type::information, xtd::string::format(message, args...));
232 #endif
233 }
234
238 static void trace_warning(const xtd::string& message) {
239 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
240 trace_event_(trace_event_type::warning, message);
241 #endif
242 }
243
247 template<class ...objects_t>
248 static void trace_warning(const xtd::string& message, const objects_t& ... args) {
249 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
250 trace_event_(trace_event_type::warning, xtd::string::format(message, args...));
251 #endif
252 }
253
255 static void unindent() noexcept;
256
261 static void write(const xtd::string& message) {
262 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
263 write_(message);
264 #endif
265 }
266
270 template<class object_t>
271 static void write(const object_t& message) {
272 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
273 write_(xtd::string::format("{}", message));
274 #endif
275 }
276
282 template<class object_t>
283 static void write(const object_t& message, const xtd::string& category) {
284 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
285 write_(xtd::string::format("{}", message), category);
286 #endif
287 }
288
293 template<class ...args_t>
294 static void write(const xtd::string& format, args_t&& ... args) {
295 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
296 write_(string::format(format, args...));
297 #endif
298 }
299
300 template<class ...args_t>
301 static void write(const char* format, args_t&& ... args) {
302 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
303 write_(string::format(format, args...));
304 #endif
305 }
307
313 static void write_if(bool condition, const xtd::string& message) {
314 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
315 if (condition) write_(message);
316 #endif
317 }
318 template<class object_t>
324 static void write_if(bool condition, const object_t& message) {
325 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
326 if (condition) write_(xtd::string::format("{}", message));
327 #endif
328 }
329
335 template<class object_t>
336 static void write_if(bool condition, const object_t& message, const xtd::string& category) {
337 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
338 if (condition) write_(xtd::string::format("{}", message), category);
339 #endif
340 }
341
346 static void write_line() {
347 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
348 write_line_("");
349 #endif
350 }
351
355 static void write_line(const xtd::string& message) {
356 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
357 write_line_(message);
358 #endif
359 }
360
364 template<class object_t>
365 static void write_line(const object_t& message) {
366 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
367 write_line_(xtd::string::format("{}", message));
368 #endif
369 }
370
376 template<class object_t>
377 static void write_line(const object_t& message, const xtd::string& category) {
378 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
379 write_line_(xtd::string::format("{}", message), category);
380 #endif
381 }
382
386 template<class ...args_t>
387 static void write_line(const xtd::string& format, args_t&& ... args) {
388 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
389 write_line_(string::format(format, args...));
390 #endif
391 }
392
393 template<class ...args_t>
394 static void write_line(const char* format, args_t&& ... args) {
395 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
396 write_line_(string::format(format, args...));
397 #endif
398 }
400
406 static void write_line_if(bool condition, const xtd::string& message) {
407 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
408 if (condition) write_line_(message);
409 #endif
410 }
411
416 template<class object_t>
417 static void write_line_if(bool condition, const object_t& message) {
418 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
419 if (condition) write_line_(message);
420 #endif
421 }
422
428 template<class object_t>
429 static void write_line_if(bool condition, const object_t& message, const xtd::string& category) {
430 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
431 if (condition) write_line_(message, category);
432 #endif
433 }
434
435
437 static inline bool __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition) {return __should_aborted__(stack_frame, condition, xtd::string::empty_string);}
438 static inline bool __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message) {return __should_aborted__(stack_frame, condition, message, xtd::string::empty_string);}
439 static inline bool __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message, const xtd::string& detail_message) {
440 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
441 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
443 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
444 #endif
445 return false;
446 }
448
450
457 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
458 static bool show_assert_dialog() noexcept;
464 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
465 static void show_assert_dialog(bool show_assert_dialog) noexcept;
467
468 private:
469 friend trace;
470 friend xtd::forms::assert_dialog;
471 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);
472 static xtd::string assert_dialog_caption();
473 static bool internal_show_assert_dialog() noexcept;
474 static void fail__(const xtd::string& message);
475 static void fail__(const xtd::string& message, const xtd::string& detail_message);
476 static void flush_();
477 static void trace_event_(trace_event_type trace_event_type, const xtd::string& message);
478 static void write_(const xtd::string& message);
479 static void write_(const xtd::string& message, const xtd::string& category);
480 static void write_line_(const xtd::string& message);
481 static void write_line_(const xtd::string& message, const xtd::string& category);
482
483 inline static bool auto_flush_ = false;
484 inline static uint32 indent_level_ = 0;
485 inline static uint32 indent_size_ = 4;
486 static listener_collection& listeners_;
487 static xtd::string source_name_;
488 };
489 }
490}
Contains add_last_arg_to_command_ macro.
Contains xtd::diagnostics::assert_dialog_result enum class.
Provides a set of methods and properties that help you debug the execution of your code....
Definition debug.hpp:59
static void write(const xtd::string &message)
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:261
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:336
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:229
static void cassert(bool condition, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
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:346
static void fail(const xtd::string &message)
Emits the specified error message.
Definition debug.hpp:144
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:283
static void print(const xtd::string &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition debug.hpp:173
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:417
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:365
static listener_collection & listeners() noexcept
Gets the collection of listeners that is monitoring the trace output.
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:294
xtd::diagnostics::trace_listener_collection listener_collection
Represents a collection of xtd::diagnostics::trace_listener.
Definition debug.hpp:65
static bool auto_flush() noexcept
Gets whether xtd::diagnostics::debug::flush should be called on the xtd::diagnostics::debug::Listener...
static uint32 indent_level() noexcept
Gets the indent level.
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:210
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:429
static void fail(const xtd::string &message, const xtd::string &detail_message)
Emits an error message and a detailed error message.
Definition debug.hpp:154
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:355
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:324
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:183
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:200
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:238
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition debug.hpp:271
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition debug.hpp:161
static uint32 indent_size() noexcept
Gets the number of spaces in an indent.
static bool use_global_lock() noexcept
Gets a value indicating whether the global lock should be used.
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:387
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:219
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:377
static bool show_assert_dialog() noexcept
Gets a value indicating whether the assert dialog should be show.
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:248
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:313
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:406
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:48
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:40
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
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: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
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.