Introduction
The idea of this class and collection of MACROS is to specify a level for a message, and record the message in a stream according to this level. In addition there are mechanisms allowing that no time is wasted in condition test. You can therefore let the debugging messages inside the code without impact on performances.
Setting up dgDEBUG macros
To allow message display the entity must be compiled with the macro
Commenting or removing this macro disable all the messages specified by the following macros.
The level up to which the messages are accepted for display is specified by:
In the constructor of the entity, the file where all the messages are written is specified by:
Using dgDEBUG macros
To print that the beginning of a method is being executed use the following macros:
5 here specifies the minimum level that you be specified by VP_DEBUG_MODE for this message to be displayed.
It will generate the following output:
/path_to/dynamic-graph/tests/debug-trace.cpp: testDebugTrace(#46) :# In {
The output displays the name of the source file, the name of the method, the line where is the macro, and the message itself.
When going out of the method:
This generates the following output:
/path_to/dynamic-graph/tests/debug-trace.cpp: testDebugTrace(#54) :# Out }
A message inside the code is written through:
dgDEBUG(5) <<
"Here is a test" << std::endl;
This generates the following output:
/path_to/dynamic-graph/tests/debug-trace.cpp: testDebugTrace(#52) :Here is a
test
Working example
A full working example is given here:
#include <iostream>
#include <sstream>
#define VP_DEBUG 1
#define VP_DEBUG_MODE 50
#define VP_TEMPLATE_DEBUG_MODE 50
#define BOOST_TEST_MODULE debug - trace
#if BOOST_VERSION >= 105900
#include <boost/test/tools/output_test_stream.hpp>
#else
#include <boost/test/output_test_stream.hpp>
#endif
#include <boost/test/unit_test.hpp>
using boost::test_tools::output_test_stream;
public:
}
}
dgDEBUG(5) <<
"Here is a test" << std::endl;
}
};
}
"my-entity")));
output_test_stream output;
std::fstream the_debug_file;
std::ios::in);
std::string astr;
std::ostringstream oss_debug_file;
while (std::getline(the_debug_file, astr)) {
std::size_t found = astr.find(":");
std::string asubstr = astr.substr(found + 1, astr.length());
found = asubstr.find(":");
std::string asubstr2 = asubstr.substr(found + 1, astr.length());
oss_debug_file << asubstr2;
}
the_debug_file.close();
std::string str_to_test =
"# In {"
"# In/Out { }"
"Here is a test"
"# Out }";
bool two_sub_string_identical;
two_sub_string_identical = str_to_test == oss_debug_file.str();
BOOST_CHECK(two_sub_string_identical);
delete ptr_entity;
}