xtd 0.2.0
Loading...
Searching...
No Matches
trace.h
Go to the documentation of this file.
1
4#pragma once
5#include "debug.h"
6
8namespace xtd {
10 namespace diagnostics {
41 public:
43
48
50
56 static bool auto_flush() noexcept;
61 static void auto_flush(bool auto_flush) noexcept;
62
66 static uint32 indent_level() noexcept;
70 static void indent_level(uint32 indent_level) noexcept;
71
75 static uint32 indent_size() noexcept;
79 static void indent_size(uint32 indent_size) noexcept;
80
85 static listener_collection& listeners() noexcept;
90 static void listeners(const listener_collection& listeners) noexcept;
91
97 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
98 static bool show_assert_dialog() noexcept;
104 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
105 static void show_assert_dialog(bool show_assert_dialog) noexcept;
106
110 static bool use_global_lock() noexcept;
114 static void use_global_lock(bool use_global_lock) noexcept;
116
118
125 static void cassert(bool condition);
129 static void cassert(bool condition, const xtd::string& message);
134 static void cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame);
139 static void cassert(bool condition, const xtd::string& message, const xtd::string& detail_message);
145 static void cassert(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame);
149 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame);
150
155 static void fail(const xtd::string& message) {
156 #if defined(TRACE)
157 fail__(message);
158 #endif
159 }
165 static void fail(const xtd::string& message, const xtd::string& detail_message) {
166 #if defined(TRACE)
167 fail__(message, detail_message);
168 #endif
169 }
170
172 static void flush() {
173 #if defined(TRACE)
174 flush_();
175 #endif
176 }
177
179 static void indent() noexcept;
180
184 static void print(const xtd::string& message) {
185 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
186 write_line_(message);
187 #endif
188 }
193 template<typename ...args_t>
194 static void print(const xtd::string& format, args_t&& ... args) {
195 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
196 write_line_(xtd::string::format(format, args...));
197 #endif
198 }
200 template<typename ...args_t>
201 static void print(const char* format, args_t&& ... args) {
202 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
203 write_line_(xtd::string::format(format, args...));
204 #endif
205 }
207
211 static void trace_error(const xtd::string& message) {
212 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
213 trace_event_(trace_event_type::error, message);
214 #endif
215 }
220 template<typename ...objects>
221 static void trace_error(const xtd::string& message, const objects& ... args) {
222 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
223 trace_event_(trace_event_type::error, message, args...);
224 #endif
225 }
226
230 static void trace_information(const xtd::string& message) {
231 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
232 trace_event_(trace_event_type::information, message);
233 #endif
234 }
239 template<typename ...objects>
240 static void trace_information(const xtd::string& message, const objects& ... args) {
241 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
242 trace_event_(trace_event_type::information, xtd::string::format(message, args...));
243 #endif
244 }
245
249 static void trace_warning(const xtd::string& message) {
250 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
251 trace_event_(trace_event_type::warning, message);
252 #endif
253 }
258 template<typename ...objects>
259 static void trace_warning(const xtd::string& message, const objects& ... args) {
260 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
261 trace_event_(trace_event_type::warning, xtd::string::format(message, args...));
262 #endif
263 }
264
266 static void unindent() noexcept;
267
272 static void write(const xtd::string& message) {
273 #if defined(TRACE)
274 write_(message);
275 #endif
276 }
277
282 template<typename object_t>
283 static void write(const object_t& message) {
284 #if defined(TRACE)
285 write_(xtd::string::format("{}", message));
286 #endif
287 }
294 template<typename object_t>
295 static void write(const object_t& message, const xtd::string& category) {
296 #if defined(TRACE)
297 write_(xtd::string::format("{}", message), category);
298 #endif
299 }
305 template<typename ...args_t>
306 static void write(const xtd::string& format, args_t&& ... args) {
307 #if defined(TRACE)
308 write_(string::format(format, args...));
309 #endif
310 }
312 template<typename ...args_t>
313 static void write(const char* format, args_t&& ... args) {
314 #if defined(TRACE)
315 write_(string::format(format, args...));
316 #endif
317 }
319
325 static void write_if(bool condition, const xtd::string& message) {
326 #if defined(TRACE)
327 if (condition) write_(message);
328 #endif
329 }
335 template<typename object_t>
336 static void write_if(bool condition, const object_t& message) {
337 #if defined(TRACE)
338 if (condition) write_(xtd::string::format("{}", message));
339 #endif
340 }
347 template<typename object_t>
348 static void write_if(bool condition, const object_t& message, const xtd::string& category) {
349 #if defined(TRACE)
350 if (condition) write_(xtd::string::format("{}", message), category);
351 #endif
352 }
353
358 static void write_line() {
359 #if defined(TRACE)
360 write_line_("");
361 #endif
362 }
367 static void write_line(const xtd::string& message) {
368 #if defined(TRACE)
369 write_line_(message);
370 #endif
371 }
376 template<typename object_t>
377 static void write_line(const object_t& message) {
378 #if defined(TRACE)
379 write_line_(xtd::string::format("{}", message));
380 #endif
381 }
388 template<typename object_t>
389 static void write_line(const object_t& message, const xtd::string& category) {
390 #if defined(TRACE)
391 write_line_(xtd::string::format("{}", message), category);
392 #endif
393 }
398 template<typename ...args_t>
399 static void write_line(const xtd::string& format, args_t&& ... args) {
400 #if defined(TRACE)
401 write_line_(xtd::string::format(format, args...));
402 #endif
403 }
405 template<typename ...args_t>
406 static void write_line(const char* format, args_t&& ... args) {
407 #if defined(TRACE)
408 write_line_(xtd::string::format(format, args...));
409 #endif
410 }
412
418 static void write_line_if(bool condition, const xtd::string& message) {
419 #if defined(TRACE)
420 if (condition) write_line_(message);
421 #endif
422 }
428 template<typename object_t>
429 static void write_line_if(bool condition, const object_t& message) {
430 #if defined(TRACE)
431 if (condition) write_line_(xtd::string::format("{}", message));
432 #endif
433 }
440 template<typename object_t>
441 static void write_line_if(bool condition, const object_t& message, const xtd::string& category) {
442 #if defined(TRACE)
443 if (condition) write_line_(xtd::string::format("{}", message), category);
444 #endif
445 }
447
449 static inline bool __should_aborted__(bool condition) { return __should_aborted__(condition, xtd::string::empty_string, csf_); }
450 static inline bool __should_aborted__(bool condition, const xtd::string& message) {return __should_aborted__(condition, message, csf_);}
451 static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame) {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) {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) {return __should_aborted__(condition, message, detail_message, csf_);}
454 static inline bool __should_aborted__(bool condition, const xtd::string& message, const xtd::string& detail_message, const xtd::diagnostics::stack_frame& stack_frame) {
455 #if defined(TRACE)
456 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
458 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
459 #endif
460 return false;
461 }
463
464 private:
465 static void fail__(const xtd::string& message);
466 static void fail__(const xtd::string& message, const xtd::string& detail_message);
467 static void flush_();
468 static void trace_event_(trace_event_type trace_event_type, const xtd::string& message);
469 static void write_(const xtd::string& message);
470 static void write_(const xtd::string& message, const xtd::string& category);
471 static void write_line_(const xtd::string& message);
472 static void write_line_(const xtd::string& message, const xtd::string& category);
473
474 inline static bool auto_flush_ = false;
475 inline static uint32 indent_level_ = 0;
476 inline static uint32 indent_size_ = 4;
477 static listener_collection& listeners_;
478 inline static bool use_global_lock_ = true;
479 static xtd::string source_name_;
480 };
481 }
482}
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.h:124
Represents text as a sequence of character units.
Definition basic_string.h:79
Provides the default output methods and behavior for tracing.
Definition default_trace_listener.h:33
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.h:40
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.h:29
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition trace.h:358
static void trace_information(const xtd::string &message, const objects &... args)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace.h:240
static bool auto_flush() noexcept
Gets whether Flush should be called on the Listeners after every write.
static void write(const xtd::string &format, args_t &&... args)
Writes a formatted string to the trace listeners in the listeners collection.
Definition trace.h:306
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 trace.h:367
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 trace.h:399
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 trace.h:429
static void trace_error(const xtd::string &message, const objects &... args)
Writes an error message to the trace listeners in the listeners collection using the specified array ...
Definition trace.h:221
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 trace.h:211
static void trace_information(const xtd::string &message)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace.h:230
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 trace.h:249
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition trace.h:283
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 trace.h:336
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 trace.h:441
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 trace.h:389
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition trace.h:172
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 trace.h:194
static void fail(const xtd::string &message, const xtd::string &detail_message)
Emits an error message and a detailed error message.
Definition trace.h:165
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 trace.h:325
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 trace.h:295
static void trace_warning(const xtd::string &message, const objects &... args)
Writes a warning message to the trace listeners in the listeners collection using the specified array...
Definition trace.h:259
static void unindent() noexcept
Decreases the current indent_level by one.
static void indent() noexcept
Increases the current indent_level by one.
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 trace.h:418
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 trace.h:377
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 trace.h:348
Provides a set of methods and properties that help you debug the execution of your code....
Definition trace.h:40
static void exit()
Terminates this process and returns an exit code to the operating system.
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:114
Contains xtd::diagnostics::debug class.
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 ...
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define core_export_
Define shared library export.
Definition core_export.h:13
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.h:23
@ 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).
@ print
The PRINT key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10