xtd 1.0.0
Loading...
Searching...
No Matches
trace.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "debug.hpp"
6
8namespace xtd {
10 namespace diagnostics {
39 public:
41
46
48
54 [[nodiscard]] static auto auto_flush() noexcept -> bool;
59 static auto auto_flush(bool auto_flush) noexcept -> void;
60
64 [[nodiscard]] static auto indent_level() noexcept -> xtd::uint32;
68 static auto indent_level(xtd::uint32 indent_level) noexcept -> void;
69
73 [[nodiscard]] static auto indent_size() noexcept -> xtd::uint32;
77 static auto indent_size(xtd::uint32 indent_size) noexcept -> void;
78
83 [[nodiscard]] static auto listeners() -> listener_collection&;
88 static auto listeners(const listener_collection& listeners) -> void;
89
93 [[nodiscard]] static auto use_global_lock() noexcept -> bool;
97 static auto use_global_lock(bool use_global_lock) noexcept -> void;
99
101
106 static auto assert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
107 #if TRACE
108 if (__should_aborted__(stack_frame, condition, string::empty_string)) __xtd_debugbreak();
109 #endif
110 }
111
115 static auto assert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
116 #if TRACE
117 if (__should_aborted__(stack_frame, condition, message)) __xtd_debugbreak();
118 #endif
119 }
120
125 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 {
126 #if TRACE
127 if (__should_aborted__(stack_frame, condition, message, detail_message)) __xtd_debugbreak();
128 #endif
129 }
130
135 [[deprecated("Use xtd::diagnostics::trace::assert method - Will be removed in version 1.2.0.)")]]
137 #if TRACE
138 if (__should_aborted__(stack_frame, condition, string::empty_string)) __xtd_debugbreak();
139 #endif
140 }
141
146 [[deprecated("Use xtd::diagnostics::trace::assert method - Will be removed in version 1.2.0.)")]]
147 static auto cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) -> void {
148 #if TRACE
149 if (__should_aborted__(stack_frame, condition, message)) __xtd_debugbreak();
150 #endif
151 }
152
158 [[deprecated("Use xtd::diagnostics::trace::assert method - Will be removed in version 1.2.0.)")]]
159 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 {
160 #if TRACE
161 if (__should_aborted__(stack_frame, condition, message, detail_message)) __xtd_debugbreak();
162 #endif
163 }
164
169 static auto fail(const xtd::string& message) -> void {
170 #if TRACE
171 fail__(message);
172 #endif
173 }
174
179 static auto fail(const xtd::string& message, const xtd::string& detail_message) -> void {
180 #if TRACE
181 fail__(message, detail_message);
182 #endif
183 }
184
186 static void flush() {
187 #if TRACE
188 flush_();
189 #endif
190 }
191
193 static auto indent() noexcept -> void;
194
198 static auto print(const xtd::string& message) -> void {
199 #if TRACE
200 write_line_(message);
201 #endif
202 }
203
207 template<typename ...args_t>
208 static auto print(const xtd::string& format, args_t&& ... args) -> void {
209 #if TRACE
210 write_line_(xtd::string::format(format, args...));
211 #endif
212 }
213
214 template<typename ...args_t>
215 static auto print(const char* format, args_t&& ... args) -> void {
216 #if TRACE
217 write_line_(xtd::string::format(format, args...));
218 #endif
219 }
221
225 static auto trace_error(const xtd::string& message) -> void {
226 #if TRACE
227 trace_event_(xtd::diagnostics::trace_event_type::error, message);
228 #endif
229 }
230
234 template<typename ...objects>
235 static auto trace_error(const xtd::string& message, const objects& ... args) -> void {
236 #if TRACE
237 trace_event_(xtd::diagnostics::trace_event_type::error, message, args...);
238 #endif
239 }
240
244 static auto trace_information(const xtd::string& message) -> void {
245 #if TRACE
247 #endif
248 }
249
253 template<typename ...objects>
254 static auto trace_information(const xtd::string& message, const objects& ... args) -> void {
255 #if TRACE
257 #endif
258 }
259
263 static auto trace_warning(const xtd::string& message) -> void {
264 #if TRACE
265 trace_event_(xtd::diagnostics::trace_event_type::warning, message);
266 #endif
267 }
268
272 template<typename ...objects>
273 static auto trace_warning(const xtd::string& message, const objects& ... args) -> void {
274 #if TRACE
276 #endif
277 }
278
280 static auto unindent() noexcept -> void;
281
286 static auto write(const xtd::string& message) -> void {
287 #if TRACE
288 write_(message);
289 #endif
290 }
291
296 template<typename object_t>
297 static auto write(const object_t& message) -> void {
298 #if TRACE
299 write_(xtd::string::format("{}", message));
300 #endif
301 }
302
308 template<typename object_t>
309 static auto write(const object_t& message, const xtd::string& category) -> void {
310 #if TRACE
311 write_(xtd::string::format("{}", message), category);
312 #endif
313 }
314
319 template<typename ...args_t>
320 static auto write(const xtd::string& format, args_t&& ... args) -> void {
321 #if TRACE
322 write_(string::format(format, args...));
323 #endif
324 }
325
326 template<typename ...args_t>
327 static auto write(const char* format, args_t&& ... args) -> void {
328 #if TRACE
329 write_(string::format(format, args...));
330 #endif
331 }
333
339 static auto write_if(bool condition, const xtd::string& message) -> void {
340 #if TRACE
341 if (condition) write_(message);
342 #endif
343 }
344
349 template<typename object_t>
350 static auto write_if(bool condition, const object_t& message) -> void {
351 #if TRACE
352 if (condition) write_(xtd::string::format("{}", message));
353 #endif
354 }
355
361 template<typename object_t>
362 static auto write_if(bool condition, const object_t& message, const xtd::string& category) -> void {
363 #if TRACE
364 if (condition) write_(xtd::string::format("{}", message), category);
365 #endif
366 }
367
372 static auto write_line() -> void {
373 #if TRACE
374 write_line_("");
375 #endif
376 }
377
381 static auto write_line(const xtd::string& message) -> void {
382 #if TRACE
383 write_line_(message);
384 #endif
385 }
386
390 template<typename object_t>
391 static auto write_line(const object_t& message) -> void {
392 #if TRACE
393 write_line_(xtd::string::format("{}", message));
394 #endif
395 }
396
402 template<typename object_t>
403 static auto write_line(const object_t& message, const xtd::string& category) -> void {
404 #if TRACE
405 write_line_(xtd::string::format("{}", message), category);
406 #endif
407 }
408
412 template<typename ...args_t>
413 static auto write_line(const xtd::string& format, args_t&& ... args) -> void {
414 #if TRACE
415 write_line_(xtd::string::format(format, args...));
416 #endif
417 }
418
419 template<typename ...args_t>
420 static auto write_line(const char* format, args_t&& ... args) -> void {
421 #if TRACE
422 write_line_(xtd::string::format(format, args...));
423 #endif
424 }
426
432 static auto write_line_if(bool condition, const xtd::string& message) -> void {
433 #if TRACE
434 if (condition) write_line_(message);
435 #endif
436 }
437
442 template<typename object_t>
443 static auto write_line_if(bool condition, const object_t& message) -> void {
444 #if TRACE
445 if (condition) write_line_(xtd::string::format("{}", message));
446 #endif
447 }
448
454 template<typename object_t>
455 static auto write_line_if(bool condition, const object_t& message, const xtd::string& category) -> void {
456 #if TRACE
457 if (condition) write_line_(xtd::string::format("{}", message), category);
458 #endif
459 }
460
461
463 [[nodiscard]] static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition) -> bool {return __should_aborted__(stack_frame, condition, xtd::string::empty_string);}
464 [[nodiscard]] 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);}
465 [[nodiscard]] static auto __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message, const xtd::string& detail_message) -> bool {
466 #if TRACE
467 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
469 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
470 #endif
471 return false;
472 }
474
476
483 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 1.2.0.")]]
484 [[nodiscard]] static auto show_assert_dialog() noexcept -> bool;
490 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 1.2.0.")]]
491 static auto show_assert_dialog(bool show_assert_dialog) noexcept -> void;
493
494 private:
495 static auto fail__(const xtd::string& message) -> void;
496 static auto fail__(const xtd::string& message, const xtd::string& detail_message) -> void;
497 static auto flush_() -> void;
498 static auto trace_event_(trace_event_type trace_event_type, const xtd::string& message) -> void;
499 static auto write_(const xtd::string& message) -> void;
500 static auto write_(const xtd::string& message, const xtd::string& category) -> void;
501 static auto write_line_(const xtd::string& message) -> void;
502 static auto write_line_(const xtd::string& message, const xtd::string& category) -> void;
503
504 inline static bool auto_flush_ = false;
505 inline static xtd::uint32 indent_level_ = 0;
506 inline static xtd::uint32 indent_size_ = 4;
507 static listener_collection& listeners_;
508 inline static bool use_global_lock_ = true;
509 };
510 }
511}
static const basic_string empty_string
Definition basic_string.hpp:111
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 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 trace.hpp:147
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 trace.hpp:362
static auto listeners() -> listener_collection &
Gets the collection of listeners that is monitoring the trace output.
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 trace.hpp:244
static auto write(const xtd::string &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition trace.hpp:286
static auto indent() noexcept -> void
Increases the current indent_level by one.
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 trace.hpp:443
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 trace.hpp:403
static auto write(const xtd::string &format, args_t &&... args) -> void
Writes a formatted string to the trace listeners in the listeners collection.
Definition trace.hpp:320
static auto fail(const xtd::string &message) -> void
Emits the specified error message.
Definition trace.hpp:169
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 trace.hpp:339
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 trace.hpp:309
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 trace.hpp:432
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 trace.hpp:391
static auto write_line() -> void
Writes a line terminator to the trace listeners in the listeners collection.
Definition trace.hpp:372
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 trace.hpp:115
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 trace.hpp:350
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 trace.hpp:106
static auto trace_information(const xtd::string &message, const objects &... args) -> void
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace.hpp:254
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 trace.hpp:455
static auto indent_level() noexcept -> xtd::uint32
Gets the indent level.
xtd::diagnostics::trace_listener_collection listener_collection
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace.hpp:44
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 trace.hpp:136
static auto fail(const xtd::string &message, const xtd::string &detail_message) -> void
Emits an error message and a detailed error message.
Definition trace.hpp:179
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 trace.hpp:125
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 trace.hpp:263
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 trace.hpp:208
static auto unindent() noexcept -> void
Decreases the current indent_level by one.
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 trace.hpp:413
static auto write(const object_t &message) -> void
Writes a message to the trace listeners in the listeners collection.
Definition trace.hpp:297
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition trace.hpp: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
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
Definition trace.hpp:159
static auto trace_error(const xtd::string &message, const objects &... args) -> void
Writes an error message to the trace listeners in the listeners collection using the specified array ...
Definition trace.hpp:235
static auto auto_flush() noexcept -> bool
Gets whether Flush should be called on the Listeners after every write.
static auto trace_warning(const xtd::string &message, const objects &... args) -> void
Writes a warning message to the trace listeners in the listeners collection using the specified array...
Definition trace.hpp:273
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 trace.hpp:225
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 trace.hpp:381
static auto indent_size() noexcept -> xtd::uint32
Gets the number of spaces in an indent.
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 trace.hpp:198
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 exit() -> void
Terminates this process and returns an exit code to the operating system.
Contains xtd::diagnostics::debug 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
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 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