Visual Servoing Platform  version 3.4.0
vpTraceOutput Class Reference

#include <vpDebug.h>

Public Member Functions

 vpTraceOutput (const char *file, int line, const char *func, bool error=false, const char *s=NULL)
 
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()
{
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 ( const char *  file,
int  line,
const char *  func,
bool  error = false,
const char *  s = NULL 
)
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 160 of file vpDebug.h.

Member Function Documentation

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 219 of file vpDebug.h.

Referenced by operator()().

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.
formatFormating string.

Definition at line 170 of file vpDebug.h.

References display().

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

Displays a string.

Parameters
formatFormating string.

Definition at line 194 of file vpDebug.h.

References display().