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 44 of file Debug.h.


Constructor & Destructor Documentation

Debug::Debug (  )  [inline]

Definition at line 55 of file Debug.h.

00055 {}

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

Definition at line 56 of file Debug.h.

References Utility::ThreadID().

00056                                   : m_id(0), m_text(x) {
00057                 fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00058                 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00059                         fprintf(stderr, "  ");
00060                 fprintf(stderr, "%s%s\n", x.c_str(), colors[0]);
00061                 m_level[Utility::ThreadID()]++;
00062         }

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

Definition at line 63 of file Debug.h.

References Utility::ThreadID().

00063                                           : m_id(id), m_text(x) {
00064                 fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00065                 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00066                         fprintf(stderr, "  ");
00067                 fprintf(stderr, "%d> %s%s\n", m_id, x.c_str(), colors[0]);
00068                 m_level[Utility::ThreadID()]++;
00069         }

Debug::~Debug (  )  [inline]

Definition at line 70 of file Debug.h.

References Utility::ThreadID().

00070                  {
00071                 if (!m_text.empty())
00072                 {
00073                         if (m_level[Utility::ThreadID()])
00074                                 m_level[Utility::ThreadID()]--;
00075                         fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00076                         for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00077                                 fprintf(stderr, "  ");
00078                         if (m_id)
00079                                 fprintf(stderr, "%d> /%s%s\n", m_id, m_text.c_str(), colors[0]);
00080                         else
00081                                 fprintf(stderr, "/%s%s\n", m_text.c_str(), colors[0]);
00082                         fflush(stderr);
00083                 }
00084         }


Member Function Documentation

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

Definition at line 60 of file Debug.cpp.

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

Referenced by operator<<().

00061 {
00062         char slask[5000]; // temporary for vsprintf / vsnprintf
00063         va_list ap;
00064 
00065         va_start(ap, format);
00066         vsnprintf(slask, sizeof(slask), format, ap);
00067         va_end(ap);
00068 
00069         fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00070         for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00071                 fprintf(stderr, "  ");
00072         if (slask[strlen(slask) - 1] == '\n')
00073                 slask[strlen(slask) - 1] = 0;
00074         fprintf(stderr, "%s%s\n", slask, colors[0]);
00075 }

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

Definition at line 78 of file Debug.cpp.

References m_line.

00079 {
00080         m_line += str;
00081         return *this;
00082 }

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

Definition at line 85 of file Debug.cpp.

References m_line.

00086 {
00087         m_line += str;
00088         return *this;
00089 }

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

Definition at line 92 of file Debug.cpp.

References Utility::l2string(), and m_line.

00093 {
00094         m_line += Utility::l2string(l);
00095         return *this;
00096 }

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

Definition at line 99 of file Debug.cpp.

References Utility::l2string(), and m_line.

00100 {
00101         m_line += Utility::l2string(l);
00102         return *this;
00103 }

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

Definition at line 106 of file Debug.cpp.

References Utility::l2string(), and m_line.

00107 {
00108         m_line += Utility::l2string(l);
00109         return *this;
00110 }

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

Definition at line 113 of file Debug.cpp.

References m_line.

00114 {
00115         char slask[100];
00116         snprintf(slask, sizeof(slask), "%f", d);
00117         m_line += slask;
00118         return *this;
00119 }

Debug & Debug::operator<< ( endl   ) 

Definition at line 122 of file Debug.cpp.

References m_line, and Print().

00123 {
00124         Print("%s", m_line.c_str());
00125         m_line = "";
00126         return *this;
00127 }


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 46 of file Debug.h.

Referenced by Print().

int Debug::m_id [private]

Definition at line 96 of file Debug.h.

std::string Debug::m_text [private]

Definition at line 97 of file Debug.h.

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

Definition at line 98 of file Debug.h.

Referenced by Print().

std::string Debug::m_line [private]

Definition at line 99 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