Logo
~Sockets~
~Examples~
~Contact~


Debug Class Reference

#include <Debug.h>

List of all members.


Public Member Functions

 Debug ()
 Debug (const std::string &x)
 Debug (int id, const std::string &x)
 ~Debug ()
Debugoperator<< (const char *)
Debugoperator<< (const std::string &)
Debugoperator<< (short)
Debugoperator<< (int)
Debugoperator<< (long)
Debugoperator<< (double)
Debugoperator<< (endl)

Static Public Member Functions

static void Print (const char *format,...)

Private Attributes

int m_id
std::string m_text
std::string m_line

Static Private Attributes

static const char * colors []
static std::map< unsigned long,
int > 
m_level

Classes

class  endl

Detailed Description

Definition at line 14 of file Debug.h.


Constructor & Destructor Documentation

Debug::Debug (  )  [inline]

Definition at line 25 of file Debug.h.

00025 {}

Debug::Debug ( const std::string &  x  )  [inline]

Definition at line 26 of file Debug.h.

References Utility::ThreadID().

00026                                   : m_id(0), m_text(x) {
00027                 fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00028                 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00029                         fprintf(stderr, "  ");
00030                 fprintf(stderr, "%s%s\n", x.c_str(), colors[0]);
00031                 m_level[Utility::ThreadID()]++;
00032         }

Debug::Debug ( int  id,
const std::string &  x 
) [inline]

Definition at line 33 of file Debug.h.

References Utility::ThreadID().

00033                                           : m_id(id), m_text(x) {
00034                 fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00035                 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00036                         fprintf(stderr, "  ");
00037                 fprintf(stderr, "%d> %s%s\n", m_id, x.c_str(), colors[0]);
00038                 m_level[Utility::ThreadID()]++;
00039         }

Debug::~Debug (  )  [inline]

Definition at line 40 of file Debug.h.

References Utility::ThreadID().

00040                  {
00041                 if (!m_text.empty())
00042                 {
00043                         if (m_level[Utility::ThreadID()])
00044                                 m_level[Utility::ThreadID()]--;
00045                         fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00046                         for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00047                                 fprintf(stderr, "  ");
00048                         if (m_id)
00049                                 fprintf(stderr, "%d> /%s%s\n", m_id, m_text.c_str(), colors[0]);
00050                         else
00051                                 fprintf(stderr, "/%s%s\n", m_text.c_str(), colors[0]);
00052                         fflush(stderr);
00053                 }
00054         }


Member Function Documentation

void Debug::Print ( const char *  format,
  ... 
) [static]

Definition at line 30 of file Debug.cpp.

References colors, m_level, and Utility::ThreadID().

Referenced by operator<<().

00031 {
00032         char slask[5000]; // temporary for vsprintf / vsnprintf
00033         va_list ap;
00034 
00035         va_start(ap, format);
00036         vsnprintf(slask, sizeof(slask), format, ap);
00037         va_end(ap);
00038 
00039         fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00040         for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00041                 fprintf(stderr, "  ");
00042         if (slask[strlen(slask) - 1] == '\n')
00043                 slask[strlen(slask) - 1] = 0;
00044         fprintf(stderr, "%s%s\n", slask, colors[0]);
00045 }

Debug & Debug::operator<< ( const char *  str  ) 

Definition at line 48 of file Debug.cpp.

References m_line.

00049 {
00050         m_line += str;
00051         return *this;
00052 }

Debug & Debug::operator<< ( const std::string &  str  ) 

Definition at line 55 of file Debug.cpp.

References m_line.

00056 {
00057         m_line += str;
00058         return *this;
00059 }

Debug & Debug::operator<< ( short  l  ) 

Definition at line 62 of file Debug.cpp.

References Utility::l2string(), and m_line.

00063 {
00064         m_line += Utility::l2string(l);
00065         return *this;
00066 }

Debug & Debug::operator<< ( int  l  ) 

Definition at line 69 of file Debug.cpp.

References Utility::l2string(), and m_line.

00070 {
00071         m_line += Utility::l2string(l);
00072         return *this;
00073 }

Debug & Debug::operator<< ( long  l  ) 

Definition at line 76 of file Debug.cpp.

References Utility::l2string(), and m_line.

00077 {
00078         m_line += Utility::l2string(l);
00079         return *this;
00080 }

Debug & Debug::operator<< ( double  d  ) 

Definition at line 83 of file Debug.cpp.

References m_line.

00084 {
00085         char slask[100];
00086         snprintf(slask, sizeof(slask), "%f", d);
00087         m_line += slask;
00088         return *this;
00089 }

Debug & Debug::operator<< ( endl   ) 

Definition at line 92 of file Debug.cpp.

References m_line, and Print().

00093 {
00094         Print("%s", m_line.c_str());
00095         m_line = "";
00096         return *this;
00097 }


Member Data Documentation

const char * Debug::colors [static, private]

Initial value:

 {
                "\x1B[0;0m", 
                "\x1B[0;0m\x1B[31m", 
                "\x1B[0;0m\x1B[32m", 
                "\x1B[0;0m\x1B[33m", 
                "\x1B[0;0m\x1B[34m", 
                "\x1B[0;0m\x1B[35m", 
                "\x1B[0;0m\x1B[36m", 
                "\x1B[0;0m\x1B[37m", 
                "\x1B[1;31m", 
                "\x1B[1;32m", 
                "\x1B[1;33m", 
                "\x1B[1;34m", 
                "\x1B[1;35m", 
                "\x1B[1;36m", 
                "\x1B[1;37m" }

Definition at line 16 of file Debug.h.

Referenced by Print().

int Debug::m_id [private]

Definition at line 66 of file Debug.h.

std::string Debug::m_text [private]

Definition at line 67 of file Debug.h.

std::map< unsigned long, int > Debug::m_level [static, private]

Definition at line 68 of file Debug.h.

Referenced by Print().

std::string Debug::m_line [private]

Definition at line 69 of file Debug.h.

Referenced by operator<<().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4