xtd 0.2.0
trace.h
Go to the documentation of this file.
1 #pragma once
5 #include "debug.h"
6 
8 namespace xtd {
10  namespace diagnostics {
38  class core_export_ trace static_ {
39  public:
41 
46 
48 
54  static bool auto_flush() noexcept;
59  static void auto_flush(bool auto_flush) noexcept;
60 
64  static uint32 indent_level() noexcept;
68  static void indent_level(uint32 indent_level) noexcept;
69 
73  static uint32 indent_size() noexcept;
77  static void indent_size(uint32 indent_size) noexcept;
78 
83  static listener_collection& listeners() noexcept;
88  static void listeners(const listener_collection& listeners) noexcept;
89 
94  static bool show_assert_dialog() noexcept;
99  static void show_assert_dialog(bool show_assert_dialog) noexcept;
100 
104  static bool use_global_lock() noexcept;
108  static void use_global_lock(bool use_global_lock) noexcept;
110 
112 
119  static void cassert(bool condition);
123  static void cassert(bool condition, const xtd::ustring& message);
128  static void cassert(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame);
133  static void cassert(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message);
139  static void cassert(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message, const xtd::diagnostics::stack_frame& stack_frame);
143  static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame);
144 
149  static void fail(const xtd::ustring& message) {
150  #if defined(TRACE)
151  fail__(message);
152  #endif
153  }
159  static void fail(const xtd::ustring& message, const xtd::ustring& detail_message) {
160  #if defined(TRACE)
161  fail__(message, detail_message);
162  #endif
163  }
164 
166  static void flush() {
167  #if defined(TRACE)
168  flush_();
169  #endif
170  }
171 
173  static void indent() noexcept;
174 
178  static void print(const xtd::ustring& message) {
179  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
180  write_line_(message);
181  #endif
182  }
187  template<typename ...args_t>
188  static void print(const xtd::ustring& format, args_t&& ... args) {
189  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
190  write_line_(xtd::ustring::format(format, args...));
191  #endif
192  }
194  template<typename ...args_t>
195  static void print(const char* format, args_t&& ... args) {
196  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
197  write_line_(xtd::ustring::format(format, args...));
198  #endif
199  }
201 
205  static void trace_error(const xtd::ustring& message) {
206  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
207  trace_event_(trace_event_type::error, message);
208  #endif
209  }
214  template<typename ...objects>
215  static void trace_error(const xtd::ustring& message, const objects& ... args) {
216  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
217  trace_event_(trace_event_type::error, message, args...);
218  #endif
219  }
220 
224  static void trace_information(const xtd::ustring& message) {
225  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
226  trace_event_(trace_event_type::information, message);
227  #endif
228  }
233  template<typename ...objects>
234  static void trace_information(const xtd::ustring& message, const objects& ... args) {
235  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
236  trace_event_(trace_event_type::information, xtd::ustring::format(message, args...));
237  #endif
238  }
239 
243  static void trace_warning(const xtd::ustring& message) {
244  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
245  trace_event_(trace_event_type::warning, message);
246  #endif
247  }
252  template<typename ...objects>
253  static void trace_warning(const xtd::ustring& message, const objects& ... args) {
254  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
255  trace_event_(trace_event_type::warning, xtd::ustring::format(message, args...));
256  #endif
257  }
258 
260  static void unindent() noexcept;
261 
266  static void write(const xtd::ustring& message) {
267  #if defined(TRACE)
268  write_(message);
269  #endif
270  }
271 
276  template<typename object_t>
277  static void write(const object_t& message) {
278  #if defined(TRACE)
279  write_(xtd::ustring::format("{}", message));
280  #endif
281  }
288  template<typename object_t>
289  static void write(const object_t& message, const xtd::ustring& category) {
290  #if defined(TRACE)
291  write_(xtd::ustring::format("{}", message), category);
292  #endif
293  }
299  template<typename ...args_t>
300  static void write(const xtd::ustring& format, args_t&& ... args) {
301  #if defined(TRACE)
302  write_(ustring::format(format, args...));
303  #endif
304  }
306  template<typename ...args_t>
307  static void write(const char* format, args_t&& ... args) {
308  #if defined(TRACE)
309  write_(ustring::format(format, args...));
310  #endif
311  }
313 
319  static void write_if(bool condition, const xtd::ustring& message) {
320  #if defined(TRACE)
321  if (condition) write_(message);
322  #endif
323  }
329  template<typename object_t>
330  static void write_if(bool condition, const object_t& message) {
331  #if defined(TRACE)
332  if (condition) write_(xtd::ustring::format("{}", message));
333  #endif
334  }
341  template<typename object_t>
342  static void write_if(bool condition, const object_t& message, const xtd::ustring& category) {
343  #if defined(TRACE)
344  if (condition) write_(xtd::ustring::format("{}", message), category);
345  #endif
346  }
347 
352  static void write_line() {
353  #if defined(TRACE)
354  write_line_("");
355  #endif
356  }
361  static void write_line(const xtd::ustring& message) {
362  #if defined(TRACE)
363  write_line_(message);
364  #endif
365  }
370  template<typename object_t>
371  static void write_line(const object_t& message) {
372  #if defined(TRACE)
373  write_line_(xtd::ustring::format("{}", message));
374  #endif
375  }
382  template<typename object_t>
383  static void write_line(const object_t& message, const xtd::ustring& category) {
384  #if defined(TRACE)
385  write_line_(xtd::ustring::format("{}", message), category);
386  #endif
387  }
392  template<typename ...args_t>
393  static void write_line(const xtd::ustring& format, args_t&& ... args) {
394  #if defined(TRACE)
395  write_line_(xtd::ustring::format(format, args...));
396  #endif
397  }
399  template<typename ...args_t>
400  static void write_line(const char* format, args_t&& ... args) {
401  #if defined(TRACE)
402  write_line_(xtd::ustring::format(format, args...));
403  #endif
404  }
406 
412  static void write_line_if(bool condition, const xtd::ustring& message) {
413  #if defined(TRACE)
414  if (condition) write_line_(message);
415  #endif
416  }
422  template<typename object_t>
423  static void write_line_if(bool condition, const object_t& message) {
424  #if defined(TRACE)
425  if (condition) write_line_(xtd::ustring::format("{}", message));
426  #endif
427  }
434  template<typename object_t>
435  static void write_line_if(bool condition, const object_t& message, const xtd::ustring& category) {
436  #if defined(TRACE)
437  if (condition) write_line_(xtd::ustring::format("{}", message), category);
438  #endif
439  }
441 
443  static inline bool __should_aborted__(bool condition) { return __should_aborted__(condition, "", csf_); }
444  static inline bool __should_aborted__(bool condition, const xtd::ustring& message) {return __should_aborted__(condition, message, csf_);}
445  static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, "", stack_frame);}
446  static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, message, "", stack_frame);}
447  static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message) {return __should_aborted__(condition, message, detail_message, csf_);}
448  static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message, const xtd::diagnostics::stack_frame& stack_frame) {
449  #if defined(TRACE)
450  auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
452  if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
453  #endif
454  return false;
455  }
457 
458  private:
459  static void fail__(const xtd::ustring& message);
460  static void fail__(const xtd::ustring& message, const xtd::ustring& detail_message);
461  static void flush_();
462  static void trace_event_(trace_event_type trace_event_type, const xtd::ustring& message);
463  static void write_(const xtd::ustring& message);
464  static void write_(const xtd::ustring& message, const xtd::ustring& category);
465  static void write_line_(const xtd::ustring& message);
466  static void write_line_(const xtd::ustring& message, const xtd::ustring& category);
467 
468  inline static bool auto_flush_ = false;
469  inline static uint32 indent_level_ = 0;
470  inline static uint32 indent_size_ = 4;
471  static listener_collection& listeners_;
472  static bool& show_assert_dialog_;
473  inline static bool use_global_lock_ = true;
474  static xtd::ustring source_name_;
475  };
476  }
477 }
static void write(const xtd::ustring &format, args_t &&... args)
Writes a formatted string to the trace listeners in the listeners collection.
Definition: trace.h:300
static void write_line(const xtd::ustring &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition: trace.h:393
static void trace_information(const xtd::ustring &message, const objects &... args)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition: trace.h:234
static void trace_warning(const xtd::ustring &message, const objects &... args)
Writes a warning message to the trace listeners in the listeners collection using the specified array...
Definition: trace.h:253
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition: trace.h:166
Contains xtd::diagnostics::debug class.
static void trace_information(const xtd::ustring &message)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition: trace.h:224
#define static_
This keyword is use to represent a static object. A static object can&#39;t be instantiated (constructors...
Definition: static.h:37
static void write_if(bool condition, const object_t &message, const xtd::ustring &category)
Writes a category name and message to the trace listeners in the Listeners collection if a condition ...
Definition: trace.h:342
static void trace_error(const xtd::ustring &message, const objects &... args)
Writes an error message to the trace listeners in the listeners collection using the specified array ...
Definition: trace.h:215
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
#define csf_
Provides information about the current stack frame.
Definition: current_stack_frame.h:30
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:371
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Warning Noncritical problem.
static void write_if(bool condition, const xtd::ustring &message)
Writes a message to the trace listeners in the Listeners collection if a condition is true...
Definition: trace.h:319
static void write_line(const object_t &message, const xtd::ustring &category)
Writes a category name and message followed by a line terminator to the trace listeners in the listen...
Definition: trace.h:383
static void exit()
Terminates this process and returns an exit code to the operating system.
The assert dialog return value is Abort (usually sent from a button labeled Abort).
static void write_line_if(bool condition, const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition: trace.h:412
static void print(const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection...
Definition: trace.h:178
static void write(const object_t &message, const xtd::ustring &category)
Writes a category name and message to the trace listeners in the listeners collection.
Definition: trace.h:289
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition: trace.h:352
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:330
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:423
Represents a collection of xtd::diagnostics::trace_listener.
Definition: trace_listener_collection.h:26
static void trace_warning(const xtd::ustring &message)
Writes a warning message to the trace listeners in the listeners collection using the specified messa...
Definition: trace.h:243
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:37
The assert dialog return value is Retry (usually sent from a button labeled Retry).
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition: trace.h:277
Provides a set of methods and properties that help you debug the execution of your code...
Definition: trace.h:38
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:744
static void print(const xtd::ustring &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition: trace.h:188
static void trace_error(const xtd::ustring &message)
Writes an error message to the trace listeners in the Listeners collection using the specified messag...
Definition: trace.h:205
static void write_line(const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection...
Definition: trace.h:361
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
static void write(const xtd::ustring &message)
Writes a message to the trace listeners in the listeners collection.
Definition: trace.h:266
static void fail(const xtd::ustring &message, const xtd::ustring &detail_message)
Emits an error message and a detailed error message.
Definition: trace.h:159
trace_event_type
Identifies the type of event that has caused the trace.
Definition: trace_event_type.h:23
static void write_line_if(bool condition, const object_t &message, const xtd::ustring &category)
Writes a category name and message followed by a line terminator to the trace listeners in the Listen...
Definition: trace.h:435