sot-core  4.11.6
Hierarchical task solver plug-in for dynamic-graph.
debug.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #ifndef SOT_CORE_DEBUG_HH
11 #define SOT_CORE_DEBUG_HH
12 #include "sot/core/api.hh"
13 #include <cstdarg>
14 #include <cstdio>
15 #include <fstream>
16 #include <sstream>
17 
18 #ifndef VP_DEBUG_MODE
19 #define VP_DEBUG_MODE 0
20 #endif
21 
22 #ifndef VP_TEMPLATE_DEBUG_MODE
23 #define VP_TEMPLATE_DEBUG_MODE 0
24 #endif
25 
26 #define SOT_COMMON_TRACES \
27  do { \
28  va_list arg; \
29  va_start(arg, format); \
30  vsnprintf(charbuffer, SIZE, format, arg); \
31  va_end(arg); \
32  outputbuffer << tmpbuffer.str() << charbuffer << std::endl; \
33  } while (0)
34 
35 namespace dynamicgraph {
36 namespace sot {
38 public:
39  static const int SIZE = 512;
40 
41  std::stringstream tmpbuffer;
42  std::ostream &outputbuffer;
43  char charbuffer[SIZE + 1];
46 
47  DebugTrace(std::ostream &os) : outputbuffer(os) {}
48 
49  inline void trace(const int level, const char *format, ...) {
50  if (level <= traceLevel)
52  tmpbuffer.str("");
53  }
54 
55  inline void trace(const char *format, ...) {
57  tmpbuffer.str("");
58  }
59 
60  inline void trace(const int level = -1) {
61  if (level <= traceLevel)
62  outputbuffer << tmpbuffer.str();
63  tmpbuffer.str("");
64  }
65 
66  inline void traceTemplate(const int level, const char *format, ...) {
67  if (level <= traceLevelTemplate)
69  tmpbuffer.str("");
70  }
71 
72  inline void traceTemplate(const char *format, ...) {
74  tmpbuffer.str("");
75  }
76 
77  inline DebugTrace &pre(const std::ostream &) { return *this; }
78 
79  inline DebugTrace &pre(const std::ostream &, int level) {
80  traceLevel = level;
81  return *this;
82  }
83 
84  static const char *DEBUG_FILENAME_DEFAULT;
85  static void openFile(const char *filename = DEBUG_FILENAME_DEFAULT);
86  static void closeFile(const char *filename = DEBUG_FILENAME_DEFAULT);
87 };
88 
91 } // namespace sot
92 } // namespace dynamicgraph
93 
94 #ifdef VP_DEBUG
95 #define sotPREDEBUG \
96  __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
97 
98 #define sotPREERROR \
99  "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
100 
101 #define sotDEBUG(level) \
102  if ((level > VP_DEBUG_MODE) || \
103  (!dynamicgraph::sot::sotDEBUGFLOW.outputbuffer.good())) \
104  ; \
105  else \
106  dynamicgraph::sot::sotDEBUGFLOW.outputbuffer << sotPREDEBUG
107 
108 #define sotDEBUGMUTE(level) \
109  if ((level > VP_DEBUG_MODE) || \
110  (!dynamicgraph::sot::sotDEBUGFLOW.outputbuffer.good())) \
111  ; \
112  else \
113  dynamicgraph::sot::sotDEBUGFLOW.outputbuffer
114 
115 #define sotERROR \
116  if (!dynamicgraph::sot::sotDEBUGFLOW.outputbuffer.good()) \
117  ; \
118  else \
119  dynamicgraph::sot::sotERRORFLOW.outputbuffer << sotPREERROR
120 
121 #define sotDEBUGF \
122  if (!dynamicgraph::sot::sotDEBUGFLOW.outputbuffer.good()) \
123  ; \
124  else \
125  dynamicgraph::sot::sotDEBUGFLOW \
126  .pre(dynamicgraph::sot::sotDEBUGFLOW.tmpbuffer << sotPREDEBUG, \
127  VP_DEBUG_MODE) \
128  .trace
129 
130 #define sotERRORF \
131  if (!dynamicgraph::sot::sotDEBUGFLOW.outputbuffer.good()) \
132  ; \
133  else \
134  sot::sotERRORFLOW.pre(sot::sotERRORFLOW.tmpbuffer << sotPREERROR).trace
135 
136 // TEMPLATE
137 #define sotTDEBUG(level) \
138  if ((level > VP_TEMPLATE_DEBUG_MODE) || \
139  (!dynamicgraph::sot::sotDEBUGFLOW.outputbuffer.good())) \
140  ; \
141  else \
142  dynamicgraph::sot::sotDEBUGFLOW.outputbuffer << sotPREDEBUG
143 
144 #define sotTDEBUGF \
145  if (!dynamicgraph::sot::sotDEBUGFLOW.outputbuffer.good()) \
146  ; \
147  else \
148  dynamicgraph::sot::sotDEBUGFLOW \
149  .pre(dynamicgraph::sot::sotDEBUGFLOW.tmpbuffer << sotPREDEBUG, \
150  VP_TEMPLATE_DEBUG_MODE) \
151  .trace
152 
153 namespace dynamicgraph {
154 namespace sot {
155 inline bool sotDEBUG_ENABLE(const int &level) { return level <= VP_DEBUG_MODE; }
156 
157 inline bool sotTDEBUG_ENABLE(const int &level) {
158  return level <= VP_TEMPLATE_DEBUG_MODE;
159 }
160 } // namespace sot
161 } // namespace dynamicgraph
162 
163 /* -------------------------------------------------------------------------- */
164 #else // VP_DEBUG
165 #define sotPREERROR \
166  "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
167 #define sotDEBUG(level) \
168  if (1) \
169  ; \
170  else \
171  ::dynamicgraph::sot::__null_stream()
172 #define sotDEBUGMUTE(level) \
173  if (1) \
174  ; \
175  else \
176  ::dynamicgraph::sot::__null_stream()
177 #define sotERROR sotERRORFLOW.outputbuffer << sotPREERROR
178 
179 namespace dynamicgraph {
180 namespace sot {
181 inline void sotDEBUGF(const int, const char *, ...) {}
182 inline void sotDEBUGF(const char *, ...) {}
183 inline void sotERRORF(const int, const char *, ...) {}
184 inline void sotERRORF(const char *, ...) {}
185 inline std::ostream &__null_stream() {
186  // This function should never be called. With -O3,
187  // it should not appear in the generated binary.
188  static std::ostream os(NULL);
189  return os;
190 }
191 } // namespace sot
192 } // namespace dynamicgraph
193 
194 // TEMPLATE
195 #define sotTDEBUG(level) \
196  if (1) \
197  ; \
198  else \
199  ::dynamicgraph::sot::__null_stream()
200 
201 namespace dynamicgraph {
202 namespace sot {
203 inline void sotTDEBUGF(const int, const char *, ...) {}
204 inline void sotTDEBUGF(const char *, ...) {}
205 } // namespace sot
206 } // namespace dynamicgraph
207 
208 #define sotDEBUG_ENABLE(level) false
209 #define sotTDEBUG_ENABLE(level) false
210 
211 #endif // VP_DEBUG
212 
213 #define sotDEBUGIN(level) sotDEBUG(level) << "# In {" << std::endl
214 #define sotDEBUGOUT(level) sotDEBUG(level) << "# Out }" << std::endl
215 #define sotDEBUGINOUT(level) sotDEBUG(level) << "# In/Out { }" << std::endl
216 
217 #define sotTDEBUGIN(level) sotTDEBUG(level) << "# In {" << std::endl
218 #define sotTDEBUGOUT(level) sotTDEBUG(level) << "# Out }" << std::endl
219 #define sotTDEBUGINOUT(level) sotTDEBUG(level) << "# In/Out { }" << std::endl
220 
221 #endif
222 
223 // Local variables:
224 // c-basic-offset: 2
225 // End:
sotTDEBUG_ENABLE
#define sotTDEBUG_ENABLE(level)
Definition: debug.hh:209
dynamicgraph::sot::DebugTrace::DebugTrace
DebugTrace(std::ostream &os)
Definition: debug.hh:47
SOT_CORE_EXPORT
#define SOT_CORE_EXPORT
Definition: api.hh:20
dynamicgraph::sot::DebugTrace::pre
DebugTrace & pre(const std::ostream &)
Definition: debug.hh:77
dynamicgraph::sot::DebugTrace::traceLevel
int traceLevel
Definition: debug.hh:44
VP_TEMPLATE_DEBUG_MODE
#define VP_TEMPLATE_DEBUG_MODE
VP_DEBUG_MODE.
Definition: debug.hh:23
dynamicgraph::sot::DebugTrace::traceLevelTemplate
int traceLevelTemplate
Definition: debug.hh:45
dynamicgraph::sot::__null_stream
std::ostream & __null_stream()
Definition: debug.hh:185
dynamicgraph::sot::sotDEBUGFLOW
SOT_CORE_EXPORT DebugTrace sotDEBUGFLOW
dynamicgraph
Definition: abstract-sot-external-interface.hh:17
VP_DEBUG_MODE
#define VP_DEBUG_MODE
Definition: debug.hh:19
dynamicgraph::sot::DebugTrace::tmpbuffer
std::stringstream tmpbuffer
Definition: debug.hh:41
dynamicgraph::sot::sotERRORFLOW
SOT_CORE_EXPORT DebugTrace sotERRORFLOW
dynamicgraph::sot::sotTDEBUGF
void sotTDEBUGF(const int, const char *,...)
Definition: debug.hh:203
dynamicgraph::sot::DebugTrace::trace
void trace(const int level, const char *format,...)
Definition: debug.hh:49
dynamicgraph::sot::DebugTrace::traceTemplate
void traceTemplate(const char *format,...)
Definition: debug.hh:72
SOT_COMMON_TRACES
#define SOT_COMMON_TRACES
VP_TEMPLATE_DEBUG_MODE.
Definition: debug.hh:26
dynamicgraph::sot::sotERRORF
void sotERRORF(const int, const char *,...)
Definition: debug.hh:183
dynamicgraph::sot::DebugTrace::pre
DebugTrace & pre(const std::ostream &, int level)
Definition: debug.hh:79
sotDEBUG_ENABLE
#define sotDEBUG_ENABLE(level)
Definition: debug.hh:208
dynamicgraph::sot::DebugTrace::trace
void trace(const int level=-1)
Definition: debug.hh:60
dynamicgraph::sot::DebugTrace::trace
void trace(const char *format,...)
Definition: debug.hh:55
api.hh
dynamicgraph::sot::DebugTrace::DEBUG_FILENAME_DEFAULT
static const char * DEBUG_FILENAME_DEFAULT
Definition: debug.hh:84
dynamicgraph::sot::DebugTrace
Definition: debug.hh:37
dynamicgraph::sot::DebugTrace::traceTemplate
void traceTemplate(const int level, const char *format,...)
Definition: debug.hh:66
dynamicgraph::sot::sotDEBUGF
void sotDEBUGF(const int, const char *,...)
Definition: debug.hh:181
dynamicgraph::sot::DebugTrace::outputbuffer
std::ostream & outputbuffer
Definition: debug.hh:42