Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
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 instantiating the object and directly calling the () operator. This is used to mimic variadic macros.

This class is used to define the following macros:

  • Macros for tracing: vpTRACE(), vpERROR_TRACE(), vpIN_FCT() and vpOUT_FCT() work like printf with career return at the end of the string, while vpCTRACE() and vpCERROR() work like the C++ output streams std::cout and std::cerr.
  • Macros for debugging: vpDEBUG_TRACE(level) and vpDERROR_TRACE(level) work like printf, but print only if the tracing level level is greater than the debug level VP_DEBUG_MODE macro. vpCDEBUG(level) work like the C++ output stream std::cout. vpDEBUG_ENABLE(level) is equal to 1 if the debug level level is greater than the debug mode VP_DEBUG_MODE, 0 else.

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>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
vpIN_FCT("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
vpOUT_FCT("main()");
}

Definition at line 137 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 
)
inline

Constructor.

Parameters
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).
Note
Call the constructor with something like vpTraceOutput(FILE,LINE, FUNCTION).

Definition at line 150 of file vpDebug.h.

Member Function Documentation

◆ display()

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

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

Parameters
formatFormating string.
argsList of arguments.

Definition at line 210 of file vpDebug.h.

Referenced by operator()().

◆ operator()() [1/2]

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

Displays a string.

Parameters
formatFormating string.

Definition at line 185 of file vpDebug.h.

References display().

◆ operator()() [2/2]

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

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

Parameters
levelLevel of this message.
formatString format.

Definition at line 159 of file vpDebug.h.

References display().