HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Debug.h
Go to the documentation of this file.
1 #ifndef __UT_Debug__
2 #define __UT_Debug__
3 
4 #include "UT_API.h"
5 /*
6 // This is a convenience class for adding debugging code to your
7 // source. It allows the use of run-time switches via environment
8 // variables and can be compiled out by not defining the pre-processor
9 // symbol UT_DEBUG.
10 //
11 // Typical use of this class involves declaring a static variable of
12 // type UT_Debug with the name of an environment variable switch that
13 // will enable this object. Then use it as follows:
14 //
15 // static UT_Debug debug("UT_DEBUG_THIS");
16 // ...
17 // if( debug.on() )
18 // debug.output("This is %x\n", this);
19 */
20 
21 // It's UGLY but...
22 
23 #ifdef UT_DEBUG
24 
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #define UT_IF(s) s
29 #define UT_IFNOT(s)
30 #define UT_IFELSE(t, f) t
31 
32 class UT_API UT_Debug
33 {
34 public:
35  explicit UT_Debug(const char *name) { myState = getenv(name) != 0; }
36  int on() const { return myState; }
37  void setDebugFile(const char *) const;
38  void output(const char *fmt, ...) const;
39 private:
40  int myState;
41 };
42 
43 #else
44 
45 #define UT_IF(s)
46 #define UT_IFNOT(s) s
47 #define UT_IFELSE(t, f) f
48 
50 {
51 public:
52  explicit UT_Debug(const char *) {}
53  int on() const { return 0; }
54  void setDebugFile(const char *) const;
55  void output(const char *, ...) const;
56 };
57 
58 #endif
59 
60 // Used by UT_DBGOUT(())
61 UT_API void UTdbgout(const char *file, int lineno, const char *text);
62 
63 UT_API const char *UTconsoleColorString(const char *colorname);
64 
65 // this macro must be used with a double parentheses!
66 // eg. UT_DBGOUT(( "value = %d", myValue ));
67 // The UTdebugFormat does not require double parentheses.
68 // Uses the same formatting codes as UTformat.
69 #if UT_ASSERT_LEVEL > 0
70  #include "UT_WorkBuffer.h"
71  #include <sstream>
72  #include <stdio.h>
73 
74  #define UTdebugFormat(...) do { \
75  UT_WorkBuffer dbostr; \
76  dbostr.format(__VA_ARGS__); \
77  UTdbgout(__FILE__, __LINE__, dbostr.buffer()); \
78  } while (false)
79 
80  #define UTdebugFormatCd(color, ...) do { \
81  UT_WorkBuffer dbostr, cdstr; \
82  dbostr.format(__VA_ARGS__); \
83  if (strcmp(#color, "none") == 0) \
84  cdstr = dbostr; \
85  else \
86  cdstr.sprintf("%s%s%s", UTconsoleColorString(#color), dbostr.buffer(), UTconsoleColorString("none")); \
87  UTdbgout(__FILE__, __LINE__, cdstr.buffer()); \
88  } while (false)
89 
90  #define UTdebugPrint(...) do { \
91  UT_WorkBuffer dbostr; \
92  dbostr.print(__VA_ARGS__); \
93  UTdbgout(__FILE__, __LINE__, dbostr.buffer()); \
94  } while (false)
95 
96  #define UTdebugPrintCd(color, ...) do { \
97  UT_WorkBuffer dbostr, cdstr; \
98  dbostr.print(__VA_ARGS__); \
99  if (strcmp(#color, "none") == 0) \
100  cdstr = dbostr; \
101  else \
102  cdstr.sprintf("%s%s%s", UTconsoleColorString(#color), dbostr.buffer(), UTconsoleColorString("none")); \
103  UTdbgout(__FILE__, __LINE__, cdstr.buffer()); \
104  } while (false)
105 
106  #define UT_DBGOUT(ZZ) do { \
107  UT_WorkBuffer dbostr; \
108  dbostr.sprintf ZZ ; \
109  UTdbgout(__FILE__, __LINE__, dbostr.buffer()); \
110  } while (false)
111 
112  #define UT_DBGOS(ZZ) do { \
113  std::stringstream os; \
114  os << ZZ ; \
115  UTdbgout(__FILE__,__LINE__,os.str().c_str()); \
116  } while (false)
117 
118  #define UT_DBGPRINTF(ZZ) printf ZZ
119 
120  #define UT_DBG_CHECKMEMORY UTdebugCheckMemory()
121  #define UT_DBG_CHECKPOINTER(PTR) UTdebugCheckPointer(PTR)
122 #else
123  #define UTdebugFormat(...) ((void)0)
124  #define UTdebugFormatCd(...) ((void)0)
125  #define UTdebugPrint(...) ((void)0)
126  #define UTdebugPrintCd(...) ((void)0)
127  #define UT_DBGOUT(ZZ) ((void)0)
128  #define UT_DBGOS(ZZ) ((void)0)
129  #define UT_DBGPRINTF(ZZ) ((void)0)
130  #define UT_DBG_CHECKMEMORY ((void)0)
131  #define UT_DBG_CHECKPOINTER(PTR) ((void)0)
132 #endif
133 
134 // UTgetSESIlogFlag will use UT_ASSERT_LEVEL >= 1 to check if it should be
135 // enabled. If we don't have sufficient assertion level, then the appropriate
136 // environment variable passed in will be used instead.
137 // Note that it uses a UT_Symbol table to keep track of the different vars.
138 // So it shouldn't be terribly inefficient to call multiple times.
139 
140 UT_API int UTgetSESIlogFlag(int env_control);
141 
142 
143 // UTisSESImachine will efficiently check the IP address of this computer to
144 // see if it is one of SESI's IP addresses and returns 1 if so.
145 // WARNING: This can register false positive on customer machines depending on
146 // the network configuration.
147 UT_API int UTisSESImachine();
148 
150 
151 UT_API bool UTdebugCheckPointer(const void *ptr);
152 
153 #endif /* __UT_Debug__ */
UT_API bool UTdebugCheckPointer(const void *ptr)
UT_Debug(const char *)
Definition: UT_Debug.h:52
UT_API const char * UTconsoleColorString(const char *colorname)
png_voidp ptr
Definition: png.h:2145
UT_API void UTdbgout(const char *file, int lineno, const char *text)
#define UT_API
Definition: UT_API.h:13
UT_API int UTdebugCheckMemory()
GLuint const GLchar * name
Definition: glcorearb.h:785
UT_API int UTgetSESIlogFlag(int env_control)
int on() const
Definition: UT_Debug.h:53
UT_API int UTisSESImachine()