xtd 0.2.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 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
89
93 static bool use_global_lock() noexcept;
97 static void use_global_lock(bool use_global_lock) noexcept;
99
101
106 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
111 static void cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
117 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());
118
123 static void fail(const xtd::string& message) {
124 #if TRACE
125 fail__(message);
126 #endif
127 }
128
133 static void fail(const xtd::string& message, const xtd::string& detail_message) {
134 #if TRACE
135 fail__(message, detail_message);
136 #endif
137 }
138
140 static void flush() {
141 #if TRACE
142 flush_();
143 #endif
144 }
145
147 static void indent() noexcept;
148
152 static void print(const xtd::string& message) {
153 #if TRACE
154 write_line_(message);
155 #endif
156 }
157
161 template<class ...args_t>
162 static void print(const xtd::string& format, args_t&& ... args) {
163 #if TRACE
164 write_line_(xtd::string::format(format, args...));
165 #endif
166 }
167
168 template<class ...args_t>
169 static void print(const char* format, args_t&& ... args) {
170 #if TRACE
171 write_line_(xtd::string::format(format, args...));
172 #endif
173 }
175
179 static void trace_error(const xtd::string& message) {
180 #if TRACE
181 trace_event_(trace_event_type::error, message);
182 #endif
183 }
184
188 template<class ...objects>
189 static void trace_error(const xtd::string& message, const objects& ... args) {
190 #if TRACE
191 trace_event_(trace_event_type::error, message, args...);
192 #endif
193 }
194
198 static void trace_information(const xtd::string& message) {
199 #if TRACE
200 trace_event_(trace_event_type::information, message);
201 #endif
202 }
203
207 template<class ...objects>
208 static void trace_information(const xtd::string& message, const objects& ... args) {
209 #if TRACE
210 trace_event_(trace_event_type::information, xtd::string::format(message, args...));
211 #endif
212 }
213
217 static void trace_warning(const xtd::string& message) {
218 #if TRACE
219 trace_event_(trace_event_type::warning, message);
220 #endif
221 }
222
226 template<class ...objects>
227 static void trace_warning(const xtd::string& message, const objects& ... args) {
228 #if TRACE
229 trace_event_(trace_event_type::warning, xtd::string::format(message, args...));
230 #endif
231 }
232
234 static void unindent() noexcept;
235
240 static void write(const xtd::string& message) {
241 #if TRACE
242 write_(message);
243 #endif
244 }
245
250 template<class object_t>
251 static void write(const object_t& message) {
252 #if TRACE
253 write_(xtd::string::format("{}", message));
254 #endif
255 }
256
262 template<class object_t>
263 static void write(const object_t& message, const xtd::string& category) {
264 #if TRACE
265 write_(xtd::string::format("{}", message), category);
266 #endif
267 }
268
273 template<class ...args_t>
274 static void write(const xtd::string& format, args_t&& ... args) {
275 #if TRACE
276 write_(string::format(format, args...));
277 #endif
278 }
279
280 template<class ...args_t>
281 static void write(const char* format, args_t&& ... args) {
282 #if TRACE
283 write_(string::format(format, args...));
284 #endif
285 }
287
293 static void write_if(bool condition, const xtd::string& message) {
294 #if TRACE
295 if (condition) write_(message);
296 #endif
297 }
298
303 template<class object_t>
304 static void write_if(bool condition, const object_t& message) {
305 #if TRACE
306 if (condition) write_(xtd::string::format("{}", message));
307 #endif
308 }
309
315 template<class object_t>
316 static void write_if(bool condition, const object_t& message, const xtd::string& category) {
317 #if TRACE
318 if (condition) write_(xtd::string::format("{}", message), category);
319 #endif
320 }
321
326 static void write_line() {
327 #if TRACE
328 write_line_("");
329 #endif
330 }
331
335 static void write_line(const xtd::string& message) {
336 #if TRACE
337 write_line_(message);
338 #endif
339 }
340
344 template<class object_t>
345 static void write_line(const object_t& message) {
346 #if TRACE
347 write_line_(xtd::string::format("{}", message));
348 #endif
349 }
350
356 template<class object_t>
357 static void write_line(const object_t& message, const xtd::string& category) {
358 #if TRACE
359 write_line_(xtd::string::format("{}", message), category);
360 #endif
361 }
362
366 template<class ...args_t>
367 static void write_line(const xtd::string& format, args_t&& ... args) {
368 #if TRACE
369 write_line_(xtd::string::format(format, args...));
370 #endif
371 }
372
373 template<class ...args_t>
374 static void write_line(const char* format, args_t&& ... args) {
375 #if TRACE
376 write_line_(xtd::string::format(format, args...));
377 #endif
378 }
380
386 static void write_line_if(bool condition, const xtd::string& message) {
387 #if TRACE
388 if (condition) write_line_(message);
389 #endif
390 }
391
396 template<class object_t>
397 static void write_line_if(bool condition, const object_t& message) {
398 #if TRACE
399 if (condition) write_line_(xtd::string::format("{}", message));
400 #endif
401 }
402
408 template<class object_t>
409 static void write_line_if(bool condition, const object_t& message, const xtd::string& category) {
410 #if TRACE
411 if (condition) write_line_(xtd::string::format("{}", message), category);
412 #endif
413 }
414
415
417 static inline bool __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition) {return __should_aborted__(stack_frame, condition, xtd::string::empty_string);}
418 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);}
419 static inline bool __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message, const xtd::string& detail_message) {
420 #if TRACE
421 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
423 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
424 #endif
425 return false;
426 }
428
430
437 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
438 static bool show_assert_dialog() noexcept;
444 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
445 static void show_assert_dialog(bool show_assert_dialog) noexcept;
447
448 private:
449 static void fail__(const xtd::string& message);
450 static void fail__(const xtd::string& message, const xtd::string& detail_message);
451 static void flush_();
452 static void trace_event_(trace_event_type trace_event_type, const xtd::string& message);
453 static void write_(const xtd::string& message);
454 static void write_(const xtd::string& message, const xtd::string& category);
455 static void write_line_(const xtd::string& message);
456 static void write_line_(const xtd::string& message, const xtd::string& category);
457
458 inline static bool auto_flush_ = false;
459 inline static uint32 indent_level_ = 0;
460 inline static uint32 indent_size_ = 4;
461 static listener_collection& listeners_;
462 inline static bool use_global_lock_ = true;
463 };
464 }
465}
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:38
static uint32 indent_size() noexcept
Gets the number of spaces in an indent.
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition trace.hpp:326
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.hpp:208
static bool use_global_lock() noexcept
Gets a value indicating whether the global lock should be used.
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.hpp:274
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.hpp:335
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.hpp:367
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.hpp:397
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.hpp:189
static uint32 indent_level() noexcept
Gets the indent level.
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.hpp:179
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.hpp:198
static void write(const xtd::string &message)
Writes a message to the trace listeners in the listeners collection.
Definition trace.hpp:240
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 bool show_assert_dialog() noexcept
Gets a value indicating whether the assert dialog should be show.
xtd::diagnostics::trace_listener_collection listener_collection
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace.hpp:44
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.hpp:217
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition trace.hpp:251
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.hpp:304
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.hpp:409
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.hpp:357
static void fail(const xtd::string &message)
Emits the specified error message.
Definition trace.hpp:123
static listener_collection & listeners()
Gets the collection of listeners that is monitoring the trace output.
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition trace.hpp:140
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.hpp:162
static void fail(const xtd::string &message, const xtd::string &detail_message)
Emits an error message and a detailed error message.
Definition trace.hpp:133
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.hpp:293
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.hpp:263
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.hpp:227
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.hpp:386
static void print(const xtd::string &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition trace.hpp:152
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.hpp:345
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.hpp:316
static void exit()
Terminates this process and returns an exit code to the operating system.
Contains xtd::diagnostics::debug 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
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
void print(FILE *file, arg_t &&value)
Writes the text representation of the specified value to the file output stream.
Definition print.hpp:19