6 #ifndef DYNAMIC_GRAPH_DEBUG_HH 7 #define DYNAMIC_GRAPH_DEBUG_HH 13 #include <dynamic-graph/dynamic-graph-api.h> 14 #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)
58 inline void trace(
const char *format, ...) {
63 inline void trace(
const int level = -1) {
64 if (level <= traceLevel) {
65 outputbuffer << tmpbuffer.str();
70 inline void traceTemplate(
const int level,
const char *format, ...) {
71 if (level <= traceLevelTemplate)
76 inline void traceTemplate(
const char *format, ...) {
81 inline DebugTrace &pre(
const std::ostream &) {
return *
this; }
83 inline DebugTrace &pre(
const std::ostream &,
int level) {
88 static const char *DEBUG_FILENAME_DEFAULT;
89 static void openFile(
const char *filename = DEBUG_FILENAME_DEFAULT);
90 static void closeFile(
const char *filename = DEBUG_FILENAME_DEFAULT);
93 DYNAMIC_GRAPH_DLLAPI
extern DebugTrace dgDEBUGFLOW;
94 DYNAMIC_GRAPH_DLLAPI
extern DebugTrace dgERRORFLOW;
99 #define dgPREDEBUG __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :" 101 "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :" 103 #define dgDEBUG(level) \ 104 if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \ 107 dgDEBUGFLOW.outputbuffer << dgPREDEBUG 109 #define dgDEBUGMUTE(level) \ 110 if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \ 113 dgDEBUGFLOW.outputbuffer 116 if (!dgDEBUGFLOW.outputbuffer.good()) \ 119 dgERRORFLOW.outputbuffer << dgPREERROR 122 if (!dgDEBUGFLOW.outputbuffer.good()) \ 125 dgDEBUGFLOW.pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_DEBUG_MODE).trace 128 if (!dgDEBUGFLOW.outputbuffer.good()) \ 131 dgERRORFLOW.pre(dgERRORFLOW.tmpbuffer << dgPREERROR).trace 134 #define dgTDEBUG(level) \ 135 if ((level > VP_TEMPLATE_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \ 138 dgDEBUGFLOW.outputbuffer << dgPREDEBUG 141 if (!dgDEBUGFLOW.outputbuffer.good()) \ 145 .pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE) \ 148 inline bool dgDEBUG_ENABLE(
const int &level) {
return level <= VP_DEBUG_MODE; }
150 inline bool dgTDEBUG_ENABLE(
const int &level) {
151 return level <= VP_TEMPLATE_DEBUG_MODE;
157 "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :" 159 #define dgDEBUG(level) \ 163 ::dynamicgraph::__null_stream() 165 #define dgDEBUGMUTE \ 167 else ::dynamicgraph::__null_stream() 169 #define dgERROR dgERRORFLOW.outputbuffer << dgPREERROR 171 inline void dgDEBUGF(
const int,
const char *, ...) {
return; }
173 inline void dgDEBUGF(
const char *, ...) {
return; }
175 inline void dgERRORF(
const int,
const char *, ...) {
return; }
177 inline void dgERRORF(
const char *, ...) {
return; }
180 inline std::ostream &__null_stream() {
183 static std::ostream os(NULL);
189 #define dgTDEBUG(level) \ 193 ::dynamicgraph::__null_stream() 195 inline void dgTDEBUGF(
const int,
const char *, ...) {
return; }
197 inline void dgTDEBUGF(
const char *, ...) {
return; }
199 #define dgDEBUG_ENABLE(level) false 200 #define dgTDEBUG_ENABLE(level) false 204 #define dgDEBUGIN(level) dgDEBUG(level) << "# In {" << std::endl 206 #define dgDEBUGOUT(level) dgDEBUG(level) << "# Out }" << std::endl 208 #define dgDEBUGINOUT(level) dgDEBUG(level) << "# In/Out { }" << std::endl 210 #define dgTDEBUGIN(level) dgTDEBUG(level) << "# In {" << std::endl 212 #define dgTDEBUGOUT(level) dgTDEBUG(level) << "# Out }" << std::endl 214 #define dgTDEBUGINOUT(level) dgTDEBUG(level) << "# In/Out { }" << std::endl