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 {
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
95 static bool use_global_lock() noexcept;
99 static void use_global_lock(bool use_global_lock) noexcept;
101
103
108 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
113 static void cassert(bool condition, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
119 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());
120
125 static void fail(const xtd::string& message) {
126 #if defined(TRACE)
127 fail__(message);
128 #endif
129 }
130
135 static void fail(const xtd::string& message, const xtd::string& detail_message) {
136 #if defined(TRACE)
137 fail__(message, detail_message);
138 #endif
139 }
140
142 static void flush() {
143 #if defined(TRACE)
144 flush_();
145 #endif
146 }
147
149 static void indent() noexcept;
150
154 static void print(const xtd::string& message) {
155 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
156 write_line_(message);
157 #endif
158 }
159
163 template<class ...args_t>
164 static void print(const xtd::string& format, args_t&& ... args) {
165 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
166 write_line_(xtd::string::format(format, args...));
167 #endif
168 }
169
170 template<class ...args_t>
171 static void print(const char* format, args_t&& ... args) {
172 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
173 write_line_(xtd::string::format(format, args...));
174 #endif
175 }
177
181 static void trace_error(const xtd::string& message) {
182 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
183 trace_event_(trace_event_type::error, message);
184 #endif
185 }
186
190 template<class ...objects>
191 static void trace_error(const xtd::string& message, const objects& ... args) {
192 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
193 trace_event_(trace_event_type::error, message, args...);
194 #endif
195 }
196
200 static void trace_information(const xtd::string& message) {
201 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
202 trace_event_(trace_event_type::information, message);
203 #endif
204 }
205
209 template<class ...objects>
210 static void trace_information(const xtd::string& message, const objects& ... args) {
211 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
212 trace_event_(trace_event_type::information, xtd::string::format(message, args...));
213 #endif
214 }
215
219 static void trace_warning(const xtd::string& message) {
220 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
221 trace_event_(trace_event_type::warning, message);
222 #endif
223 }
224
228 template<class ...objects>
229 static void trace_warning(const xtd::string& message, const objects& ... args) {
230 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
231 trace_event_(trace_event_type::warning, xtd::string::format(message, args...));
232 #endif
233 }
234
236 static void unindent() noexcept;
237
242 static void write(const xtd::string& message) {
243 #if defined(TRACE)
244 write_(message);
245 #endif
246 }
247
252 template<class object_t>
253 static void write(const object_t& message) {
254 #if defined(TRACE)
255 write_(xtd::string::format("{}", message));
256 #endif
257 }
258
264 template<class object_t>
265 static void write(const object_t& message, const xtd::string& category) {
266 #if defined(TRACE)
267 write_(xtd::string::format("{}", message), category);
268 #endif
269 }
270
275 template<class ...args_t>
276 static void write(const xtd::string& format, args_t&& ... args) {
277 #if defined(TRACE)
278 write_(string::format(format, args...));
279 #endif
280 }
281
282 template<class ...args_t>
283 static void write(const char* format, args_t&& ... args) {
284 #if defined(TRACE)
285 write_(string::format(format, args...));
286 #endif
287 }
289
295 static void write_if(bool condition, const xtd::string& message) {
296 #if defined(TRACE)
297 if (condition) write_(message);
298 #endif
299 }
300
305 template<class object_t>
306 static void write_if(bool condition, const object_t& message) {
307 #if defined(TRACE)
308 if (condition) write_(xtd::string::format("{}", message));
309 #endif
310 }
311
317 template<class object_t>
318 static void write_if(bool condition, const object_t& message, const xtd::string& category) {
319 #if defined(TRACE)
320 if (condition) write_(xtd::string::format("{}", message), category);
321 #endif
322 }
323
328 static void write_line() {
329 #if defined(TRACE)
330 write_line_("");
331 #endif
332 }
333
337 static void write_line(const xtd::string& message) {
338 #if defined(TRACE)
339 write_line_(message);
340 #endif
341 }
342
346 template<class object_t>
347 static void write_line(const object_t& message) {
348 #if defined(TRACE)
349 write_line_(xtd::string::format("{}", message));
350 #endif
351 }
352
358 template<class object_t>
359 static void write_line(const object_t& message, const xtd::string& category) {
360 #if defined(TRACE)
361 write_line_(xtd::string::format("{}", message), category);
362 #endif
363 }
364
368 template<class ...args_t>
369 static void write_line(const xtd::string& format, args_t&& ... args) {
370 #if defined(TRACE)
371 write_line_(xtd::string::format(format, args...));
372 #endif
373 }
374
375 template<class ...args_t>
376 static void write_line(const char* format, args_t&& ... args) {
377 #if defined(TRACE)
378 write_line_(xtd::string::format(format, args...));
379 #endif
380 }
382
388 static void write_line_if(bool condition, const xtd::string& message) {
389 #if defined(TRACE)
390 if (condition) write_line_(message);
391 #endif
392 }
393
398 template<class object_t>
399 static void write_line_if(bool condition, const object_t& message) {
400 #if defined(TRACE)
401 if (condition) write_line_(xtd::string::format("{}", message));
402 #endif
403 }
404
410 template<class object_t>
411 static void write_line_if(bool condition, const object_t& message, const xtd::string& category) {
412 #if defined(TRACE)
413 if (condition) write_line_(xtd::string::format("{}", message), category);
414 #endif
415 }
416
417
419 static inline bool __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition) {return __should_aborted__(stack_frame, condition, xtd::string::empty_string);}
420 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);}
421 static inline bool __should_aborted__(const xtd::diagnostics::stack_frame& stack_frame, bool condition, const xtd::string& message, const xtd::string& detail_message) {
422 #if defined(TRACE)
423 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
425 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
426 #endif
427 return false;
428 }
430
432
439 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
440 static bool show_assert_dialog() noexcept;
446 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0.")]]
447 static void show_assert_dialog(bool show_assert_dialog) noexcept;
449
450 private:
451 static void fail__(const xtd::string& message);
452 static void fail__(const xtd::string& message, const xtd::string& detail_message);
453 static void flush_();
454 static void trace_event_(trace_event_type trace_event_type, const xtd::string& message);
455 static void write_(const xtd::string& message);
456 static void write_(const xtd::string& message, const xtd::string& category);
457 static void write_line_(const xtd::string& message);
458 static void write_line_(const xtd::string& message, const xtd::string& category);
459
460 inline static bool auto_flush_ = false;
461 inline static uint32 indent_level_ = 0;
462 inline static uint32 indent_size_ = 4;
463 static listener_collection& listeners_;
464 inline static bool use_global_lock_ = true;
465 static xtd::string source_name_;
466 };
467 }
468}
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:40
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:328
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:210
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:276
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:337
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:369
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:399
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:191
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:181
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:200
static void write(const xtd::string &message)
Writes a message to the trace listeners in the listeners collection.
Definition trace.hpp:242
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 listener_collection & listeners() noexcept
Gets the collection of listeners that is monitoring the trace output.
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:46
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:219
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition trace.hpp:253
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:306
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:411
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:359
static void fail(const xtd::string &message)
Emits the specified error message.
Definition trace.hpp:125
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition trace.hpp:142
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:164
static void fail(const xtd::string &message, const xtd::string &detail_message)
Emits an error message and a detailed error message.
Definition trace.hpp:135
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:295
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:265
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:229
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:388
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:154
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:347
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:318
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