Logo
~Sockets~
~Examples~
~Contact~


Debug.h

Go to the documentation of this file.
00001 #ifndef _SOCKETS_Debug_H
00002 #define _SOCKETS_Debug_H
00003 
00004 #include "sockets-config.h"
00005 #include <string>
00006 #include "Utility.h"
00007 #include <map>
00008 
00009 
00010 #ifdef SOCKETS_NAMESPACE
00011 namespace SOCKETS_NAMESPACE {
00012 #endif
00013 
00014 
00015 class Debug
00016 {
00017 static  const char *colors[];
00018 
00019 public:
00020         Debug(const std::string& x) : 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         }
00027         Debug(int id, const std::string& x) : 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         }
00034         ~Debug() {
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         }
00046 static  void Print(const char *format, ...);
00047 
00048 private:
00049         int m_id;
00050         std::string m_text;
00051 static  std::map<unsigned long, int> m_level;
00052 };
00053 
00054 
00055 #ifdef SOCKETS_NAMESPACE
00056 } // namespace SOCKETS_NAMESPACE {
00057 #endif
00058 
00059 #endif // _SOCKETS_Debug_H
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4