QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Macros
Debugging macros

Macros

#define QL_TRACE_ENABLE
 enable tracing More...
 
#define QL_TRACE_DISABLE
 disable tracing More...
 
#define QL_TRACE_ON(out)
 set tracing stream More...
 
#define QL_TRACE(message)
 output tracing information More...
 
#define QL_TRACE_ENTER_FUNCTION
 output tracing information More...
 
#define QL_TRACE_EXIT_FUNCTION
 output tracing information More...
 
#define QL_TRACE_LOCATION
 output tracing information More...
 
#define QL_TRACE_VARIABLE(variable)
 output tracing information More...
 

Detailed Description

For debugging purposes, macros can be used to output information about the code being executed. Instrumenting code as in:

namespace Foo {
int bar(int i) {
if (i == 42) {
QL_TRACE("Right answer, but no question");
} else {
QL_TRACE("Wrong answer");
i *= 2;
}
return i;
}
}
#define QL_TRACE_EXIT_FUNCTION
output tracing information
Definition: tracing.hpp:275
#define QL_TRACE(message)
output tracing information
Definition: tracing.hpp:273
#define QL_TRACE_LOCATION
output tracing information
Definition: tracing.hpp:276
#define QL_TRACE_VARIABLE(variable)
output tracing information
Definition: tracing.hpp:277
#define QL_TRACE_ENTER_FUNCTION
output tracing information
Definition: tracing.hpp:274

will output a trace like the following when the code is run:

trace[3]: Entering int Foo::bar(int)
trace[3]: i = 21
trace[3]: At line 16 in tracing_example.cpp
trace[3]: Wrong answer
trace[3]: i = 42
trace[3]: Exiting int Foo::bar(int)

(the actual output will depend on the compiler and the file names). A word of warning must be added: adding so much tracing to your code might degrade its readability.

Macro Definition Documentation

◆ QL_TRACE_ENABLE

#define QL_TRACE_ENABLE

enable tracing

The statement

#define QL_TRACE_ENABLE
enable tracing
Definition: tracing.hpp:270

can be used to enable tracing. Such statement might be ignored; refer to QL_TRACE for details.

Definition at line 270 of file tracing.hpp.

◆ QL_TRACE_DISABLE

#define QL_TRACE_DISABLE

disable tracing

The statement

#define QL_TRACE_DISABLE
disable tracing
Definition: tracing.hpp:271

can be used to disable tracing. Such statement might be ignored; refer to QL_TRACE for details.

Definition at line 271 of file tracing.hpp.

◆ QL_TRACE_ON

#define QL_TRACE_ON (   out)

set tracing stream

The statement

QL_TRACE_ON(stream);
#define QL_TRACE_ON(out)
set tracing stream
Definition: tracing.hpp:272

can be used to set the stream where tracing messages are output. Such statement might be ignored; refer to QL_TRACE for details.

Definition at line 272 of file tracing.hpp.

◆ QL_TRACE

#define QL_TRACE (   message)

output tracing information

The statement

QL_TRACE(message);

can be used to output a trace of the code being executed. If tracing was disabled during configuration, such statements are removed by the preprocessor for maximum performance; if it was enabled, whether and where the message is output depends on the current settings.

Definition at line 273 of file tracing.hpp.

◆ QL_TRACE_ENTER_FUNCTION

#define QL_TRACE_ENTER_FUNCTION

output tracing information

The statement

can be used at the beginning of a function to trace the fact that the program execution is entering such function. It should be paired with a corresponding QL_TRACE_EXIT_FUNCTION macro. Such statement might be ignored; refer to QL_TRACE for details. Also, function information might not be available depending on the compiler.

Definition at line 274 of file tracing.hpp.

◆ QL_TRACE_EXIT_FUNCTION

#define QL_TRACE_EXIT_FUNCTION

output tracing information

The statement

can be used before returning from a function to trace the fact that the program execution is exiting such function. It should be paired with a corresponding QL_TRACE_ENTER_FUNCTION macro. Such statement might be ignored; refer to QL_TRACE for details. Also, function information might not be available depending on the compiler.

Definition at line 275 of file tracing.hpp.

◆ QL_TRACE_LOCATION

#define QL_TRACE_LOCATION

output tracing information

The statement

can be used to trace the current file and line. Such statement might be ignored; refer to QL_TRACE for details.

Definition at line 276 of file tracing.hpp.

◆ QL_TRACE_VARIABLE

#define QL_TRACE_VARIABLE (   variable)

output tracing information

The statement

can be used to trace the current value of a variable. Such statement might be ignored; refer to QL_TRACE for details. Also, the variable type must allow sending it to an output stream.

Definition at line 277 of file tracing.hpp.