Chunk is purely a wrapper class, any 'state variables', like 'characters in room...
[UnsignedByte.git] / src / Sockets / Debug.h
blob9644348b154cec9bf893147458e6185fc19edc36
1 #ifndef _SOCKETS_Debug_H
2 #define _SOCKETS_Debug_H
4 #include "sockets-config.h"
5 #include <string>
6 #include "Utility.h"
7 #include <map>
10 #ifdef SOCKETS_NAMESPACE
11 namespace SOCKETS_NAMESPACE {
12 #endif
15 class Debug
17 static const char *colors[];
19 public:
20 Debug(const std::string& x) : m_id(0), m_text(x) {
21 fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
22 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
23 fprintf(stderr, " ");
24 fprintf(stderr, "%s%s\n", x.c_str(), colors[0]);
25 m_level[Utility::ThreadID()]++;
27 Debug(int id, const std::string& x) : m_id(id), m_text(x) {
28 fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
29 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
30 fprintf(stderr, " ");
31 fprintf(stderr, "%d> %s%s\n", m_id, x.c_str(), colors[0]);
32 m_level[Utility::ThreadID()]++;
34 ~Debug() {
35 if (m_level[Utility::ThreadID()])
36 m_level[Utility::ThreadID()]--;
37 fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
38 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
39 fprintf(stderr, " ");
40 if (m_id)
41 fprintf(stderr, "%d> /%s%s\n", m_id, m_text.c_str(), colors[0]);
42 else
43 fprintf(stderr, "/%s%s\n", m_text.c_str(), colors[0]);
44 fflush(stderr);
46 static void Print(const char *format, ...);
48 private:
49 int m_id;
50 std::string m_text;
51 static std::map<unsigned long, int> m_level;
55 #ifdef SOCKETS_NAMESPACE
56 } // namespace SOCKETS_NAMESPACE {
57 #endif
59 #endif // _SOCKETS_Debug_H