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
123 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
128 static void cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
134 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());
135
140 static void fail(const xtd::string& message) {
141 #if defined(TRACE)
142 fail__(message);
143 #endif
144 }
150 static void fail(const xtd::string& message, const xtd::string& detail_message) {
151 #if defined(TRACE)
152 fail__(message, detail_message);
153 #endif
154 }
155
157 static void flush() {
158 #if defined(TRACE)
159 flush_();
160 #endif
161 }
162
164 static void indent() noexcept;
165
169 static void print(const xtd::string& message) {
170 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
171 write_line_(message);
172 #endif
173 }
178 template<typename ...args_t>
179 static void print(const xtd::string& format, args_t&& ... args) {
180 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
181 write_line_(xtd::string::format(format, args...));
182 #endif
183 }
185 template<typename ...args_t>
186 static void print(const char* format, args_t&& ... args) {
187 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
188 write_line_(xtd::string::format(format, args...));
189 #endif
190 }
192
196 static void trace_error(const xtd::string& message) {
197 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
198 trace_event_(trace_event_type::error, message);
199 #endif
200 }
205 template<typename ...objects>
206 static void trace_error(const xtd::string& message, const objects& ... args) {
207 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
208 trace_event_(trace_event_type::error, message, args...);
209 #endif
210 }
211
215 static void trace_information(const xtd::string& message) {
216 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
217 trace_event_(trace_event_type::information, message);
218 #endif
219 }
224 template<typename ...objects>
225 static void trace_information(const xtd::string& message, const objects& ... args) {
226 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
227 trace_event_(trace_event_type::information, xtd::string::format(message, args...));
228 #endif
229 }
230
234 static void trace_warning(const xtd::string& message) {
235 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
236 trace_event_(trace_event_type::warning, message);
237 #endif
238 }
243 template<typename ...objects>
244 static void trace_warning(const xtd::string& message, const objects& ... args) {
245 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
246 trace_event_(trace_event_type::warning, xtd::string::format(message, args...));
247 #endif
248 }
249
251 static void unindent() noexcept;
252
257 static void write(const xtd::string& message) {
258 #if defined(TRACE)
259 write_(message);
260 #endif
261 }
262
267 template<typename object_t>
268 static void write(const object_t& message) {
269 #if defined(TRACE)
270 write_(xtd::string::format("{}", message));
271 #endif
272 }
279 template<typename object_t>
280 static void write(const object_t& message, const xtd::string& category) {
281 #if defined(TRACE)
282 write_(xtd::string::format("{}", message), category);
283 #endif
284 }
290 template<typename ...args_t>
291 static void write(const xtd::string& format, args_t&& ... args) {
292 #if defined(TRACE)
293 write_(string::format(format, args...));
294 #endif
295 }
297 template<typename ...args_t>
298 static void write(const char* format, args_t&& ... args) {
299 #if defined(TRACE)
300 write_(string::format(format, args...));
301 #endif
302 }
304
310 static void write_if(bool condition, const xtd::string& message) {
311 #if defined(TRACE)
312 if (condition) write_(message);
313 #endif
314 }
320 template<typename object_t>
321 static void write_if(bool condition, const object_t& message) {
322 #if defined(TRACE)
323 if (condition) write_(xtd::string::format("{}", message));
324 #endif
325 }
332 template<typename object_t>
333 static void write_if(bool condition, const object_t& message, const xtd::string& category) {
334 #if defined(TRACE)
335 if (condition) write_(xtd::string::format("{}", message), category);
336 #endif
337 }
338
343 static void write_line() {
344 #if defined(TRACE)
345 write_line_("");
346 #endif
347 }
352 static void write_line(const xtd::string& message) {
353 #if defined(TRACE)
354 write_line_(message);
355 #endif
356 }
361 template<typename object_t>
362 static void write_line(const object_t& message) {
363 #if defined(TRACE)
364 write_line_(xtd::string::format("{}", message));
365 #endif
366 }
373 template<typename object_t>
374 static void write_line(const object_t& message, const xtd::string& category) {
375 #if defined(TRACE)
376 write_line_(xtd::string::format("{}", message), category);
377 #endif
378 }
383 template<typename ...args_t>
384 static void write_line(const xtd::string& format, args_t&& ... args) {
385 #if defined(TRACE)
386 write_line_(xtd::string::format(format, args...));
387 #endif
388 }
390 template<typename ...args_t>
391 static void write_line(const char* format, args_t&& ... args) {
392 #if defined(TRACE)
393 write_line_(xtd::string::format(format, args...));
394 #endif
395 }
397
403 static void write_line_if(bool condition, const xtd::string& message) {
404 #if defined(TRACE)
405 if (condition) write_line_(message);
406 #endif
407 }
413 template<typename object_t>
414 static void write_line_if(bool condition, const object_t& message) {
415 #if defined(TRACE)
416 if (condition) write_line_(xtd::string::format("{}", message));
417 #endif
418 }
425 template<typename object_t>
426 static void write_line_if(bool condition, const object_t& message, const xtd::string& category) {
427 #if defined(TRACE)
428 if (condition) write_line_(xtd::string::format("{}", message), category);
429 #endif
430 }
432
434 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);}
435 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);}
436 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()) {
437 #if defined(TRACE)
438 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
440 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
441 #endif
442 return false;
443 }
445
446 private:
447 static void fail__(const xtd::string& message);
448 static void fail__(const xtd::string& message, const xtd::string& detail_message);
449 static void flush_();
450 static void trace_event_(trace_event_type trace_event_type, const xtd::string& message);
451 static void write_(const xtd::string& message);
452 static void write_(const xtd::string& message, const xtd::string& category);
453 static void write_line_(const xtd::string& message);
454 static void write_line_(const xtd::string& message, const xtd::string& category);
455
456 inline static bool auto_flush_ = false;
457 inline static uint32 indent_level_ = 0;
458 inline static uint32 indent_size_ = 4;
459 static listener_collection& listeners_;
460 inline static bool use_global_lock_ = true;
461 static xtd::string source_name_;
462 };
463 }
464}
Represents text as a sequence of character units.
Definition basic_string.h:79
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.h:124
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: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.h:29
Provides a set of methods and properties that help you debug the execution of your code....
Definition trace.h:40
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition trace.h:343
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:225
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:291
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:352
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:384
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:414
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:206
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:196
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: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 trace.h:234
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition trace.h:268
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:321
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:426
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:374
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition trace.h:157
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:179
static void fail(const xtd::string &message, const xtd::string &detail_message)
Emits an error message and a detailed error message.
Definition trace.h:150
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:310
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:280
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:244
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:403
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:362
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:333
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
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