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


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31