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 std::string &)
Debugoperator<< (long)
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 15 of file Debug.h.


Constructor & Destructor Documentation

Debug::Debug (  )  [inline]

Definition at line 26 of file Debug.h.

00026 {}

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

Definition at line 27 of file Debug.h.

References Utility::ThreadID().

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

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

Definition at line 34 of file Debug.h.

References Utility::ThreadID().

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

Debug::~Debug (  )  [inline]

Definition at line 41 of file Debug.h.

References Utility::ThreadID().

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


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 #ifdef _WIN32
00037         vsprintf(slask, format, ap);
00038 #else
00039         vsnprintf(slask, 5000, format, ap);
00040 #endif
00041         va_end(ap);
00042 
00043         fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00044         for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00045                 fprintf(stderr, "  ");
00046         if (slask[strlen(slask) - 1] == '\n')
00047                 slask[strlen(slask) - 1] = 0;
00048         fprintf(stderr, "%s%s\n", slask, colors[0]);
00049 }

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

Definition at line 52 of file Debug.cpp.

References m_line.

00053 {
00054         m_line += str;
00055         return *this;
00056 }

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

Definition at line 59 of file Debug.cpp.

References Utility::l2string(), and m_line.

00060 {
00061         m_line += Utility::l2string(l);
00062         return *this;
00063 }

Debug & Debug::operator<< ( endl   ) 

Definition at line 66 of file Debug.cpp.

References m_line, and Print().

00067 {
00068         Print("%s", m_line.c_str());
00069         m_line = "";
00070         return *this;
00071 }


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

Referenced by Print().

int Debug::m_id [private]

Definition at line 63 of file Debug.h.

std::string Debug::m_text [private]

Definition at line 64 of file Debug.h.

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

Definition at line 65 of file Debug.h.

Referenced by Print().

std::string Debug::m_line [private]

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