Visual Servoing Platform  version 3.6.1 under development (2024-02-13)
vpTraceOutput Class Reference

#include <visp3/core/vpDebug.h>

Public Member Functions

 vpTraceOutput (const char *file, int line, const char *func, bool error=false, const char *s=nullptr)
void operator() (int level, const char *format,...)
void operator() (const char *format,...)
void display (const char *format, va_list args)

Detailed Description

This class is used to display debug or error messages.

It needs to be initialized with the file name, function name and line, of the place where it is created. It is best used by first instanciating the object and directly calling the () operator. This is used to mimic variadic macros.

This class is used to define the following macros:

The example below shows how to use these macros.

#define VP_TRACE // Activate the trace mode
#define VP_DEBUG // Activate the debug mode
#define VP_DEBUG_MODE 2 // Activate debug level 1 and 2
#include <visp3/core/vpDebug.h>
int main()
// Check the active debug levels
std::cout << "Debug level 1 active: " << vpDEBUG_ENABLE(1) << std::endl;
std::cout << "Debug level 2 active: " << vpDEBUG_ENABLE(2) << std::endl;
std::cout << "Debug level 3 active: " << vpDEBUG_ENABLE(3) << std::endl;
// C-like debug printings
vpTRACE("C-like trace"); // stdout
// Printing depend only VP_DEBUG_MODE value is >= 1
vpTRACE(1, "C-like trace level 1"); // stdout
vpERROR_TRACE(1, "C-like error trace level 1"); // stderr
// Printing if VP_DEBUG defined and VP_DEBUG_MODE value >= 2
vpDEBUG_TRACE(2, "C-like debug trace level 2"); // stdout
vpDERROR_TRACE(2, "C-like error trace level 2"); // stderr
// C++-like debug printings
vpCTRACE << "C++-like trace" << std::endl; // stdout
vpCERROR << "C++-like error trace" << std::endl; // stderr
// Printing if VP_DEBUG defined and VP_DEBUG_MODE value >= 2
vpCDEBUG(2) << "C++-like debug trace level 2" << std::endl; // stdout
#define vpCTRACE
Definition: vpDebug.h:329
#define vpCDEBUG(level)
Definition: vpDebug.h:497
#define vpCERROR
Definition: vpDebug.h:356
#define vpIN_FCT
Definition: vpDebug.h:269
#define vpTRACE
Definition: vpDebug.h:405
#define vpOUT_FCT
Definition: vpDebug.h:289
#define vpDEBUG_TRACE
Definition: vpDebug.h:473
#define vpDERROR_TRACE
Definition: vpDebug.h:450
#define vpERROR_TRACE
Definition: vpDebug.h:382
#define vpDEBUG_ENABLE(level)
Definition: vpDebug.h:524

Definition at line 132 of file vpDebug.h.

Constructor & Destructor Documentation

◆ vpTraceOutput()

vpTraceOutput::vpTraceOutput ( const char *  file,
int  line,
const char *  func,
bool  error = false,
const char *  s = nullptr 


fileShould be the name of the file where this constructor was called.
lineShould be the line in file where this constructor was called.
funcShould be the name of the function where this constructor was called.
errorIf true, writes to the error stream.
sString to print before any other message (acts like a header).
Call the constructor with something like vpTraceOutput(FILE,LINE, FUNCTION).

Definition at line 155 of file vpDebug.h.

Member Function Documentation

◆ display()

void vpTraceOutput::display ( const char *  format,
va_list  args 

Displays a message to either stdout or stderr (based on error boolean).

formatFormating string.
argsList of arguments.

Definition at line 213 of file vpDebug.h.

Referenced by operator()().

◆ operator()() [1/2]

void vpTraceOutput::operator() ( const char *  format,

Displays a string.

formatFormating string.

Definition at line 188 of file vpDebug.h.

References display().

◆ operator()() [2/2]

void vpTraceOutput::operator() ( int  level,
const char *  format,

Displays a string if the debug level is inferior to VP_DEBUG_MODE.

levelLevel of this message.
formatString format.

Definition at line 164 of file vpDebug.h.

References display().