6 #ifndef DYNAMIC_GRAPH_DEBUG_HH
7 #define DYNAMIC_GRAPH_DEBUG_HH
8 #include <dynamic-graph/dynamic-graph-api.h>
12 #include <dynamic-graph/fwd.hh>
17 #define VP_DEBUG_MODE 0
20 #ifndef VP_TEMPLATE_DEBUG_MODE
21 #define VP_TEMPLATE_DEBUG_MODE 0
24 #define DG_COMMON_TRACES \
27 va_start(arg, format); \
28 vsnprintf(charbuffer, SIZE, format, arg); \
30 outputbuffer << tmpbuffer.str() << charbuffer << std::endl; \
42 static const int SIZE = 512;
44 std::stringstream tmpbuffer;
45 std::ostream &outputbuffer;
46 char charbuffer[SIZE + 1];
48 int traceLevelTemplate;
50 DebugTrace(std::ostream &os) : outputbuffer(os) {}
52 inline void trace(
const int level,
const char *format, ...) {
53 if (level <= traceLevel) DG_COMMON_TRACES;
57 inline void trace(
const char *format, ...) {
62 inline void trace(
const int level = -1) {
63 if (level <= traceLevel) {
64 outputbuffer << tmpbuffer.str();
69 inline void traceTemplate(
const int level,
const char *format, ...) {
70 if (level <= traceLevelTemplate) DG_COMMON_TRACES;
74 inline void traceTemplate(
const char *format, ...) {
79 inline DebugTrace &pre(
const std::ostream &) {
return *
this; }
81 inline DebugTrace &pre(
const std::ostream &,
int level) {
86 static const char *DEBUG_FILENAME_DEFAULT;
87 static void openFile(
const char *filename = DEBUG_FILENAME_DEFAULT);
88 static void closeFile(
const char *filename = DEBUG_FILENAME_DEFAULT);
91 DYNAMIC_GRAPH_DLLAPI
extern DebugTrace dgDEBUGFLOW;
92 DYNAMIC_GRAPH_DLLAPI
extern DebugTrace dgERRORFLOW;
97 #define dgPREDEBUG __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
99 "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
101 #define dgDEBUG(level) \
102 if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
105 dgDEBUGFLOW.outputbuffer << dgPREDEBUG
107 #define dgDEBUGMUTE(level) \
108 if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
111 dgDEBUGFLOW.outputbuffer
114 if (!dgDEBUGFLOW.outputbuffer.good()) \
117 dgERRORFLOW.outputbuffer << dgPREERROR
120 if (!dgDEBUGFLOW.outputbuffer.good()) \
123 dgDEBUGFLOW.pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_DEBUG_MODE).trace
126 if (!dgDEBUGFLOW.outputbuffer.good()) \
129 dgERRORFLOW.pre(dgERRORFLOW.tmpbuffer << dgPREERROR).trace
132 #define dgTDEBUG(level) \
133 if ((level > VP_TEMPLATE_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
136 dgDEBUGFLOW.outputbuffer << dgPREDEBUG
139 if (!dgDEBUGFLOW.outputbuffer.good()) \
143 .pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE) \
146 inline bool dgDEBUG_ENABLE(
const int &level) {
return level <= VP_DEBUG_MODE; }
148 inline bool dgTDEBUG_ENABLE(
const int &level) {
149 return level <= VP_TEMPLATE_DEBUG_MODE;
155 "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
157 #define dgDEBUG(level) \
161 ::dynamicgraph::__null_stream()
163 #define dgDEBUGMUTE \
165 else ::dynamicgraph::__null_stream()
167 #define dgERROR dgERRORFLOW.outputbuffer << dgPREERROR
169 inline void dgDEBUGF(
const int,
const char *, ...) {
return; }
171 inline void dgDEBUGF(
const char *, ...) {
return; }
173 inline void dgERRORF(
const int,
const char *, ...) {
return; }
175 inline void dgERRORF(
const char *, ...) {
return; }
178 inline std::ostream &__null_stream() {
181 static std::ostream os(NULL);
187 #define dgTDEBUG(level) \
191 ::dynamicgraph::__null_stream()
193 inline void dgTDEBUGF(
const int,
const char *, ...) {
return; }
195 inline void dgTDEBUGF(
const char *, ...) {
return; }
197 #define dgDEBUG_ENABLE(level) false
198 #define dgTDEBUG_ENABLE(level) false
202 #define dgDEBUGIN(level) dgDEBUG(level) << "# In {" << std::endl
204 #define dgDEBUGOUT(level) dgDEBUG(level) << "# Out }" << std::endl
206 #define dgDEBUGINOUT(level) dgDEBUG(level) << "# In/Out { }" << std::endl
208 #define dgTDEBUGIN(level) dgTDEBUG(level) << "# In {" << std::endl
210 #define dgTDEBUGOUT(level) dgTDEBUG(level) << "# Out }" << std::endl
212 #define dgTDEBUGINOUT(level) dgTDEBUG(level) << "# In/Out { }" << std::endl