Logo
~Sockets~
~Examples~
~Contact~


Debug Class Reference

#include <Debug.h>

List of all members.


Public Member Functions

 Debug (const std::string &x)
 Debug (int id, const std::string &x)
 ~Debug ()

Static Public Member Functions

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

Private Attributes

int m_id
std::string m_text

Static Private Attributes

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

Detailed Description

Definition at line 15 of file Debug.h.


Constructor & Destructor Documentation

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

Definition at line 20 of file Debug.h.

References Utility::ThreadID().

00020                                   : m_id(0), m_text(x) {
00021                 fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
00022                 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00023                         fprintf(stderr, "  ");
00024                 fprintf(stderr, "%s%s\n", x.c_str(), colors[0]);
00025                 m_level[Utility::ThreadID()]++;
00026         }

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

Definition at line 27 of file Debug.h.

References Utility::ThreadID().

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

Debug::~Debug (  )  [inline]

Definition at line 34 of file Debug.h.

References Utility::ThreadID().

00034                  {
00035                 if (m_level[Utility::ThreadID()])
00036                         m_level[Utility::ThreadID()]--;
00037                 fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
00038                 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00039                         fprintf(stderr, "  ");
00040                 if (m_id)
00041                         fprintf(stderr, "%d> /%s%s\n", m_id, m_text.c_str(), colors[0]);
00042                 else
00043                         fprintf(stderr, "/%s%s\n", m_text.c_str(), colors[0]);
00044                 fflush(stderr);
00045         }


Member Function Documentation

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

Definition at line 32 of file Debug.cpp.

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

00033 {
00034         char slask[5000]; // temporary for vsprintf / vsnprintf
00035         va_list ap;
00036 
00037         va_start(ap, format);
00038 #ifdef _WIN32
00039         vsprintf(slask, format, ap);
00040 #else
00041         vsnprintf(slask, 5000, format, ap);
00042 #endif
00043         va_end(ap);
00044 
00045         fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
00046         for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00047                 fprintf(stderr, "  ");
00048         if (slask[strlen(slask) - 1] == '\n')
00049                 slask[strlen(slask) - 1] = 0;
00050         fprintf(stderr, "%s%s\n", slask, colors[0]);
00051 }


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[0;0m\x1B[30m", 
                "\x1B[1;31m", 
                "\x1B[1;32m", 
                "\x1B[1;33m", 
                "\x1B[1;34m", 
                "\x1B[1;35m", 
                "\x1B[1;36m", 
                "\x1B[1;37m", 
                "\x1B[1;30m" }

Definition at line 17 of file Debug.h.

Referenced by Print().

int Debug::m_id [private]

Definition at line 49 of file Debug.h.

std::string Debug::m_text [private]

Definition at line 50 of file Debug.h.

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

Definition at line 51 of file Debug.h.

Referenced by Print().


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