SDHLibrary-CPP 0.0.2.10SCHUNK GmbH & Co. KG
C++ access library for SCHUNK Dextrous Hand SDH

SDH::cDBG Class Reference

A class to print colored debug messages. More...

#include <dbg.h>

List of all members.

Public Member Functions

 cDBG (bool flag=false, char const *color="red", std::ostream *fd=&std::cerr)
 ~cDBG ()
void SetFlag (bool flag)
bool GetFlag (void) const
void SetColor (char const *color)
void SetOutput (std::ostream *fd)
void PDM (char const *fmt,...) SDH__attribute__((format(printf

Protected Attributes

char const * debug_color
char const * normal_color
std::ostream * output
bool debug_flag
std::streamsize mywidth

Detailed Description

A class to print colored debug messages.

  • The printing can be switched on or off so the debug code can remain in the code. (default is off)
  • The messages can be colorized (default is red).
  • The output can be redirected. (default is sys.stderr)
  • Debug messages can be printed in a functional way or in C++ stream like way

If the environment variable "SDH_NO_COLOR" is defined then the messages are printed without coloring (usefull for logging or if your terminal does not support colors.

Example:

   #include "sdh/dbg.h"
   d = cDBG( true );
   g = cDBG( true, "green" );

   d.PDM( "This message is printed in default color red" );
   g << "and this one in a nice green ";

   g << "of course you can debug print any objects that have a string representation: " << 08 << 15 << true;

   g << "Messages can be turned of and on, e.g. selected by command line options";
   g.SetFlag(false);
   g << "This messages is not printed";

Constructor & Destructor Documentation

SDH::cDBG::cDBG ( bool  flag = false,
char const *  color = "red",
std::ostream *  fd = &std::cerr 
) [inline]

constructor: construct a cDBG object

Parameters:
flag- the initial state of the flag, if true then messages sent to the object are printed. Default is false. Can be changed with SetFlag()
color- the name of the color to use, default is "red". Can be changed with SetColor()
fd- the ostream to use for output, default is stderr. Can be changed with SetOutput()
SDH::cDBG::~cDBG ( ) [inline]

Member Function Documentation

bool SDH::cDBG::GetFlag ( void  ) const [inline]

Get debug_flag of this cDBG object.

void SDH::cDBG::PDM ( char const *  fmt,
  ... 
)

Print debug messages of printf like fmt, ... in the color set with SetColor, but only if debug_flag is true.

void SDH::cDBG::SetColor ( char const *  color) [inline]

Set debug_color of this cDBG object to color. color is a string like "red", see util.py for valid names.

Attention:
The string is NOT copied, just a pointer is stored
void SDH::cDBG::SetFlag ( bool  flag) [inline]

Set debug_flag of this cDBG object to flag. After setting the flag to true debug messages are printed, else not.

void SDH::cDBG::SetOutput ( std::ostream *  fd) [inline]

Set output of this cDBG object to fd, which must be a file like object like sys.stderr


Member Data Documentation

char const* SDH::cDBG::debug_color [protected]
bool SDH::cDBG::debug_flag [protected]
std::streamsize SDH::cDBG::mywidth [protected]
char const* SDH::cDBG::normal_color [protected]
std::ostream* SDH::cDBG::output [protected]

The documentation for this class was generated from the following file: