rasdaman complete source
nmlog.h
Go to the documentation of this file.
1 /*
2  * name: nmlog.h
3  * author: Alexander Herzig
4  *
5  * last updated: 08/01/11
6  *
7  * version 0.3.0
8  *
9  */
10 
11 #ifndef NMLOG_H_
12 #define NMLOG_H_
13 
14 #include <string>
15 #include <sstream>
16 #include <iostream>
17 
18 namespace nmlog
19 {
20 extern int nmindent;
21 }
22 
23 // DEBUG MACROs
24 #ifdef DEBUG
25 #define NMDebug(arg) \
26  { \
27  std::ostringstream str; \
28  str arg; \
29  std::cout << str.str(); \
30  }
31 
32 #define NMDebugAI(arg) \
33  { \
34  std::ostringstream str; \
35  for (int q=1; q <= nmlog::nmindent+1; q++) \
36  {\
37  str << " "; \
38  }\
39  str arg; \
40  std::cout << str.str(); \
41  }
42 
43 #define NMDebugInd(level, arg) \
44  { \
45  std::ostringstream str; \
46  for (int q=1; q <= level; q++) \
47  {\
48  str << " "; \
49  }\
50  str arg; \
51  std::cout << str.str(); \
52  }
53 
54 #define NMDebugTimeInd(level, arg) \
55  { \
56  std::ostringstream str; \
57  for (int q=1; q <= level; q++) \
58  {\
59  str << " "; \
60  }\
61  str << __TIME__ << " - " arg; \
62  std::cout << str.str(); \
63  }
64 
65 #define NMDebugTime(arg) \
66  { \
67  std::ostringstream str; \
68  str << __TIME__ << " - " arg; \
69  std::cout << str.str(); \
70  }
71 
72 #define NMDebugCtx(context, arg) \
73  { \
74  std::string tmp;\
75  std::ostringstream str; \
76  str arg;\
77  tmp = str.str();\
78  str.str(""); \
79  if (tmp == "...") \
80  nmlog::nmindent++; \
81  for (int q=1; q <= nmlog::nmindent; q++) \
82  {\
83  str << "--"; \
84  }\
85  str << context << "::" << \
86  __FUNCTION__ << ": " arg; \
87  std::cout << str.str() << std::endl; \
88  if (tmp == "done!") \
89  nmlog::nmindent--; \
90  }
91 
92 #define NMDebugTimeCtx(context, arg) \
93  { \
94  std::ostringstream str; \
95  str << __TIME__ << ": " << context << "::" << \
96  __FUNCTION__ << ": " arg; \
97  std::cout << str.str() << std::endl; \
98  }
99 #else
100 #define NMDebug(arg)
101 #define NMDebugAI(arg)
102 #define NMDebugInd(level, arg)
103 #define NMDebugTime(arg)
104 #define NMDebugTimeInd(level, arg)
105 #define NMDebugCtx(ctx, arg)
106 #define NMDebugTimeCtx(ctx, arg)
107 #endif
108 
109 // ERROR MACRO
110 #define NMErr(context, arg) \
111  { \
112  std::ostringstream str; \
113  str << "ERROR - " << context << "::" << \
114  __FUNCTION__ << ", l. " << \
115  __LINE__ << ": " arg; \
116  std::cerr << str.str() << std::endl; \
117  }
118 
119 // MESSAGE MACRO
120 #define NMMsg(arg) \
121  { \
122  std::ostringstream str; \
123  str arg; \
124  std::cout << str.str() << std::endl; \
125  }
126 
127 #endif /* NMLOG_H_ */
int nmindent